Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ${author} and ${branch} in templates #792

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

esteban-aliverti
Copy link

This PR adds basic support for ${author} and ${branch} variables in the commit templates.

It is also possible to use a part of the branch name by adding a regular expression to the ${branch} variable. For example: ${branch:ISSUE-[0-9]+}. In this case, if the branch name is something like "bugfix/ISSUE-1234_something", the value of the variable will be "ISSUE-1234"

This is related to issue #457

@@ -277,7 +277,17 @@ CommitEditor::CommitEditor(const git::Repository &repo, QWidget *parent)
}
}
}
applyTemplate(t, files);

RepoView *view = RepoView::parentView(this);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure if there was an easier way to get the author and branch name at this point

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Because of the possibility to temporarly changing the username amd email, I think you need to take the one from the repoview

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you change temporarly the username (click on the Author link above the commit message), still the old name is used.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esteban-aliverti can you have a look into it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QString pattern = TemplateButton::filesPosition;
pattern.replace("{", "\\{");
pattern.replace("}", "\\}");
pattern.replace("$", "\\$");
QRegularExpression re(pattern);
QRegularExpressionMatch match = re.match(templ);
int start = -1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand why were we calculating the offset instead of simply replacing all the variables and then checking where the placeholder for the cursor was left after all the substitutions.
This is what I'm doing not, but I may have missed something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants