Skip to content

Commit f3067de

Browse files
brightcohenYotam Cohen
authored andcommitted
Add env vars to enable/disable checks
1 parent eec9014 commit f3067de

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ [email protected]
4242
JIRA_PASSWORD=bar
4343
4444
# List of issue statuses that would be accepted
45+
JIRA_STATUS_CHECK=TRUE
4546
JIRA_APPROVED_STATUSES="Approved, Progress"
4647
48+
# Search for the Jira Issue ID in commit message
49+
SEARCH_JIRA_ISSUE_IN_COMMIT=TRUE
50+
51+
# Optional variable to allow multiple commits in the same PR
52+
ALLOW_MANY_COMMITS=TRUE
53+
54+
4755
# URL prefix used for hyperlinks.
4856
URL_PREFIX=http://localhost:3000
4957

app.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function getJiraInfo(pullRequest) {
7878
const jiraApprovedStatusesArray = jiraApprovedStatuses.split(",").map(status => status.trim())
7979

8080
// Check Jira ticket for validity
81-
if (!jiraApprovedStatuses.includes(jiraStatus)) {
81+
if (!jiraApprovedStatuses.includes(jiraStatus) && process.env.JIRA_STATUS_CHECK === "TRUE") {
8282
return {
8383
issueKey,
8484
jiraStatus,
@@ -93,34 +93,37 @@ async function getJiraInfo(pullRequest) {
9393
}
9494

9595
// Check for consistency with the commit messages
96-
for (const commitInfo of commits) {
97-
const commitIssueKey = parseMessage(commitInfo.commit.message);
98-
if (commitIssueKey === null) {
99-
return {
100-
issueKey,
101-
jiraStatus,
102-
numCommits,
103-
isMaintMerge,
104-
prFlags,
105-
pass: false,
106-
description: "Commit message for " + commitInfo.sha.substr(0, 7) + " fails validation",
107-
badCommit: commitInfo
108-
};
109-
} else if (commitIssueKey !== issueKey && !prFlags["DISABLE_JIRA_ISSUE_MATCH"] && !isMaintMerge) {
110-
return {
111-
issueKey,
112-
jiraStatus,
113-
numCommits,
114-
isMaintMerge,
115-
prFlags,
116-
pass: false,
117-
description: "Commit " + commitInfo.sha.substr(0, 7) + " is for " + commitIssueKey + ", but the PR is for " + issueKey,
118-
extendedDescription: "Please fix your commit message to have the same ticket number as the pull request. If the inconsistency is intentional, you can disable this warning with DISABLE_JIRA_ISSUE_MATCH=true in the PR description.",
119-
badCommit: commitInfo
120-
};
96+
if(process.env.SEARCH_JIRA_ISSUE_IN_COMMIT === "TRUE") {
97+
for (const commitInfo of commits) {
98+
const commitIssueKey = parseMessage(commitInfo.commit.message);
99+
if (commitIssueKey === null) {
100+
return {
101+
issueKey,
102+
jiraStatus,
103+
numCommits,
104+
isMaintMerge,
105+
prFlags,
106+
pass: false,
107+
description: "Commit message for " + commitInfo.sha.substr(0, 7) + " fails validation",
108+
badCommit: commitInfo
109+
};
110+
} else if (commitIssueKey !== issueKey && !prFlags["DISABLE_JIRA_ISSUE_MATCH"] && !isMaintMerge) {
111+
return {
112+
issueKey,
113+
jiraStatus,
114+
numCommits,
115+
isMaintMerge,
116+
prFlags,
117+
pass: false,
118+
description: "Commit " + commitInfo.sha.substr(0, 7) + " is for " + commitIssueKey + ", but the PR is for " + issueKey,
119+
extendedDescription: "Please fix your commit message to have the same ticket number as the pull request. If the inconsistency is intentional, you can disable this warning with DISABLE_JIRA_ISSUE_MATCH=true in the PR description.",
120+
badCommit: commitInfo
121+
};
122+
}
121123
}
122124
}
123125

126+
124127
// Since we can't easily check more than 100 commits, reject PRs with more than 100 commits
125128
if (commits.length === 100) {
126129
return {
@@ -222,8 +225,12 @@ async function touch(pullRequest, jiraInfo) {
222225
const multiCommitMessage = (jiraInfo.numCommits === 0) ? "No commits found on PR" : (jiraInfo.numCommits === 1) ? "This PR includes exactly 1 commit!" : "This PR has " + jiraInfo.numCommits + " commits" + (multiCommitPass ? "" : "; consider squashing.");
223226
const promises = [
224227
github.createStatus("jira-ticket", pullRequest, jiraInfo.pass, url, jiraInfo.description),
225-
github.createStatus("single-commit", pullRequest, multiCommitPass, undefined, multiCommitMessage)
226228
];
229+
230+
if (!(process.env.ALLOW_MANY_COMMITS === "TRUE")) {
231+
promises.push(github.createStatus("single-commit", pullRequest, multiCommitPass, undefined, multiCommitMessage))
232+
}
233+
227234
if (jiraInfo.isMaintMerge) {
228235
promises.push(github.createStatus("maint-merge", pullRequest, false, undefined, "Reminder: use a MERGE COMMIT and new ticket in the message."));
229236
}

0 commit comments

Comments
 (0)