Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add group pull request capability for dependabot pull requests.
- Loading branch information
Showing
5 changed files
with
612 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const compareVersions = require("compare-versions"); | ||
|
||
const groupPullRequests = (pullRequests) => { | ||
|
||
const dependabotPRs = {} | ||
const otherPRs = [] | ||
|
||
const dependabot = new RegExp("Bump ([^\S]+) from ([^\S]+) to ([^\S]+)", "gm"); | ||
for (let i in pullRequests) { | ||
const currentPullRequest = pullRequests[i] | ||
|
||
if (currentPullRequest.title.match(dependabot)) { | ||
const matches = [...pullRequests[i].title.matchAll(dependabot)] | ||
if (dependabotPRs[matches[0][1]]) { | ||
const curr = dependabotPRs[matches[0][1]] | ||
const from = (compareVersions(matches[0][2], curr.from) < 0) ? matches[0][2] : curr.from | ||
const to = (compareVersions(matches[0][3], curr.to) > 0) ? matches[0][3] : curr.to | ||
curr.number.push(currentPullRequest.number) | ||
dependabotPRs[matches[0][1]] = { | ||
from: from, | ||
to: to, | ||
number: curr.number, | ||
pr: currentPullRequest | ||
} | ||
} else { | ||
dependabotPRs[matches[0][1]] = { | ||
from: matches[0][2], | ||
to: matches[0][3], | ||
number: [currentPullRequest.number], | ||
pr: currentPullRequest | ||
} | ||
} | ||
} else { | ||
otherPRs.push(currentPullRequest) | ||
} | ||
} | ||
|
||
const result = [...otherPRs] | ||
|
||
for (const [key, value] of Object.entries(dependabotPRs)) { | ||
const item = value.pr | ||
const joined = `Bump ${key} from ${value.from} to ${value.to}` | ||
item.title = joined | ||
item.number = value.number | ||
result.push(item) | ||
} | ||
console.log(result) | ||
|
||
return result | ||
} | ||
|
||
exports.groupPullRequests = groupPullRequests |
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
329 changes: 329 additions & 0 deletions
329
test/fixtures/__generated__/graphql-commits-dependabot.json
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.