From 641814d32ef6ae67f691486394465c43a8750348 Mon Sep 17 00:00:00 2001 From: Nikolaus Piccolotto Date: Thu, 27 Oct 2016 16:25:17 +0200 Subject: [PATCH] #341 support commit patterns anywhere in the multiline message (#473) --- config/app-enterprise.yaml | 6 +++--- config/app-opensource.yaml | 2 +- server/checks/CommitMessage.js | 2 +- test/server/commitmessage.test.js | 10 ++++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/config/app-enterprise.yaml b/config/app-enterprise.yaml index 80129801..a88e79b8 100644 --- a/config/app-enterprise.yaml +++ b/config/app-enterprise.yaml @@ -22,9 +22,9 @@ ZAPPR_DEFAULT_CONFIG: commit: message: patterns: - - "^(?:(?:[a-zA-Z0-9_\\-]*|[a-zA-Z0-9_\\-]+\\/[a-zA-Z0-9_\\-]+)#|GH-)\\d+" - - "^#?[A-Z]+-[0-9]+" # like JIRA-123 - - "^#[0-9+]" # regular github pattern like #123 + - "(?:(?:[a-zA-Z0-9_\\-]*|[a-zA-Z0-9_\\-]+\\/[a-zA-Z0-9_\\-]+)#|GH-)\\d+" + - "#?[A-Z]+-[0-9]+" # like JIRA-123 + - "#[0-9+]" # regular github pattern like #123 approvals: minimum: 2 ignore: none diff --git a/config/app-opensource.yaml b/config/app-opensource.yaml index bb4dd56e..8655d5f8 100644 --- a/config/app-opensource.yaml +++ b/config/app-opensource.yaml @@ -24,7 +24,7 @@ ZAPPR_DEFAULT_CONFIG: commit: message: patterns: - - "^#[0-9]+" + - "#[0-9]+" approvals: minimum: 2 ignore: none diff --git a/server/checks/CommitMessage.js b/server/checks/CommitMessage.js index 3805ff8b..55d47eaa 100644 --- a/server/checks/CommitMessage.js +++ b/server/checks/CommitMessage.js @@ -65,7 +65,7 @@ export default class CommitMessage extends Check { // get all the commits in the PR const commits = await this.github.fetchPullRequestCommits(owner.login, name, number, token) // get matcher function for all those patterns - const matcherFn = getAnyMatcherFn(patterns.map(pattern => new RegExp(pattern))) + const matcherFn = getAnyMatcherFn(patterns.map(pattern => new RegExp(pattern, 'm'))) // gather non-merge commits with bad messages const badCommits = commits.filter(c => !isMergeCommit(c) && !matcherFn(c.commit.message.trim())) diff --git a/test/server/commitmessage.test.js b/test/server/commitmessage.test.js index 9a8884e0..791d5867 100644 --- a/test/server/commitmessage.test.js +++ b/test/server/commitmessage.test.js @@ -5,7 +5,7 @@ import CommitMessage, {getAnyMatcherFn} from '../../server/checks/CommitMessage' const CONFIG = { commit: { message: { - patterns: ['^#[0-9]+'] + patterns: ['#[0-9]+'] } } } @@ -124,7 +124,13 @@ describe('CommitMessage', () => { }, { sha: '2commit', commit: { - message: '#123 polizei' + message: `also matching, but multiline +#552` + } + }, { + sha: '3commit', + commit: { + message: `does not have to be at beginning: #123` } }, { sha: '4commit',