Skip to content

Commit 0458658

Browse files
Copilotkategengler
andauthored
Replace deprecated github package with @octokit/rest in bin/changelog.js (#21277)
Co-authored-by: kategengler <444218+kategengler@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Katie Gengler <katie@kmg.io>
1 parent 8d1f5d2 commit 0458658

3 files changed

Lines changed: 190 additions & 39 deletions

File tree

bin/changelog.js

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,69 @@
1414
* bin/changelog.js
1515
*/
1616

17-
const RSVP = require('rsvp');
18-
const GitHubApi = require('github');
17+
const { Octokit } = require('@octokit/rest');
1918
const execSync = require('child_process').execSync;
2019

21-
const github = new GitHubApi({ version: '3.0.0' });
22-
if (process.env.GITHUB_TOKEN) {
23-
github.authenticate({
24-
type: 'token',
25-
token: process.env.GITHUB_TOKEN,
26-
});
27-
}
28-
const compareCommits = RSVP.denodeify(github.repos.compareCommits);
29-
const getPullRequest = RSVP.denodeify(github.pullRequests.get);
20+
const octokit = new Octokit({
21+
auth: process.env.GITHUB_TOKEN,
22+
});
23+
24+
const DEBUG = process.env.DEBUG === 'true';
25+
const debug = (...args) => DEBUG && console.error('[DEBUG]', ...args);
3026

3127
const currentVersion = process.env.PRIOR_VERSION;
32-
const head = process.env.HEAD || execSync('git rev-parse HEAD', { encoding: 'UTF-8' });
28+
const head = (process.env.HEAD || execSync('git rev-parse HEAD', { encoding: 'UTF-8' })).trim();
29+
30+
debug('Current version:', currentVersion);
31+
debug('Head:', head);
3332

3433
generateChangelog()
3534
.then(console.log)
3635
.catch((err) => console.error(err));
3736

3837
async function fetchAllChanges() {
39-
let result = await compareCommits({
40-
user: 'emberjs',
38+
debug('Fetching comparison:', `${currentVersion}...${head}`);
39+
const comparison = await octokit.repos.compareCommitsWithBasehead({
40+
owner: 'emberjs',
4141
repo: 'ember.js',
42-
base: currentVersion,
43-
head,
42+
basehead: `${currentVersion}...${head}`,
43+
per_page: 100,
4444
});
45-
let data = result.commits;
46-
while (github.hasNextPage(result)) {
47-
result = await github.getNextPage(result);
48-
data.concat(result.commits);
45+
46+
let commits = comparison.data.commits;
47+
const totalCommits = comparison.data.total_commits;
48+
debug('Total commits:', totalCommits, 'Fetched:', commits.length);
49+
50+
// If there are more commits than returned, fetch them page by page
51+
if (totalCommits > commits.length) {
52+
let page = 2;
53+
while (commits.length < totalCommits) {
54+
debug('Fetching page:', page);
55+
const nextPage = await octokit.repos.compareCommitsWithBasehead({
56+
owner: 'emberjs',
57+
repo: 'ember.js',
58+
basehead: `${currentVersion}...${head}`,
59+
per_page: 100,
60+
page: page,
61+
});
62+
commits = commits.concat(nextPage.data.commits);
63+
debug('Now have', commits.length, 'commits');
64+
page++;
65+
66+
// Safety check to prevent infinite loops
67+
if (nextPage.data.commits.length === 0) break;
68+
}
4969
}
5070

51-
return data;
71+
return commits;
5272
}
5373

5474
async function generateChangelog() {
5575
let commits = await fetchAllChanges();
76+
debug('Processing', commits.length, 'commits');
5677

5778
let contributions = commits.filter(excludeDependabot).filter(isMergeOrCherryPick);
79+
debug('Found', contributions.length, 'contributions after filtering');
5880

5981
let changes = await Promise.all(
6082
contributions.map(async function (commitInfo) {
@@ -83,10 +105,12 @@ async function generateChangelog() {
83105
result.title = message.split('\n\n')[0];
84106
}
85107

108+
debug('Processed commit:', result.number || result.sha.slice(0, 8), '-', result.title);
86109
return result;
87110
})
88111
);
89112

113+
debug('Sorting and deduplicating changes');
90114
return changes
91115
.sort(comparePrNumber)
92116
.filter(uniqueByPrNumber)
@@ -112,6 +136,7 @@ async function getCommitMessage(commitInfo) {
112136
let matches;
113137

114138
if (message.indexOf('cherry picked from commit') > -1) {
139+
debug('Processing cherry-pick commit:', commitInfo.sha.slice(0, 8));
115140
let cherryPickRegex = /cherry picked from commit ([a-z0-9]+)/;
116141
let originalCommit = cherryPickRegex.exec(message)[1];
117142

@@ -125,7 +150,9 @@ async function getCommitMessage(commitInfo) {
125150
'..origin/main --first-parent | cat -n) | sort -k2 | uniq -f1 -d | sort -n | tail -1 | cut -f2) && git show --format="%s\n\n%b" $commit',
126151
{ encoding: 'utf8' }
127152
);
153+
debug('Found original merge commit for cherry-pick');
128154
} catch {
155+
debug('Could not find original merge commit for cherry-pick');
129156
// ignored
130157
}
131158
}
@@ -139,10 +166,11 @@ async function getCommitMessage(commitInfo) {
139166
let lines = message.split(/\n\n/);
140167

141168
if (!lines[1]) {
142-
let pullRequest = await getPullRequest({
143-
user: 'emberjs',
169+
debug('Fetching PR title for #' + prNumber);
170+
let { data: pullRequest } = await octokit.pulls.get({
171+
owner: 'emberjs',
144172
repo: 'ember.js',
145-
number: prNumber,
173+
pull_number: prNumber,
146174
});
147175
return `Merge pull request #${prNumber}\n\n${pullRequest.title}`;
148176
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@embroider/vite": "^1.7.2",
9090
"@eslint/js": "^9.21.0",
9191
"@glimmer/component": "workspace:*",
92+
"@octokit/rest": "^20.1.2",
9293
"@rollup/plugin-babel": "^6.0.4",
9394
"@simple-dom/document": "^1.4.0",
9495
"@swc-node/register": "^1.6.8",
@@ -118,7 +119,6 @@
118119
"expect-type": "^0.15.0",
119120
"fs-extra": "^11.1.1",
120121
"git-repo-info": "^2.1.1",
121-
"github": "^0.2.3",
122122
"glob": "^8.0.3",
123123
"globals": "^16.0.0",
124124
"kill-port-process": "^3.2.1",

0 commit comments

Comments
 (0)