Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
actions: Create script for generating release notes
- Loading branch information
1 parent
c4e5a21
commit b7bdbff
Showing
4 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
.github/workflows/scripts/releases/generate-release-notes/.gitignore
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,2 @@ | ||
node_modules/ | ||
*.md |
64 changes: 64 additions & 0 deletions
64
.github/workflows/scripts/releases/generate-release-notes/index.js
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,64 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { throttling } from "@octokit/plugin-throttling"; | ||
import { retry } from "@octokit/plugin-retry"; | ||
Octokit.plugin(throttling); | ||
Octokit.plugin(retry); | ||
const octokit = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN, | ||
userAgent: 'PCSX2/pcsx2', | ||
log: { | ||
debug: () => { }, | ||
info: () => { }, | ||
warn: console.warn, | ||
error: console.error | ||
}, | ||
throttle: { | ||
onRateLimit: (retryAfter, options) => { | ||
octokit.log.warn( | ||
`Request quota exhausted for request ${options.method} ${options.url}` | ||
); | ||
|
||
// Retry twice after hitting a rate limit error, then give up | ||
if (options.request.retryCount <= 2) { | ||
console.log(`Retrying after ${retryAfter} seconds!`); | ||
return true; | ||
} | ||
}, | ||
onAbuseLimit: (retryAfter, options) => { | ||
// does not retry, only logs a warning | ||
octokit.log.warn( | ||
`Abuse detected for request ${options.method} ${options.url}` | ||
); | ||
}, | ||
} | ||
}); | ||
|
||
var args = process.argv.slice(2); | ||
let commitSha = process.env.COMMIT_SHA; | ||
|
||
console.log(`Searching for Commit - ${commitSha}`); | ||
|
||
const { data: commit } = await octokit.rest.repos.getCommit({ | ||
owner: "PCSX2", | ||
repo: "pcsx2", | ||
ref: commitSha, | ||
}); | ||
|
||
const { data: associatedPulls } = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
owner: "PCSX2", | ||
repo: "pcsx2", | ||
commit_sha: commit.sha, | ||
}); | ||
|
||
let releaseNotes = ``; | ||
|
||
if (associatedPulls.length == 0) { | ||
releaseNotes += `- ${commit.commit.message}\n`; | ||
} else { | ||
for (var j = 0; j < associatedPulls.length; j++) { | ||
releaseNotes += `- [${associatedPulls[j].title}](${associatedPulls[j].html_url})\n`; | ||
} | ||
} | ||
|
||
import * as fs from 'fs'; | ||
fs.writeFileSync('./release-notes.md', releaseNotes); |
202 changes: 202 additions & 0 deletions
202
.github/workflows/scripts/releases/generate-release-notes/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
.github/workflows/scripts/releases/generate-release-notes/package.json
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,17 @@ | ||
{ | ||
"name": "generate-release-notes", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@octokit/plugin-retry": "^3.0.9", | ||
"@octokit/plugin-throttling": "^3.5.2", | ||
"@octokit/rest": "^18.12.0" | ||
} | ||
} |