Skip to content

Commit

Permalink
Add config option for pull-request-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ssolbeck committed Oct 3, 2023
1 parent 576ba52 commit 962d622
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/generate-fixtures.js
Expand Up @@ -86,6 +86,7 @@ for (const repo of repos) {
withPullRequestURL: true,
withBaseRefName: true,
withHeadRefName: true,
pullRequestLimit: 5,
},
})
)
Expand Down
10 changes: 9 additions & 1 deletion dist/index.js
Expand Up @@ -142563,6 +142563,7 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
$after: String
$withBaseRefName: Boolean!
$withHeadRefName: Boolean!
$pullRequestLimit: Int!
) {
repository(name: $name, owner: $owner) {
object(expression: $targetCommitish) {
Expand All @@ -142583,7 +142584,7 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
login
}
}
associatedPullRequests(first: 5) {
associatedPullRequests(first: $pullRequestLimit) {
nodes {
title
number
Expand Down Expand Up @@ -142630,6 +142631,7 @@ const findCommitsWithAssociatedPullRequests = async ({
withPullRequestURL: config['change-template'].includes('$URL'),
withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'),
withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'),
pullRequestLimit: config['pull-request-limit'],
}
const includePaths = config['include-paths']
const dataPath = ['repository', 'object', 'history']
Expand Down Expand Up @@ -142824,6 +142826,7 @@ const DEFAULT_CONFIG = Object.freeze({
latest: 'true',
'filter-by-commitish': false,
commitish: '',
'pull-request-limit': 5,
'category-template': `## $TITLE`,
header: '',
footer: '',
Expand Down Expand Up @@ -143529,6 +143532,11 @@ const schema = (context) => {

commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']),

'pull-request-limit': Joi.number()
.positive()
.integer()
.default(DEFAULT_CONFIG['pull-request-limit']),

replacers: Joi.array()
.items(
Joi.object().keys({
Expand Down
4 changes: 3 additions & 1 deletion lib/commits.js
Expand Up @@ -40,6 +40,7 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
$after: String
$withBaseRefName: Boolean!
$withHeadRefName: Boolean!
$pullRequestLimit: Int!
) {
repository(name: $name, owner: $owner) {
object(expression: $targetCommitish) {
Expand All @@ -60,7 +61,7 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
login
}
}
associatedPullRequests(first: 5) {
associatedPullRequests(first: $pullRequestLimit) {
nodes {
title
number
Expand Down Expand Up @@ -107,6 +108,7 @@ const findCommitsWithAssociatedPullRequests = async ({
withPullRequestURL: config['change-template'].includes('$URL'),
withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'),
withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'),
pullRequestLimit: config['pull-request-limit'],
}
const includePaths = config['include-paths']
const dataPath = ['repository', 'object', 'history']
Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Expand Up @@ -30,6 +30,7 @@ const DEFAULT_CONFIG = Object.freeze({
latest: 'true',
'filter-by-commitish': false,
commitish: '',
'pull-request-limit': 5,
'category-template': `## $TITLE`,
header: '',
footer: '',
Expand Down
5 changes: 5 additions & 0 deletions lib/schema.js
Expand Up @@ -95,6 +95,11 @@ const schema = (context) => {

commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']),

'pull-request-limit': Joi.number()
.positive()
.integer()
.default(DEFAULT_CONFIG['pull-request-limit']),

replacers: Joi.array()
.items(
Joi.object().keys({
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/config/config-with-pull-request-limit.yml
@@ -0,0 +1,2 @@
template: '$CHANGES'
pull-request-limit: 34
72 changes: 72 additions & 0 deletions test/index.test.js
Expand Up @@ -2424,6 +2424,78 @@ describe('release-drafter', () => {
})
})

describe('with pull-request-limit config', () => {
it('uses the correct default when not specified', async () => {
getConfigMock()

nock('https://api.github.com')
.post('/graphql', (body) => {
if (
body.query.includes('query findCommitsWithAssociatedPullRequests')
) {
expect(body.variables.pullRequestLimit).toBe(5)
return true
}
return false
})
.reply(200, graphqlCommitsNoPRsPayload)

nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [])

nock('https://api.github.com')
.post('/repos/toolmantim/release-drafter-test-project/releases')
.reply(200, releasePayload)

const payload = pushPayload

await probot.receive({
name: 'push',
payload,
})

expect.assertions(1)
})

it('requests the specified number of associated PRs', async () => {
getConfigMock('config-with-pull-request-limit.yml')

nock('https://api.github.com')
.post('/graphql', (body) => {
if (
body.query.includes('query findCommitsWithAssociatedPullRequests')
) {
expect(body.variables.pullRequestLimit).toBe(34)
return true
}
return false
})
.reply(200, graphqlCommitsNoPRsPayload)

nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [])

nock('https://api.github.com')
.post('/repos/toolmantim/release-drafter-test-project/releases')
.reply(200, releasePayload)

const payload = pushPayload

await probot.receive({
name: 'push',
payload,
})

expect.assertions(1)
})
})

describe('config error handling', () => {
it('schema error', async () => {
getConfigMock('config-with-schema-error.yml')
Expand Down
2 changes: 2 additions & 0 deletions test/schema.test.js
Expand Up @@ -20,6 +20,7 @@ const validConfigs = [
[{ template, header: 'I am on top' }],
[{ template, footer: 'I am on bottm' }],
[{ template, header: 'I am on top', footer: 'I am on bottm' }],
[{ template, 'pull-request-limit': 49 }],
]

const invalidConfigs = [
Expand Down Expand Up @@ -53,6 +54,7 @@ const invalidConfigs = [
],
[{ replacers: [{ search: '123', replace: 123 }] }, 'must be a string'],
[{ commitish: false }, 'must be a string'],
[{ 'pull-request-limit': 'forty nine' }, 'must be a number'],
]

describe('schema', () => {
Expand Down

0 comments on commit 962d622

Please sign in to comment.