From bd5cbba03ee8c20509a48592933043cdd0098966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sat, 26 Jan 2019 16:03:51 -0500 Subject: [PATCH 1/4] Do not report the (renamed) Renovate bot as a contributor --- scripts/changelog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index f0e4a255..f94f3091 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -688,7 +688,7 @@ function dedupeEntries(changelog, items) { // (with format `@username`) of everyone who contributed to this version. function extractContributors(entries) { const set = Object.values(entries).reduce((memo, pullRequest) => { - if (pullRequest.author.login !== "greenkeeper" && pullRequest.author.login !== "renovate-bot") { + if (pullRequest.author.login !== "renovate") { memo.add("@" + pullRequest.author.login); } From 85d87a3b37b3ec965c47b07aa001e4b07666f041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Tue, 29 Jan 2019 01:04:30 -0500 Subject: [PATCH 2/4] Make sure to retrieve the correct tag info when there is no commit attached to the tag --- scripts/changelog.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index f94f3091..a43d4d35 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -227,6 +227,7 @@ class RepositoryFetcher { repository(owner: "thelounge", name: $repositoryName) { ref(qualifiedName: $tag) { tag: target { + oid ... on Tag { commit: target { oid @@ -237,7 +238,7 @@ class RepositoryFetcher { } }`; const data = await this.fetch(tagQuery, {tag}); - return data.repository.ref.tag.commit; + return data.repository.ref.tag.commit || data.repository.ref.tag; } // Returns an array of annotated commits that have been made on the master From 682207ffe65381b1c5d7ab86dd3801ef7684f32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 30 Jan 2019 00:34:39 -0500 Subject: [PATCH 3/4] Use a __typename on commits and pull requests to discriminate on types This was done by checking if the entry had a title or a messageHeadline, which is rather brittle. --- scripts/changelog.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index a43d4d35..0bfba744 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -256,6 +256,7 @@ class RepositoryFetcher { endCursor } commits: nodes { + __typename oid abbreviatedOid messageHeadline @@ -378,6 +379,7 @@ class RepositoryFetcher { repository(owner: "thelounge", name: $repositoryName) { ${numbers.map((number) => ` PR${number}: pullRequest(number: ${number}) { + __typename title url author { @@ -457,7 +459,7 @@ function printAuthorLink({login, url}) { // Builds a Markdown link for a given pull request or commit object function printEntryLink(entry) { - const label = entry.title + const label = entry.__typename === "PullRequest" ? `#${entry.number}` : `\`${entry.abbreviatedOid}\``; @@ -466,7 +468,7 @@ function printEntryLink(entry) { // Builds a Markdown entry list item depending on its type function printLine(entry) { - if (entry.title) { + if (entry.__typename === "PullRequest") { return printPullRequest(entry); } @@ -550,7 +552,7 @@ function hasAnnotatedComment(comments, expected) { function isSkipped(entry) { return ( - (entry.messageHeadline && ( + (entry.__typename === "Commit" && ( // Version bump commits created by `yarn version` isValidVersion(entry.messageHeadline) || // Commit message suggested by this script From 7c024864b2e3c2d469a26e441cadc7943ae549a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 30 Jan 2019 00:37:06 -0500 Subject: [PATCH 4/4] Improve discriminating bots from actual contributors in the list of PRs/commits --- scripts/changelog.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index 0bfba744..00fbadfc 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -299,8 +299,6 @@ class RepositoryFetcher { const commits = await fetchPaginatedCommits(); commits.forEach((commit) => { - commit.author = commit.author.user; - const resultPR = /^Merge pull request #([0-9]+) .+/.exec(commit.messageHeadline); if (resultPR) { @@ -383,6 +381,7 @@ class RepositoryFetcher { title url author { + __typename login url } @@ -482,7 +481,7 @@ function printPullRequest(pullRequest) { // Builds a Markdown list item for a commit made directly in `master` function printCommit(commit) { - return `- ${commit.messageHeadline} (${printEntryLink(commit)} ${printAuthorLink(commit.author)})`; + return `- ${commit.messageHeadline} (${printEntryLink(commit)} ${printAuthorLink(commit.author.user)})`; } // Builds a Markdown list of all given items @@ -690,9 +689,13 @@ function dedupeEntries(changelog, items) { // Given a list of entries (pull requests, commits), retrieves GitHub usernames // (with format `@username`) of everyone who contributed to this version. function extractContributors(entries) { - const set = Object.values(entries).reduce((memo, pullRequest) => { - if (pullRequest.author.login !== "renovate") { - memo.add("@" + pullRequest.author.login); + const set = Object.values(entries).reduce((memo, {__typename, author}) => { + if (__typename === "PullRequest" && author.__typename !== "Bot") { + memo.add("@" + author.login); + // Commit authors are *always* of type "User", so have to discriminate some + // other way. Making the assumption of a suffix for now, see how that goes. + } else if (__typename === "Commit" && !author.user.login.endsWith("-bot")) { + memo.add("@" + author.user.login); } return memo;