Skip to content

Commit

Permalink
Fix: Correctly mention bot accounts in release notes
Browse files Browse the repository at this point in the history
As noted in release-drafter#60, bot accounts are currently being mis-mentioned, where
instead of linking through to `dependabot[bot]` it'll tag a user
`@dependabot` which isn't the same, and can result in unwanted
notifications.

To address this, we can retrieve the type of user that has authored a
Pull Request, looking at the `__typename` to determine if it's a `Bot`
or a `User` account, and provide a Markdown link to the Bot account's
app page.

Unfortunately this may result in a name such as:

    @[dependabot[bot]](https://github.com/apps/dependabot)

But this is a better result than tagging the wrong account.

Closes release-drafter#60.
  • Loading branch information
jamietanna committed Jan 3, 2024
1 parent 09c613e commit 8b04f12
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 16 deletions.
27 changes: 22 additions & 5 deletions dist/index.js
Expand Up @@ -142591,6 +142591,8 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
body @include(if: $withPullRequestBody)
author {
login
__typename
url
}
baseRepository {
nameWithOwner
Expand Down Expand Up @@ -143027,7 +143029,13 @@ const contributorsSentence = ({ commits, pullRequests, config }) => {
pullRequest.author &&
!excludeContributors.includes(pullRequest.author.login)
) {
contributors.add(`@${pullRequest.author.login}`)
if (pullRequest.author.__typename === 'Bot') {
contributors.add(
`[${pullRequest.author.login}[bot]](${pullRequest.author.url})`
)
} else {
contributors.add(`@${pullRequest.author.login}`)
}
}
}

Expand Down Expand Up @@ -143151,17 +143159,26 @@ const generateChangeLog = (mergedPullRequests, config) => {

const pullRequestToString = (pullRequests) =>
pullRequests
.map((pullRequest) =>
template(config['change-template'], {
.map((pullRequest) => {
var pullAuthor = 'ghost'
if (pullRequest.author) {
pullAuthor =
pullRequest.author.__typename &&
pullRequest.author.__typename === 'Bot'
? `[${pullRequest.author.login}[bot]](${pullRequest.author.url})`
: pullRequest.author.login
}

return template(config['change-template'], {
$TITLE: escapeTitle(pullRequest.title),
$NUMBER: pullRequest.number,
$AUTHOR: pullRequest.author ? pullRequest.author.login : 'ghost',
$AUTHOR: pullAuthor,
$BODY: pullRequest.body,
$URL: pullRequest.url,
$BASE_REF_NAME: pullRequest.baseRefName,
$HEAD_REF_NAME: pullRequest.headRefName,
})
)
})
.join('\n')

const changeLog = []
Expand Down
2 changes: 2 additions & 0 deletions lib/commits.js
Expand Up @@ -68,6 +68,8 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
body @include(if: $withPullRequestBody)
author {
login
__typename
url
}
baseRepository {
nameWithOwner
Expand Down
25 changes: 20 additions & 5 deletions lib/releases.js
Expand Up @@ -111,7 +111,13 @@ const contributorsSentence = ({ commits, pullRequests, config }) => {
pullRequest.author &&
!excludeContributors.includes(pullRequest.author.login)
) {
contributors.add(`@${pullRequest.author.login}`)
if (pullRequest.author.__typename === 'Bot') {
contributors.add(
`[${pullRequest.author.login}[bot]](${pullRequest.author.url})`
)
} else {
contributors.add(`@${pullRequest.author.login}`)
}
}
}

Expand Down Expand Up @@ -235,17 +241,26 @@ const generateChangeLog = (mergedPullRequests, config) => {

const pullRequestToString = (pullRequests) =>
pullRequests
.map((pullRequest) =>
template(config['change-template'], {
.map((pullRequest) => {
var pullAuthor = 'ghost'
if (pullRequest.author) {
pullAuthor =
pullRequest.author.__typename &&
pullRequest.author.__typename === 'Bot'
? `[${pullRequest.author.login}[bot]](${pullRequest.author.url})`
: pullRequest.author.login
}

return template(config['change-template'], {
$TITLE: escapeTitle(pullRequest.title),
$NUMBER: pullRequest.number,
$AUTHOR: pullRequest.author ? pullRequest.author.login : 'ghost',
$AUTHOR: pullAuthor,
$BODY: pullRequest.body,
$URL: pullRequest.url,
$BASE_REF_NAME: pullRequest.baseRefName,
$HEAD_REF_NAME: pullRequest.headRefName,
})
)
})
.join('\n')

const changeLog = []
Expand Down
35 changes: 29 additions & 6 deletions test/releases.test.js
Expand Up @@ -80,6 +80,21 @@ const pullRequests = [
baseRefName: 'master',
headRefName: 'implement-feature',
},
{
title: 'Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples',
number: 0,
body: 'Updates the dependency ....',
url: 'https://github.com',
labels: { nodes: [{ name: 'dependencies' }] },
author: {
login: 'dependabot',
// although the RESTful API returns a `type: "Bot"`, GraphQL only allows us to look up based on the `__typename`
__typename: 'Bot',
url: 'https://github.com/apps/dependabot',
},
baseRefName: 'master',
headRefName: 'dependabot/go_modules/examples/golang.org/x/crypto-0.17.0',
},
]
const baseConfig = {
...DEFAULT_CONFIG,
Expand All @@ -99,7 +114,8 @@ describe('releases', () => {
* Fixes #4 (#5) @Happypig375
* 2*2 should equal to 4*1 (#6) @jetersen
* Rename __confgs\\\\confg.yml to __configs\\\\config.yml (#7) @ghost
* Adds @nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375"
* Adds @nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)"
`)
})
it('escapes titles with \\s correctly', () => {
Expand All @@ -116,7 +132,8 @@ describe('releases', () => {
* Fixes #4 (#5) @Happypig375
* 2*2 should equal to 4*1 (#6) @jetersen
* Rename __confgs\\\\\\\\confg.yml to __configs\\\\\\\\config.yml (#7) @ghost
* Adds @nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375"
* Adds @nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)"
`)
})
it('escapes titles with \\<*_& correctly', () => {
Expand All @@ -133,7 +150,8 @@ describe('releases', () => {
* Fixes #4 (#5) @Happypig375
* 2\\\\*2 should equal to 4\\\\*1 (#6) @jetersen
* Rename \\\\_\\\\_confgs\\\\\\\\confg.yml to \\\\_\\\\_configs\\\\\\\\config.yml (#7) @ghost
* Adds @nullable annotations to the 1\\\\*1+2\\\\*4 test in \`tests.java\` (#0) @Happypig375"
* Adds @nullable annotations to the 1\\\\*1+2\\\\*4 test in \`tests.java\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)"
`)
})
it('escapes titles with @s correctly', () => {
Expand All @@ -150,7 +168,8 @@ describe('releases', () => {
* Fixes #4 (#5) @Happypig375
* 2*2 should equal to 4*1 (#6) @jetersen
* Rename __confgs\\\\confg.yml to __configs\\\\config.yml (#7) @ghost
* Adds @<!---->nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375"
* Adds @<!---->nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)"
`)
})
it('escapes titles with @s and #s correctly', () => {
Expand All @@ -167,7 +186,8 @@ describe('releases', () => {
* Fixes #<!---->4 (#5) @Happypig375
* 2*2 should equal to 4*1 (#6) @jetersen
* Rename __confgs\\\\confg.yml to __configs\\\\config.yml (#7) @ghost
* Adds @<!---->nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375"
* Adds @<!---->nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)"
`)
})
it('escapes titles with \\<@*_&`# correctly', () => {
Expand All @@ -184,7 +204,8 @@ describe('releases', () => {
* Fixes #<!---->4 (#5) @Happypig375
* 2\\\\*2 should equal to 4\\\\*1 (#6) @jetersen
* Rename \\\\_\\\\_confgs\\\\\\\\confg.yml to \\\\_\\\\_configs\\\\\\\\config.yml (#7) @ghost
* Adds @<!---->nullable annotations to the 1\\\\*1+2\\\\*4 test in \\\\\`tests.java\\\\\` (#0) @Happypig375"
* Adds @<!---->nullable annotations to the 1\\\\*1+2\\\\*4 test in \\\\\`tests.java\\\\\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)"
`)
})
it('adds proper details/summary markdown when collapse-after is set and more than 3 PRs', () => {
Expand All @@ -197,6 +218,7 @@ describe('releases', () => {
"* B2 (#2) @ghost
* Rename __confgs\\\\confg.yml to __configs\\\\config.yml (#7) @ghost
* Adds @nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)
## Bugs
Expand Down Expand Up @@ -227,6 +249,7 @@ describe('releases', () => {
* Fixes #4 (#5) @Happypig375
* 2*2 should equal to 4*1 (#6) @jetersen
* Rename __confgs\\\\confg.yml to __configs\\\\config.yml (#7) @ghost
* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /examples (#0) @[dependabot[bot]](https://github.com/apps/dependabot)
## Feature
Expand Down

0 comments on commit 8b04f12

Please sign in to comment.