mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-10 14:06:30 +00:00
Merge 9bc20992dc
into 1d2c1a35e3
This commit is contained in:
commit
a6418f0f6f
3 changed files with 117 additions and 16 deletions
|
@ -61,6 +61,15 @@ The formula for the delay between attempts is `RENOVATE_X_GITLAB_MERGE_REQUEST_D
|
|||
|
||||
Default value: `5` (attempts results in max. 13.75 seconds timeout).
|
||||
|
||||
## `RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPTS`
|
||||
|
||||
If set to a positive integer, Renovate will use this as the number of attempts to check branch status before trying to add a status check.
|
||||
The delay between attempts is `RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY` milliseconds.
|
||||
|
||||
Default value: `2` (attempts results in maximum 2 seconds timeout).
|
||||
|
||||
!!! warning Increasing this value too much penalizes projects that do not have defined pipelines, Renovate will systematically wait `RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPTS * RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY` milliseconds on these projects and slow down the Renovate analyzes.
|
||||
|
||||
## `RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY`
|
||||
|
||||
Adjust default time (in milliseconds) given to GitLab to create pipelines for a commit pushed by Renovate.
|
||||
|
|
|
@ -51,6 +51,7 @@ describe('modules/platform/gitlab/index', () => {
|
|||
token: '123test',
|
||||
});
|
||||
delete process.env.GITLAB_IGNORE_REPO_URL;
|
||||
delete process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPTS;
|
||||
delete process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY;
|
||||
delete process.env.RENOVATE_X_GITLAB_AUTO_MERGEABLE_CHECK_ATTEMPS;
|
||||
delete process.env.RENOVATE_X_GITLAB_MERGE_REQUEST_DELAY;
|
||||
|
@ -1058,6 +1059,20 @@ describe('modules/platform/gitlab/index', () => {
|
|||
describe('setBranchStatus', () => {
|
||||
const states: BranchStatus[] = ['green', 'yellow', 'red'];
|
||||
|
||||
it('should log message that branch commit SHA not found', async () => {
|
||||
git.getBranchCommit.mockReturnValue(null);
|
||||
await gitlab.setBranchStatus({
|
||||
branchName: 'some-branch',
|
||||
context: 'some-context',
|
||||
description: 'some-description',
|
||||
state: 'green',
|
||||
url: 'some-url',
|
||||
});
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'Failed to get the branch commit SHA',
|
||||
);
|
||||
});
|
||||
|
||||
it.each(states)('sets branch status %s', async (state) => {
|
||||
const scope = await initRepo();
|
||||
scope
|
||||
|
@ -1072,6 +1087,10 @@ describe('modules/platform/gitlab/index', () => {
|
|||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, []);
|
||||
|
||||
await expect(
|
||||
|
@ -1099,6 +1118,10 @@ describe('modules/platform/gitlab/index', () => {
|
|||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, []);
|
||||
|
||||
await gitlab.setBranchStatus({
|
||||
|
@ -1109,7 +1132,7 @@ describe('modules/platform/gitlab/index', () => {
|
|||
url: 'some-url',
|
||||
});
|
||||
|
||||
expect(timers.setTimeout.mock.calls).toHaveLength(1);
|
||||
expect(timers.setTimeout.mock.calls).toHaveLength(2);
|
||||
expect(timers.setTimeout.mock.calls[0][0]).toBe(1000);
|
||||
});
|
||||
|
||||
|
@ -1146,6 +1169,7 @@ describe('modules/platform/gitlab/index', () => {
|
|||
|
||||
it('waits for RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY ms when set', async () => {
|
||||
const delay = 5000;
|
||||
const retry = 2;
|
||||
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY = String(delay);
|
||||
|
||||
const scope = await initRepo();
|
||||
|
@ -1161,6 +1185,10 @@ describe('modules/platform/gitlab/index', () => {
|
|||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, []);
|
||||
|
||||
await gitlab.setBranchStatus({
|
||||
|
@ -1171,7 +1199,55 @@ describe('modules/platform/gitlab/index', () => {
|
|||
url: 'some-url',
|
||||
});
|
||||
|
||||
expect(timers.setTimeout.mock.calls).toHaveLength(1);
|
||||
expect(timers.setTimeout.mock.calls).toHaveLength(retry);
|
||||
expect(timers.setTimeout.mock.calls[0][0]).toBe(delay);
|
||||
});
|
||||
|
||||
it('do RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPTS attemps when set', async () => {
|
||||
const delay = 1000;
|
||||
const retry = 5;
|
||||
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPTS = `${retry}`;
|
||||
|
||||
const scope = await initRepo();
|
||||
scope
|
||||
.post(
|
||||
'/api/v4/projects/some%2Frepo/statuses/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, {})
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e/statuses',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, [])
|
||||
.get(
|
||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||
)
|
||||
.reply(200, []);
|
||||
|
||||
await gitlab.setBranchStatus({
|
||||
branchName: 'some-branch',
|
||||
context: 'some-context',
|
||||
description: 'some-description',
|
||||
state: 'green',
|
||||
url: 'some-url',
|
||||
});
|
||||
|
||||
expect(timers.setTimeout.mock.calls).toHaveLength(retry);
|
||||
expect(timers.setTimeout.mock.calls[0][0]).toBe(delay);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -989,9 +989,12 @@ export async function setBranchStatus({
|
|||
}: BranchStatusConfig): Promise<void> {
|
||||
// First, get the branch commit SHA
|
||||
const branchSha = git.getBranchCommit(branchName);
|
||||
if (!branchSha) {
|
||||
logger.warn('Failed to get the branch commit SHA');
|
||||
return;
|
||||
}
|
||||
// Now, check the statuses for that commit
|
||||
// TODO: types (#22198)
|
||||
const url = `projects/${config.repository}/statuses/${branchSha!}`;
|
||||
const url = `projects/${config.repository}/statuses/${branchSha}`;
|
||||
let state = 'success';
|
||||
if (renovateState === 'yellow') {
|
||||
state = 'pending';
|
||||
|
@ -1008,21 +1011,34 @@ export async function setBranchStatus({
|
|||
options.target_url = targetUrl;
|
||||
}
|
||||
|
||||
if (branchSha) {
|
||||
const commitUrl = `projects/${config.repository}/repository/commits/${branchSha}`;
|
||||
await gitlabApi
|
||||
.getJsonSafe(commitUrl, LastPipelineId)
|
||||
.onValue((pipelineId) => {
|
||||
options.pipeline_id = pipelineId;
|
||||
});
|
||||
const retryTimes = parseInteger(
|
||||
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPTS,
|
||||
2,
|
||||
);
|
||||
|
||||
try {
|
||||
for (let attempt = 1; attempt <= retryTimes; attempt += 1) {
|
||||
const commitUrl = `projects/${config.repository}/repository/commits/${branchSha}`;
|
||||
await gitlabApi
|
||||
.getJsonSafe(commitUrl, { memCache: false }, LastPipelineId)
|
||||
.onValue((pipelineId) => {
|
||||
options.pipeline_id = pipelineId;
|
||||
});
|
||||
if (options.pipeline_id !== undefined) {
|
||||
break;
|
||||
}
|
||||
logger.debug(`Pipeline not yet created. Retrying ${attempt}`);
|
||||
// give gitlab some time to create pipelines for the sha
|
||||
await setTimeout(
|
||||
parseInteger(process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY, 1000),
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.debug({ err });
|
||||
logger.warn('Failed to retrieve commit pipeline');
|
||||
}
|
||||
|
||||
try {
|
||||
// give gitlab some time to create pipelines for the sha
|
||||
await setTimeout(
|
||||
parseInteger(process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY, 1000),
|
||||
);
|
||||
|
||||
await gitlabApi.postJson(url, { body: options });
|
||||
|
||||
// update status cache
|
||||
|
|
Loading…
Reference in a new issue