Skip to content

Commit b04e543

Browse files
committed
guessReleaseNotes: refactor for clarity
The previous code was concise, but not very easy to read. Make it clear how we determine whether we're looking at the title/body of a PR or of an issue, and how we match in each respective case. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 15185a0 commit b04e543

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

GitForWindowsHelper/component-updates.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,23 @@ const guessReleaseNotes = (issue) => {
5757

5858
package_name = prettyPackageName(package_name.replace(/^mingw-w64-/, ''))
5959

60-
const urlMatch = issue.pull_request
61-
? issue.body.match(/See (https:\/\/\S+) for details/)
62-
: issue.body.match(/(?:^|\n)(https:\/\/\S+)$/)
63-
if (!urlMatch) throw new Error(`Could not determine URL from issue ${issue.number}`)
60+
const matchURLInIssue = (issue) => {
61+
const match = issue.body.match(/(?:^|\n)(https:\/\/\S+)$/)
62+
return match && match[1]
63+
}
64+
65+
const matchURL = async () => {
66+
if (!issue.pull_request) return matchURLInIssue(issue)
67+
68+
const match = issue.body.match(/See (https:\/\/\S+) for details/)
69+
if (match) return match[1]
70+
}
71+
72+
const url = await matchURL()
73+
if (!url) throw new Error(`Could not determine URL from issue ${issue.number}`)
6474
return {
6575
type: 'feature',
66-
message: `Comes with [${package_name} v${version}](${urlMatch[1]}).`
76+
message: `Comes with [${package_name} v${version}](${url}).`
6777
}
6878
}
6979

0 commit comments

Comments
 (0)