-
Notifications
You must be signed in to change notification settings - Fork 100
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
Is there a way to get branch name in a user-defined rule? #108
Comments
So gitlint doesn't provide a way to do this out of the box, but I might have a workaround using the non-public from gitlint.rules import CommitRule, RuleViolation
from gitlint.options import IntOption
from gitlint.git import _git
class CheckBranchRule(CommitRule):
name = "branch-name-match-title"
id = "UC1"
def validate(self, commit):
print("title", commit.message.title)
# See https://stackoverflow.com/a/12142066/381010
print _git("rev-parse", "--abbrev-ref", "HEAD")
# I'll leave the comparison logic to you :-)
return [RuleViolation(self.id, "Title and branch name don't match", line_nr=1)] Caveats:
Hope this helps! |
Thanks for the quick reply @jorisroovers! Do you have plans to make branch name (or names) accessible via |
That did occur to me when writing the reply. |
Each GitCommit object now contains a 'branches' property that can be used as part of rules. Also added an extra user-defined rule example that demonstrates this. This implements #108
Each GitCommit object now contains a 'branches' property that can be used as part of rules. Also added an extra user-defined rule example that demonstrates this. This implements #108
Each GitCommit object now contains a 'branches' property that can be used as part of rules. Also added an extra user-defined rule example that demonstrates this. This implements #108
Implemented. Will release this as part of the 0.13.0 release, hopefully soon :-) Also, I think it would be nice to also have a |
The GitContext class now contains a current_branch property. Related to #108
- Behavior Change: Revert Commits are now recognized and ignored by default #99 - --staged flag: gitlint can now detect meta-data (such as author details, changed files, etc) of staged/pre-commits. Useful when you use gitlint's commit-msg hook or precommit (#105) - New branch properties on GitCommit and GitContext, useful when writing your own user-defined rules: commit.branches and commit.context.current_branch #108 - Python 3.8 support - Python 3.4 no longer supported. Python 3.4 has reached EOL and an increasing of gitlint's dependencies have dropped support which makes it hard to maintain - Improved Windows support: better unicode handling. - Bugfixes: - Gitlint no longer crashes when acting on empty repositories (this only occurred in specific circumstances). - Changed files are now better detected in repos that only have a root commit - Improved performance and memory (gitlint now caches git properties) - Improved --debug output - Improved documentation - Under-the-hood: dependencies updated, unit and integration test improvements, migrated from TravisCI to Github Actions. Full Release details in CHANGELOG.md.
Released this yesterday as part of the 0.13.0 release - closing this out now :) |
By convention in our company we should put Jira ticket ID in the beginning of branch name (for example
JIRA-123_do_something_great
) and also we should put ticket id in commit message. I would like to check if they are the same. For this I need to get branch name inside ofvalidate
method of the rule. But I don't see that there is some property incommit
orcontext
objects that would help me. Do I miss something or gitlint is not able to help me in this case?The text was updated successfully, but these errors were encountered: