Skip to content

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

Draft
esteban-aliverti wants to merge 1 commit intoMurmele:masterfrom
esteban-aliverti:feature/457_extra_template_variables
Draft

Add support for ${author} and ${branch} in templates#792
esteban-aliverti wants to merge 1 commit intoMurmele:masterfrom
esteban-aliverti:feature/457_extra_template_variables

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

}
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.

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.

Copy link
Owner

@Murmele Murmele Jul 30, 2025

Choose a reason for hiding this comment

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

Sorry for the late response. How do you know afterwards where to set the cursor?

@Murmele Murmele marked this pull request as draft September 12, 2025 09:47
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