Skip to content

Commit

Permalink
gen-changelog: remove hardcoded GitHub org and repo (#2035)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 15, 2019
1 parent 49d86bb commit 3cd06f1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions resources/gen-changelog.js
Expand Up @@ -42,6 +42,20 @@ if (!GH_TOKEN) {
process.exit(1);
}

if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') {
console.error('package.json is missing repository.url string!');
process.exit(1);
}

const match = /https:\/\/github.com\/([^/]+)\/([^/]+).git/.exec(
packageJSON.repository.url,
);
if (match == null) {
console.error('Can not extract organisation and repo name from repo URL!');
process.exit(1);
}
const [, githubOrg, githubRepo] = match;

getChangeLog()
.then(changelog => process.stdout.write(changelog))
.catch(error => console.error(error));
Expand Down Expand Up @@ -120,7 +134,7 @@ function graphqlRequestImpl(query, variables, cb) {
headers: {
Authorization: 'bearer ' + GH_TOKEN,
'Content-Type': 'application/json',
'User-Agent': 'graphql-js-changelog',
'User-Agent': 'gen-changelog',
},
});

Expand Down Expand Up @@ -200,7 +214,7 @@ async function batchCommitInfo(commits) {

const response = await graphqlRequest(`
{
repository(owner: "graphql", name: "graphql-js") {
repository(owner: "${githubOrg}", name: "${githubRepo}") {
${commitsSubQuery}
}
}
Expand All @@ -217,7 +231,7 @@ function commitsInfoToPRs(commits) {
const prs = {};
for (const commit of commits) {
const associatedPRs = commit.associatedPullRequests.nodes.filter(
pr => pr.repository.nameWithOwner === 'graphql/graphql-js',
pr => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
);
if (associatedPRs.length === 0) {
throw new Error(
Expand Down

0 comments on commit 3cd06f1

Please sign in to comment.