-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakub Strzebonski
committed
Sep 23, 2020
1 parent
087ae36
commit 34e5c14
Showing
4 changed files
with
128 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,74 @@ | ||
const core = require("@actions/core"); | ||
|
||
function checkPrBranch(prBranch) { | ||
core.info(`Checking branch name\n - "${prBranch}"`); | ||
|
||
let prBranchRegexp = /^\d+(-[^\W_]+)+$/; | ||
return prBranchRegexp.test(prBranch); | ||
} | ||
|
||
function checkPrTitle(prTitle) { | ||
core.info(`Checking PR title\n - "${prTitle}"`); | ||
|
||
let prTitleRegexp = /^#?\d+:?\s+.+$/; | ||
return prTitleRegexp.test(prTitle); | ||
} | ||
|
||
function checkPrDescription(prDescription) { | ||
core.info(`Checking PR description\n - "${prDescription}"`); | ||
|
||
let prDescriptionRegexp = /((fix(e[ds])?)|(close[ds]?)|(resolve[ds]?))(:? #)\d+/i; | ||
return prDescriptionRegexp.test(prDescription); | ||
} | ||
|
||
function compareTitleDescriptionBranchIssue(prBranch, prTitle, prDescription) { | ||
core.info("Extracting issue number from"); | ||
|
||
let branchIssue = extractBranchIssue(prBranch); | ||
core.info(` - branch name - "${branchIssue}"`); | ||
|
||
let titleIssue = extractTitleIssue(prTitle); | ||
core.info(` - PR title - "${titleIssue}"`); | ||
|
||
let descriptionIssue = extractDescriptionIssue(prDescription); | ||
core.info(` - PR description - "${descriptionIssue}"`); | ||
|
||
return branchIssue === titleIssue && titleIssue === descriptionIssue; | ||
} | ||
|
||
function extractBranchIssue(prBranch) { | ||
let prBranchRegexp = /^\d+(?=((-[^\W_]+)+$))/; | ||
let issueNumber = prBranch.match(prBranchRegexp); | ||
return parseInt(issueNumber); | ||
let issueStr = prBranch.match(prBranchRegexp); | ||
let issueNumber = parseInt(issueStr, 10); | ||
|
||
return issueNumber; | ||
} | ||
|
||
function extractTitleIssue(prTitle) { | ||
let prTitleRegexp = /(((?<=^)\d+)|((?<=^#)\d+))/; | ||
let issueNumber = prTitle.match(prTitleRegexp); | ||
return parseInt(issueNumber, 10); | ||
let issueStr = prTitle.match(prTitleRegexp); | ||
let issueNumber = parseInt(issueStr, 10); | ||
|
||
return issueNumber; | ||
} | ||
|
||
function extractDescriptionIssue(prDescription) { | ||
let prDescriptionRegexp = /(?<=[Ff]ixes #)\d+/; | ||
let issueNumber = prDescription.match(prDescriptionRegexp); | ||
return parseInt(issueNumber, 10); | ||
} | ||
// Firstly extract "Fixes #issue" phrase | ||
let prDescriptionRegexp = /((fix(e[ds])?)|(close[ds]?)|(resolve[ds]?))(:? #)\d+/i; | ||
let fixesIssueStr = prDescription.match(prDescriptionRegexp); | ||
|
||
function compareTitleDescriptionBranchIssue(prBranch, prTitle, prDescription) { | ||
let branchIssue = extractBranchIssue(prBranch); | ||
let titleIssue = extractTitleIssue(prTitle); | ||
let descriptionIssue = extractDescriptionIssue(prDescription); | ||
return branchIssue === titleIssue && titleIssue === descriptionIssue; | ||
// Next extract issue number | ||
let issueNumberRegexp = /\d+/; | ||
let issueStr = fixesIssueStr[0].match(issueNumberRegexp); | ||
let issueNumber = parseInt(issueStr, 10); | ||
|
||
return issueNumber; | ||
} | ||
|
||
exports.checkPrBranch = checkPrBranch; | ||
exports.checkPrTitle = checkPrTitle; | ||
exports.checkPrDescription = checkPrDescription; | ||
exports.compareTitleDescriptionBranchIssue = compareTitleDescriptionBranchIssue; | ||
exports.extractBranchIssue = extractBranchIssue; | ||
exports.extractTitleIssue = extractTitleIssue; | ||
exports.extractDescriptionIssue = extractDescriptionIssue; | ||
exports.compareTitleDescriptionBranchIssue = compareTitleDescriptionBranchIssue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters