Skip to content

Commit 3cd06f1

Browse files
gen-changelog: remove hardcoded GitHub org and repo (#2035)
1 parent 49d86bb commit 3cd06f1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

resources/gen-changelog.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ if (!GH_TOKEN) {
4242
process.exit(1);
4343
}
4444

45+
if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') {
46+
console.error('package.json is missing repository.url string!');
47+
process.exit(1);
48+
}
49+
50+
const match = /https:\/\/github.com\/([^/]+)\/([^/]+).git/.exec(
51+
packageJSON.repository.url,
52+
);
53+
if (match == null) {
54+
console.error('Can not extract organisation and repo name from repo URL!');
55+
process.exit(1);
56+
}
57+
const [, githubOrg, githubRepo] = match;
58+
4559
getChangeLog()
4660
.then(changelog => process.stdout.write(changelog))
4761
.catch(error => console.error(error));
@@ -120,7 +134,7 @@ function graphqlRequestImpl(query, variables, cb) {
120134
headers: {
121135
Authorization: 'bearer ' + GH_TOKEN,
122136
'Content-Type': 'application/json',
123-
'User-Agent': 'graphql-js-changelog',
137+
'User-Agent': 'gen-changelog',
124138
},
125139
});
126140

@@ -200,7 +214,7 @@ async function batchCommitInfo(commits) {
200214

201215
const response = await graphqlRequest(`
202216
{
203-
repository(owner: "graphql", name: "graphql-js") {
217+
repository(owner: "${githubOrg}", name: "${githubRepo}") {
204218
${commitsSubQuery}
205219
}
206220
}
@@ -217,7 +231,7 @@ function commitsInfoToPRs(commits) {
217231
const prs = {};
218232
for (const commit of commits) {
219233
const associatedPRs = commit.associatedPullRequests.nodes.filter(
220-
pr => pr.repository.nameWithOwner === 'graphql/graphql-js',
234+
pr => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
221235
);
222236
if (associatedPRs.length === 0) {
223237
throw new Error(

0 commit comments

Comments
 (0)