Skip to content

Commit

Permalink
feat: add support for bitbucket merge messages
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed Nov 6, 2022
1 parent 5d4a621 commit f0c60c7
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 317 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## **2.2.0** <sub><sup>2022-11-06 ([9e026c5...d0b5b6b](https://github.com/qoomon/git-conventional-commits/compare/9e026c5...d0b5b6b?diff=split))</sup></sub>

### Features
* add support for bitbucket merge messages ([d0b5b6b](https://github.com/qoomon/git-conventional-commits/commit/d0b5b6b))


### Bug Fixes
* fix \#107 ([b7a3e41](https://github.com/qoomon/git-conventional-commits/commit/b7a3e41))


## **2.1.2** <sub><sup>2022-09-20 ([9e026c5...68a02b6](https://github.com/qoomon/git-conventional-commits/compare/9e026c5...68a02b6?diff=split))</sup></sub>

### Bug Fixes
Expand Down
5 changes: 4 additions & 1 deletion lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ function defaultConfig() {

// regex patterns
config.convention.msgRegex = /^(?<type>\w+)(?:\((?<scope>[^()]+)\))?(?<breaking>!)?:\s*(?<description>.+)/i;
config.convention.msgMergeRegex = /^Merge branch +["'](?<branch>.+)['"]/i;
config.convention.msgMergeRegexList = [
/^Merge (?<description>.+)/i, // Default Git merge message
/^Merged in (?<description>.+)/i, // Bitbucket merge message e.g. "Merged in team/repository/branch"
];
config.convention.msgRevertRegex = /^Revert +["'](?<subject>.+)['"]/i;
config.convention.bodyRevertRegex = /(?<hash>\S+)\.+?$/im; // \S - no white spaces
// match only release version e.g. 1.2.3 ((?:[^-]|$) ignores pre-release versions e.g. 1.2.3-SNAPSHOT)
Expand Down
13 changes: 11 additions & 2 deletions lib/gitCommitConvention.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ module.exports = function (convention, commitAnchor = 'HEAD') {
conventionalSubject.breaking = msgMatch.groups.breaking === '!';
conventionalSubject.description = msgMatch.groups.description;
} else {
const msgMergeMatch = commit.subject.match(convention.msgMergeRegex);
const msgMergeMatch = getFirstMatch(commit.subject, convention.msgMergeRegexList);
if (msgMergeMatch) {
conventionalSubject.type = 'merge';
conventionalSubject.description = msgMergeMatch.groups.branch;
conventionalSubject.description = msgMergeMatch.groups.description;
} else {
const msgRevertMatch = commit.subject.match(convention.msgRevertRegex);
if (msgRevertMatch) {
Expand Down Expand Up @@ -132,4 +132,13 @@ module.exports = function (convention, commitAnchor = 'HEAD') {
excludePattern: '*-*', // exclude pre-release versions
})
}

function getFirstMatch(string, regexList) {
for (const regex of regexList) {
const match = string.match(regex);
if (match) {
return match;
}
}
}
};
Loading

0 comments on commit f0c60c7

Please sign in to comment.