Skip to content

Commit

Permalink
Cleanup and adding FIXME comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Nov 22, 2023
1 parent 0bdafae commit 5c95d31
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
59 changes: 31 additions & 28 deletions lib/group-pull-requests.js
Expand Up @@ -5,46 +5,49 @@ const groupPullRequests = (pullRequests) => {
const dependabotPRs = {}
const otherPRs = []

const dependabot = new RegExp("Bump ([^\S]+) from ([^\S]+) to ([^\S]+)", "gm");
const bumpVersionRegExp = new RegExp("Bump ([^\S]+) from ([^\S]+) to ([^\S]+)", "g");

// group all matching dependabot PRs
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
const currentPR = pullRequests[i]

if (currentPR.title.match(bumpVersionRegExp)) {
const match = [...pullRequests[i].title.matchAll(bumpVersionRegExp)][0]

const artifact = match[1]
const fromVersion = match[2]
const toVersion = match[3]

if (dependabotPRs[artifact]) {
const prevDependabotPR = dependabotPRs[artifact]
dependabotPRs[artifact] = {
from: (compareVersions(fromVersion, prevDependabotPR.from) < 0) ? fromVersion : prevDependabotPR.from,
to: (compareVersions(toVersion, prevDependabotPR.to) > 0) ? toVersion : prevDependabotPR.to,
pullRequests: [...prevDependabotPR.pullRequests, currentPR.number],
// use the latest PR for creating the final changelog entry
pr: (compareVersions(toVersion, prevDependabotPR.to) > 0) ? currentPR : prevDependabotPR.pr
}
} else {
dependabotPRs[matches[0][1]] = {
from: matches[0][2],
to: matches[0][3],
number: [currentPullRequest.number],
pr: currentPullRequest
dependabotPRs[artifact] = {
from: fromVersion,
to: toVersion,
pullRequests: [currentPR.number],
pr: currentPR
}
}
} else {
otherPRs.push(currentPullRequest)
otherPRs.push(currentPR)
}
}

// reconstruct all PRs
const result = [...otherPRs]

for (const [key, value] of Object.entries(dependabotPRs)) {
const item = value.pr
item.title = `Bump ${key} from ${value.from} to ${value.to}`
item.number = value.number
result.push(item)
const pr = value.pr
pr.title = `Bump ${key} from ${value.from} to ${value.to}`
pr.number = value.pullRequests
result.push(pr)
}
console.log(result)

return result
}

Expand Down
4 changes: 4 additions & 0 deletions lib/template.js
Expand Up @@ -13,6 +13,10 @@ const template = (string, object, customReplacers) => {
if (object[k] === undefined || object[k] === null) {
result = k
} else if (Array.isArray(object[k])) {
// FIXME: this is basically a hack to support changelog entries to refer to multiple PRs
// we assume that a list of values refers to PR numbers. If somebody has a better
// idea how to handle that in a clean way, i.e. to support the change template for
// each individual PR number.
result = object[k].map(item => `${item}`).join(',#')
} else if (typeof object[k] === 'object') {
result = template(object[k].template, object[k])
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Expand Up @@ -3406,11 +3406,11 @@ describe('release-drafter', () => {
Object {
"body": "# What's Changed
* Bump org.owasp:dependency-check-maven from 8.4.0 to 8.4.3 (#272,#259) @dependabot
* Bump com.fasterxml.jackson.core:jackson-databind from 2.13.1 to 2.16.0 (#273,#261,#256) @dependabot
* Bump the quarkus group with 1 update (#271) @dependabot
* Bump org.cyclonedx:cyclonedx-maven-plugin from 2.7.9 to 2.7.10 (#258) @dependabot
* Bump org.owasp:dependency-check-maven from 8.4.0 to 8.4.3 (#272,#259) @dependabot
* Bump surefire-plugin.version from 3.1.2 to 3.2.1 (#260) @dependabot
* Bump com.fasterxml.jackson.core:jackson-databind from 2.13.1 to 2.16.0 (#273,#261,#256) @dependabot
",
"draft": true,
"make_latest": "true",
Expand Down

0 comments on commit 5c95d31

Please sign in to comment.