Skip to content

Commit

Permalink
Remove support for GitLab < v12.4
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Apr 27, 2022
1 parent fbcbe91 commit c2cf5a9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 35 deletions.
14 changes: 1 addition & 13 deletions lib/plugin/gitlab/GitLab.js
Expand Up @@ -92,19 +92,7 @@ class GitLab extends Release {
return access_level && access_level >= 30;
} catch (err) {
this.debug(err);
if (err.name === 'HTTPError' && err.response.statusCode === 404) {
// Using another endpoint, since "/projects/:id/members/all/:user_id" was introduced in v12.4
const endpoint = `projects/${id}/members/${user.id}`;
try {
const { access_level } = await this.request(endpoint, { method: 'GET' });
return access_level && access_level >= 30;
} catch (err) {
this.debug(err);
return false;
}
} else {
return false;
}
return false;
}
}

Expand Down
14 changes: 0 additions & 14 deletions test/gitlab.js
Expand Up @@ -6,7 +6,6 @@ import { factory, runTasks } from './util/index.js';
import {
interceptUser,
interceptCollaborator,
interceptCollaboratorFallback,
interceptPublish,
interceptAsset,
interceptMilestones
Expand Down Expand Up @@ -220,19 +219,6 @@ test.serial('should throw for insufficient access level', async t => {
await t.throwsAsync(runTasks(gitlab), { message: /^User john is not a collaborator for john\/repo/ });
});

test.serial('should fallback for gitlab < v12.4', async t => {
const host = 'https://gitlab.com';
const pushRepo = `${host}/user/repo`;
const options = { gitlab: { tokenRef, pushRepo, host } };
const gitlab = factory(GitLab, { options });
const scope = nock(host);
scope.get(`/api/v4/projects/user%2Frepo/members/all/1`).reply(404);
interceptUser();
interceptCollaboratorFallback();

await t.notThrowsAsync(gitlab.init());
});

test('should not make requests in dry run', async t => {
const [host, owner, repo] = ['https://gitlab.example.org', 'user', 'repo'];
const pushRepo = `${host}/${owner}/${repo}`;
Expand Down
8 changes: 0 additions & 8 deletions test/stub/gitlab.js
Expand Up @@ -11,14 +11,6 @@ export let interceptCollaborator = (
.get(`/api/v4/projects/${group ? `${group}%2F` : ''}${owner}%2F${project}/members/all/${userId}`)
.reply(200, { id: userId, username: owner, access_level: 30 });

export let interceptCollaboratorFallback = (
{ host = 'https://gitlab.com', owner = 'user', project = 'repo', group, userId = 1 } = {},
options
) =>
nock(host, options)
.get(`/api/v4/projects/${group ? `${group}%2F` : ''}${owner}%2F${project}/members/${userId}`)
.reply(200, { id: userId, username: owner, access_level: 30 });

export let interceptPublish = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', body } = {}, options) =>
nock(host, options).post(`/api/v4/projects/${owner}%2F${project}/releases`, body).reply(200, {});

Expand Down

0 comments on commit c2cf5a9

Please sign in to comment.