Skip to content

Commit 923fffe

Browse files
gjvoostencchanche
andauthored
Add config option for history-limit (#1470)
* Add config option for history-limit (#1450) Also document this and the previously added pull-request-limit in the README. * Update description of new options in README (#1450, #1362) --------- Co-authored-by: Clément Chanchevrier <[email protected]>
1 parent fa20e47 commit 923fffe

9 files changed

Lines changed: 97 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ You can configure Release Drafter using the following key in your `.github/relea
146146
| `commitish` | Optional | The release target, i.e. branch or commit it should point to. Default: the ref that release-drafter runs for, e.g. `refs/heads/master` if configured to run on pushes to `master`. |
147147
| `filter-by-commitish` | Optional | Filter previous releases to consider only those with the target matching `commitish`. Default: `false`. |
148148
| `include-paths` | Optional | Restrict pull requests included in the release notes to only the pull requests that modified any of the paths in this array. Supports files and directories. Default: `[]` |
149+
| `pull-request-limit` | Optional | Limit for associatedPullRequests API call. Use this when working with long-lived non-default branches. See #1354. Default: `5` |
150+
| `history-limit` | Optional | Size of the pagination window when walking the repo. Can avoid erratic 502s from Github. Default: `15` |
149151
| `initial-commits-since` | Optional | When drafting your first release, limit the amount of scanned commits. Expects an ISO 8601 date, ex: `"2025-06-18T10:29:51Z"`. Default: `""` (unlimited) |
150152

151153
Release Drafter also supports [Probot Config](https://github.com/probot/probot-config), if you want to store your configuration files in a central repository. This allows you to share configurations between projects, and create a organization-wide configuration file by creating a repository named `.github` with the file `.github/release-drafter.yml`.

bin/generate-fixtures.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ for (const repo of repos) {
8787
withBaseRefName: true,
8888
withHeadRefName: true,
8989
pullRequestLimit: 5,
90+
historyLimit: 15,
9091
},
9192
})
9293
)

dist/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193761,11 +193761,12 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
193761193761
$withBaseRefName: Boolean!
193762193762
$withHeadRefName: Boolean!
193763193763
$pullRequestLimit: Int!
193764+
$historyLimit: Int!
193764193765
) {
193765193766
repository(name: $name, owner: $owner) {
193766193767
object(expression: $targetCommitish) {
193767193768
... on Commit {
193768-
history(first: 100, since: $since, after: $after) {
193769+
history(first: $historyLimit, since: $since, after: $after) {
193769193770
totalCount
193770193771
pageInfo {
193771193772
hasNextPage
@@ -193831,6 +193832,7 @@ const findCommitsWithAssociatedPullRequests = async ({
193831193832
withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'),
193832193833
withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'),
193833193834
pullRequestLimit: config['pull-request-limit'],
193835+
historyLimit: config['history-limit'],
193834193836
}
193835193837
const includePaths = config['include-paths']
193836193838
const dataPath = ['repository', 'object', 'history']
@@ -194043,6 +194045,7 @@ const DEFAULT_CONFIG = Object.freeze({
194043194045
'filter-by-commitish': false,
194044194046
commitish: '',
194045194047
'pull-request-limit': 5,
194048+
'history-limit': 15,
194046194049
'category-template': `## $TITLE`,
194047194050
header: '',
194048194051
footer: '',
@@ -194772,6 +194775,11 @@ const schema = (context) => {
194772194775
.integer()
194773194776
.default(DEFAULT_CONFIG['pull-request-limit']),
194774194777

194778+
'history-limit': Joi.number()
194779+
.positive()
194780+
.integer()
194781+
.default(DEFAULT_CONFIG['history-limit']),
194782+
194775194783
replacers: Joi.array()
194776194784
.items(
194777194785
Joi.object().keys({

lib/commits.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
4343
$withBaseRefName: Boolean!
4444
$withHeadRefName: Boolean!
4545
$pullRequestLimit: Int!
46+
$historyLimit: Int!
4647
) {
4748
repository(name: $name, owner: $owner) {
4849
object(expression: $targetCommitish) {
4950
... on Commit {
50-
history(first: 100, since: $since, after: $after) {
51+
history(first: $historyLimit, since: $since, after: $after) {
5152
totalCount
5253
pageInfo {
5354
hasNextPage
@@ -113,6 +114,7 @@ const findCommitsWithAssociatedPullRequests = async ({
113114
withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'),
114115
withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'),
115116
pullRequestLimit: config['pull-request-limit'],
117+
historyLimit: config['history-limit'],
116118
}
117119
const includePaths = config['include-paths']
118120
const dataPath = ['repository', 'object', 'history']

lib/default-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DEFAULT_CONFIG = Object.freeze({
3131
'filter-by-commitish': false,
3232
commitish: '',
3333
'pull-request-limit': 5,
34+
'history-limit': 15,
3435
'category-template': `## $TITLE`,
3536
header: '',
3637
footer: '',

lib/schema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ const schema = (context) => {
102102
.integer()
103103
.default(DEFAULT_CONFIG['pull-request-limit']),
104104

105+
'history-limit': Joi.number()
106+
.positive()
107+
.integer()
108+
.default(DEFAULT_CONFIG['history-limit']),
109+
105110
replacers: Joi.array()
106111
.items(
107112
Joi.object().keys({
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
template: '$CHANGES'
2+
history-limit: 42

test/index.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,78 @@ describe('release-drafter', () => {
24962496
})
24972497
})
24982498

2499+
describe('with history-limit config', () => {
2500+
it('uses the correct default when not specified', async () => {
2501+
getConfigMock()
2502+
2503+
nock('https://api.github.com')
2504+
.post('/graphql', (body) => {
2505+
if (
2506+
body.query.includes('query findCommitsWithAssociatedPullRequests')
2507+
) {
2508+
expect(body.variables.historyLimit).toBe(15)
2509+
return true
2510+
}
2511+
return false
2512+
})
2513+
.reply(200, graphqlCommitsNoPRsPayload)
2514+
2515+
nock('https://api.github.com')
2516+
.get(
2517+
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
2518+
)
2519+
.reply(200, [])
2520+
2521+
nock('https://api.github.com')
2522+
.post('/repos/toolmantim/release-drafter-test-project/releases')
2523+
.reply(200, releasePayload)
2524+
2525+
const payload = pushPayload
2526+
2527+
await probot.receive({
2528+
name: 'push',
2529+
payload,
2530+
})
2531+
2532+
expect.assertions(1)
2533+
})
2534+
2535+
it('requests the specified number of associated PRs', async () => {
2536+
getConfigMock('config-with-history-limit.yml')
2537+
2538+
nock('https://api.github.com')
2539+
.post('/graphql', (body) => {
2540+
if (
2541+
body.query.includes('query findCommitsWithAssociatedPullRequests')
2542+
) {
2543+
expect(body.variables.historyLimit).toBe(42)
2544+
return true
2545+
}
2546+
return false
2547+
})
2548+
.reply(200, graphqlCommitsNoPRsPayload)
2549+
2550+
nock('https://api.github.com')
2551+
.get(
2552+
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
2553+
)
2554+
.reply(200, [])
2555+
2556+
nock('https://api.github.com')
2557+
.post('/repos/toolmantim/release-drafter-test-project/releases')
2558+
.reply(200, releasePayload)
2559+
2560+
const payload = pushPayload
2561+
2562+
await probot.receive({
2563+
name: 'push',
2564+
payload,
2565+
})
2566+
2567+
expect.assertions(1)
2568+
})
2569+
})
2570+
24992571
describe('config error handling', () => {
25002572
it('schema error', async () => {
25012573
getConfigMock('config-with-schema-error.yml')

test/schema.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const validConfigs = [
2121
[{ template, footer: 'I am on bottm' }],
2222
[{ template, header: 'I am on top', footer: 'I am on bottm' }],
2323
[{ template, 'pull-request-limit': 49 }],
24+
[{ template, 'history-limit': 17 }],
2425
[
2526
{ template, 'initial-commits-since': '2025-06-18T10:29:51Z' },
2627
{ template, 'initial-commits-since': new Date('2025-06-18T10:29:51Z') },
@@ -60,6 +61,7 @@ const invalidConfigs = [
6061
[{ replacers: [{ search: '123', replace: 123 }] }, 'must be a string'],
6162
[{ commitish: false }, 'must be a string'],
6263
[{ 'pull-request-limit': 'forty nine' }, 'must be a number'],
64+
[{ 'history-limit': 'seventeen' }, 'must be a number'],
6365
[{ 'initial-commits-since': 'a day' }, 'must be in ISO 8601 date format'],
6466
[
6567
{

0 commit comments

Comments
 (0)