Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for configuring a delay between pull request creation calls #1504

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/manifest-releaser.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ documented in comments)
// absence defaults to false, causing calls to be issued concurrently.
"sequential-calls": false,

// sets a delay (in milliseconds) between pull request create calls. This may
// help avoid hitting secondary rate limits on pull request creation when a
// large number of pull requests are opened in a monorepo.
// Absence defaults to 0.
"pr-creation-delay-ms": 2000,

// per package configuration: at least one entry required.
// the key is the relative path from the repo root to the folder that contains
Expand Down
4 changes: 4 additions & 0 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@
"description": "When considering commit history, only look this many commits deep.",
"type": "number"
},
"pr-creation-delay-ms": {
"description": "Delay this many milliseconds between issuing pull request creation calls.",
"type": "number"
},
"sequential-calls": {
"description": "Whether to open pull requests/releases sequentially rather than concurrently. If you have many components, you may want to set this to avoid secondary rate limits.",
"type": "boolean"
Expand Down
12 changes: 12 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export interface ManifestOptions {
groupPullRequestTitlePattern?: string;
releaseSearchDepth?: number;
commitSearchDepth?: number;
prCreationDelayMs?: number;
}

interface ReleaserPackageConfig extends ReleaserConfigJson {
Expand Down Expand Up @@ -196,6 +197,7 @@ export interface ManifestConfig extends ReleaserConfigJson {
'group-pull-request-title-pattern'?: string;
'release-search-depth'?: number;
'commit-search-depth'?: number;
'pr-creation-delay-ms'?: number;
'sequential-calls'?: boolean;
}
// path => version
Expand All @@ -213,6 +215,7 @@ export const DEFAULT_SNAPSHOT_LABELS = ['autorelease: snapshot'];
export const SNOOZE_LABEL = 'autorelease: snooze';
const DEFAULT_RELEASE_SEARCH_DEPTH = 400;
const DEFAULT_COMMIT_SEARCH_DEPTH = 500;
const DEFAULT_PR_CREATION_DELAY_MS = 0;

export const MANIFEST_PULL_REQUEST_TITLE_PATTERN = 'chore: release ${branch}';

Expand Down Expand Up @@ -250,6 +253,7 @@ export class Manifest {
private groupPullRequestTitlePattern?: string;
readonly releaseSearchDepth: number;
readonly commitSearchDepth: number;
readonly prCreationDelayMs: number;

/**
* Create a Manifest from explicit config in code. This assumes that the
Expand Down Expand Up @@ -313,6 +317,8 @@ export class Manifest {
manifestOptions?.releaseSearchDepth || DEFAULT_RELEASE_SEARCH_DEPTH;
this.commitSearchDepth =
manifestOptions?.commitSearchDepth || DEFAULT_COMMIT_SEARCH_DEPTH;
this.prCreationDelayMs =
manifestOptions?.prCreationDelayMs || DEFAULT_PR_CREATION_DELAY_MS;
}

/**
Expand Down Expand Up @@ -867,6 +873,8 @@ export class Manifest {
skipLabeling: this.skipLabeling,
}
);

await sleepInMs(this.prCreationDelayMs);
return newPullRequest;
}

Expand Down Expand Up @@ -1220,6 +1228,7 @@ async function parseConfig(
releaseSearchDepth: config['release-search-depth'],
commitSearchDepth: config['commit-search-depth'],
sequentialCalls: config['sequential-calls'],
prCreationDelayMs: config['pr-creation-delay-ms'],
};
return {config: repositoryConfig, options: manifestOptions};
}
Expand Down Expand Up @@ -1534,3 +1543,6 @@ function tagMatchesConfig(
(!includeComponentInTag && !tag.component)
);
}

const sleepInMs = (ms: number) =>
new Promise(resolve => setTimeout(resolve, ms));
8 changes: 8 additions & 0 deletions test/fixtures/manifest/config/pr-creation-delay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"pr-creation-delay-ms": 5000,
"packages": {
".": {
"release-type": "simple"
}
}
}
27 changes: 27 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,33 @@ describe('Manifest', () => {
expect(manifest.commitSearchDepth).to.eql(50);
});

it('should configure PR creation delay from manifest', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('release-please-config.json', 'main')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/config/pr-creation-delay.json'
)
)
.withArgs('.release-please-manifest.json', 'main')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/versions/versions.json'
)
);
const manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch
);
expect(manifest.prCreationDelayMs).to.eql(5000);
});

it('should read changelog host from manifest', async () => {
const getFileContentsStub = sandbox.stub(
github,
Expand Down