You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am currently trying to parse our issues from the commit messages and that works. But because our format is [ABC-1234] we get [ABC-1234] as a result because the issue matcher returns group() (=group(0)).
In regex otherwise we could define non-capturing groups ( "(?:pattern)" ) which would result in this matching pattern NOT returned by the group.
The only difference for the default regex would be that it always have to be in one group aka surrounded by brackets.
So \b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\b
would be (\b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\b) and group(1) for ABC-1234 would return ABC-1234
and in our case we could use (?:\[)(([a-zA-Z](?:[a-zA-Z]+)-(?:[0-9]+)))(?:\]) and group(1) for [ABC-1234] would return ABC-1234
This way there would be more flexibility in the regex. The other, more complicated approach would be to also add a parameter for which group should be returned or return all groups or something but in my understanding group(1) should do the trick for the default and most other cases as you could just filter out everything else.
If you wrap the issue ID in special characters, like we do (e.g. [ABC-1234]). because we have several issue tracking systems with different formats, than \b(regex)\b does not work as the issue ID is not a word but \b[(regex)]\b does would work. But then the brackets are part of the issue id which is wrong and does not work down the road with loading Jira issue titles etc.
Just (regex) would also work but than of course it could match some other part of the commit message as well unintentionally.
issueMatcher.group() just returns the whole match.
issueMatcher.group(1) returns the first group of the matching String. So as I stated above you could define a regex that matches the String [(regex)] but groups only the real issueID and uses non-capturing groups to cut of the parts of the block that are not part of the issue ID.
Hi,
I am currently trying to parse our issues from the commit messages and that works. But because our format is [ABC-1234] we get [ABC-1234] as a result because the issue matcher returns group() (=group(0)).
In regex otherwise we could define non-capturing groups ( "(?:pattern)" ) which would result in this matching pattern NOT returned by the group.
The only difference for the default regex would be that it always have to be in one group aka surrounded by brackets.
So
\b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\b
would be
(\b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\b)
and group(1) for ABC-1234 would return ABC-1234and in our case we could use
(?:\[)(([a-zA-Z](?:[a-zA-Z]+)-(?:[0-9]+)))(?:\])
and group(1) for [ABC-1234] would return ABC-1234This way there would be more flexibility in the regex. The other, more complicated approach would be to also add a parameter for which group should be returned or return all groups or something but in my understanding group(1) should do the trick for the default and most other cases as you could just filter out everything else.
Code change would be here:
git-changelog-lib/src/main/java/se/bjurr/gitchangelog/internal/issues/IssueParser.java
Line 72 in e37028a
The text was updated successfully, but these errors were encountered: