mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-10 22:16:28 +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).
|
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`
|
## `RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY`
|
||||||
|
|
||||||
Adjust default time (in milliseconds) given to GitLab to create pipelines for a commit pushed by Renovate.
|
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',
|
token: '123test',
|
||||||
});
|
});
|
||||||
delete process.env.GITLAB_IGNORE_REPO_URL;
|
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_BRANCH_STATUS_DELAY;
|
||||||
delete process.env.RENOVATE_X_GITLAB_AUTO_MERGEABLE_CHECK_ATTEMPS;
|
delete process.env.RENOVATE_X_GITLAB_AUTO_MERGEABLE_CHECK_ATTEMPS;
|
||||||
delete process.env.RENOVATE_X_GITLAB_MERGE_REQUEST_DELAY;
|
delete process.env.RENOVATE_X_GITLAB_MERGE_REQUEST_DELAY;
|
||||||
|
@ -1058,6 +1059,20 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
describe('setBranchStatus', () => {
|
describe('setBranchStatus', () => {
|
||||||
const states: BranchStatus[] = ['green', 'yellow', 'red'];
|
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) => {
|
it.each(states)('sets branch status %s', async (state) => {
|
||||||
const scope = await initRepo();
|
const scope = await initRepo();
|
||||||
scope
|
scope
|
||||||
|
@ -1072,6 +1087,10 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
.get(
|
.get(
|
||||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||||
)
|
)
|
||||||
|
.reply(200, [])
|
||||||
|
.get(
|
||||||
|
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||||
|
)
|
||||||
.reply(200, []);
|
.reply(200, []);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
|
@ -1099,6 +1118,10 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
.get(
|
.get(
|
||||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||||
)
|
)
|
||||||
|
.reply(200, [])
|
||||||
|
.get(
|
||||||
|
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||||
|
)
|
||||||
.reply(200, []);
|
.reply(200, []);
|
||||||
|
|
||||||
await gitlab.setBranchStatus({
|
await gitlab.setBranchStatus({
|
||||||
|
@ -1109,7 +1132,7 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
url: 'some-url',
|
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);
|
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 () => {
|
it('waits for RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY ms when set', async () => {
|
||||||
const delay = 5000;
|
const delay = 5000;
|
||||||
|
const retry = 2;
|
||||||
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY = String(delay);
|
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY = String(delay);
|
||||||
|
|
||||||
const scope = await initRepo();
|
const scope = await initRepo();
|
||||||
|
@ -1161,6 +1185,10 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
.get(
|
.get(
|
||||||
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||||
)
|
)
|
||||||
|
.reply(200, [])
|
||||||
|
.get(
|
||||||
|
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
|
||||||
|
)
|
||||||
.reply(200, []);
|
.reply(200, []);
|
||||||
|
|
||||||
await gitlab.setBranchStatus({
|
await gitlab.setBranchStatus({
|
||||||
|
@ -1171,7 +1199,55 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
url: 'some-url',
|
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);
|
expect(timers.setTimeout.mock.calls[0][0]).toBe(delay);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -989,9 +989,12 @@ export async function setBranchStatus({
|
||||||
}: BranchStatusConfig): Promise<void> {
|
}: BranchStatusConfig): Promise<void> {
|
||||||
// First, get the branch commit SHA
|
// First, get the branch commit SHA
|
||||||
const branchSha = git.getBranchCommit(branchName);
|
const branchSha = git.getBranchCommit(branchName);
|
||||||
|
if (!branchSha) {
|
||||||
|
logger.warn('Failed to get the branch commit SHA');
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Now, check the statuses for that commit
|
// 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';
|
let state = 'success';
|
||||||
if (renovateState === 'yellow') {
|
if (renovateState === 'yellow') {
|
||||||
state = 'pending';
|
state = 'pending';
|
||||||
|
@ -1008,21 +1011,34 @@ export async function setBranchStatus({
|
||||||
options.target_url = targetUrl;
|
options.target_url = targetUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (branchSha) {
|
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}`;
|
const commitUrl = `projects/${config.repository}/repository/commits/${branchSha}`;
|
||||||
await gitlabApi
|
await gitlabApi
|
||||||
.getJsonSafe(commitUrl, LastPipelineId)
|
.getJsonSafe(commitUrl, { memCache: false }, LastPipelineId)
|
||||||
.onValue((pipelineId) => {
|
.onValue((pipelineId) => {
|
||||||
options.pipeline_id = pipelineId;
|
options.pipeline_id = pipelineId;
|
||||||
});
|
});
|
||||||
|
if (options.pipeline_id !== undefined) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
logger.debug(`Pipeline not yet created. Retrying ${attempt}`);
|
||||||
try {
|
|
||||||
// give gitlab some time to create pipelines for the sha
|
// give gitlab some time to create pipelines for the sha
|
||||||
await setTimeout(
|
await setTimeout(
|
||||||
parseInteger(process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY, 1000),
|
parseInteger(process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY, 1000),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.debug({ err });
|
||||||
|
logger.warn('Failed to retrieve commit pipeline');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await gitlabApi.postJson(url, { body: options });
|
await gitlabApi.postJson(url, { body: options });
|
||||||
|
|
||||||
// update status cache
|
// update status cache
|
||||||
|
|
Loading…
Reference in a new issue