2018-09-12 10:16:17 +00:00
|
|
|
const hostRules = require('../../../lib/util/host-rules');
|
2018-07-06 05:26:36 +00:00
|
|
|
|
2017-10-24 08:27:17 +00:00
|
|
|
describe('platform/gitlab', () => {
|
2017-06-22 19:35:32 +00:00
|
|
|
let gitlab;
|
2017-10-17 05:15:01 +00:00
|
|
|
let get;
|
2017-06-22 19:35:32 +00:00
|
|
|
beforeEach(() => {
|
2018-09-12 10:16:17 +00:00
|
|
|
// clean up hostRules
|
|
|
|
hostRules.clear();
|
2017-06-22 19:35:32 +00:00
|
|
|
|
|
|
|
// reset module
|
|
|
|
jest.resetModules();
|
2017-11-05 07:18:20 +00:00
|
|
|
jest.mock('../../../lib/platform/gitlab/gl-got-wrapper');
|
|
|
|
gitlab = require('../../../lib/platform/gitlab');
|
|
|
|
get = require('../../../lib/platform/gitlab/gl-got-wrapper');
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('getRepos', () => {
|
2017-11-03 10:56:25 +00:00
|
|
|
function getRepos(...args) {
|
2017-06-22 19:35:32 +00:00
|
|
|
// repo info
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({
|
2017-06-22 19:35:32 +00:00
|
|
|
body: [
|
|
|
|
{
|
|
|
|
path_with_namespace: 'a/b',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path_with_namespace: 'c/d',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
return gitlab.getRepos(...args);
|
|
|
|
}
|
|
|
|
it('should throw an error if no token is provided', async () => {
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(gitlab.getRepos()).rejects.toThrow(
|
|
|
|
Error('No token found for getRepos')
|
|
|
|
);
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
|
|
|
it('should throw an error if it receives an error', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementation(() => {
|
2017-06-22 19:35:32 +00:00
|
|
|
throw new Error('getRepos error');
|
|
|
|
});
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(gitlab.getRepos('sometoken')).rejects.toThrow(
|
|
|
|
Error('getRepos error')
|
|
|
|
);
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
|
|
|
it('should return an array of repos', async () => {
|
|
|
|
const repos = await getRepos('sometoken');
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.mock.calls).toMatchSnapshot();
|
2017-06-22 19:35:32 +00:00
|
|
|
expect(repos).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('should support a custom endpoint', async () => {
|
|
|
|
const repos = await getRepos('sometoken', 'someendpoint');
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.mock.calls).toMatchSnapshot();
|
2017-06-22 19:35:32 +00:00
|
|
|
expect(repos).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-09-10 13:32:03 +00:00
|
|
|
describe('getRepoStatus()', () => {
|
|
|
|
it('exists', async () => {
|
|
|
|
expect(await gitlab.getRepoStatus()).toEqual({});
|
|
|
|
});
|
|
|
|
});
|
2018-04-04 12:16:36 +00:00
|
|
|
describe('cleanRepo()', () => {
|
|
|
|
it('exists', () => {
|
|
|
|
gitlab.cleanRepo();
|
|
|
|
});
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
function initRepo(...args) {
|
2018-01-25 11:24:13 +00:00
|
|
|
// projects/${config.repository
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({
|
2017-06-22 19:35:32 +00:00
|
|
|
body: {
|
|
|
|
default_branch: 'master',
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
// user
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({
|
2017-06-22 19:35:32 +00:00
|
|
|
body: {
|
|
|
|
email: 'a@b.com',
|
|
|
|
},
|
|
|
|
}));
|
2018-06-12 05:18:28 +00:00
|
|
|
get.mockReturnValue({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
number: 1,
|
|
|
|
source_branch: 'branch-a',
|
|
|
|
title: 'branch a pr',
|
|
|
|
state: 'opened',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2017-06-22 19:35:32 +00:00
|
|
|
return gitlab.initRepo(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('initRepo', () => {
|
|
|
|
[
|
2018-01-25 11:24:13 +00:00
|
|
|
[undefined, 'mytoken', undefined],
|
|
|
|
[undefined, 'mytoken', 'https://my.custom.endpoint/'],
|
|
|
|
['myenvtoken', 'myenvtoken', undefined],
|
2018-06-27 16:40:54 +00:00
|
|
|
[undefined, 'mytoken', undefined, 'Renovate Bot <bot@renovatebot.com>'],
|
|
|
|
].forEach(([envToken, token, endpoint, gitAuthor], i) => {
|
2017-06-22 19:35:32 +00:00
|
|
|
it(`should initialise the config for the repo - ${i}`, async () => {
|
|
|
|
if (envToken !== undefined) {
|
2019-01-14 06:53:42 +00:00
|
|
|
process.env.RENOVATE_TOKEN = envToken;
|
2017-06-22 19:35:32 +00:00
|
|
|
}
|
2017-12-23 07:03:16 +00:00
|
|
|
get.mockReturnValue({ body: [] });
|
2018-01-25 11:24:13 +00:00
|
|
|
const config = await initRepo({
|
|
|
|
repository: 'some/repo',
|
|
|
|
token,
|
|
|
|
endpoint,
|
2018-06-27 16:40:54 +00:00
|
|
|
gitAuthor,
|
2018-01-25 11:24:13 +00:00
|
|
|
});
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.mock.calls).toMatchSnapshot();
|
2017-06-22 19:35:32 +00:00
|
|
|
expect(config).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2017-12-14 05:19:24 +00:00
|
|
|
it(`should escape all forward slashes in project names`, async () => {
|
2017-12-23 07:03:16 +00:00
|
|
|
get.mockReturnValue({ body: [] });
|
2018-01-25 11:24:13 +00:00
|
|
|
await initRepo({ repository: 'some/repo/project', token: 'some-token' });
|
2017-12-14 05:19:24 +00:00
|
|
|
expect(get.mock.calls).toMatchSnapshot();
|
|
|
|
});
|
2017-06-22 19:35:32 +00:00
|
|
|
it('should throw an error if no token is provided', async () => {
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(
|
|
|
|
gitlab.initRepo({ repository: 'some/repo' })
|
|
|
|
).rejects.toThrow(
|
|
|
|
Error('No token found for GitLab repository some/repo')
|
2017-06-22 19:35:32 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should throw an error if receiving an error', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementation(() => {
|
2017-06-22 19:35:32 +00:00
|
|
|
throw new Error('always error');
|
|
|
|
});
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(
|
|
|
|
gitlab.initRepo({ repository: 'some/repo', token: 'sometoken' })
|
|
|
|
).rejects.toThrow(Error('always error'));
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
2018-09-02 19:13:23 +00:00
|
|
|
it('should throw an error if repository is archived', async () => {
|
|
|
|
get.mockReturnValue({ body: { archived: true } });
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(
|
|
|
|
gitlab.initRepo({ repository: 'some/repo', token: 'sometoken' })
|
|
|
|
).rejects.toThrow(Error('archived'));
|
2018-09-02 19:13:23 +00:00
|
|
|
});
|
2018-11-10 22:19:20 +00:00
|
|
|
it('should throw an error if repository is empty', async () => {
|
|
|
|
get.mockReturnValue({ body: { default_branch: null } });
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(
|
|
|
|
gitlab.initRepo({ repository: 'some/repo', token: 'sometoken' })
|
|
|
|
).rejects.toThrow(Error('empty'));
|
2018-11-10 22:19:20 +00:00
|
|
|
});
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
2017-11-15 14:31:20 +00:00
|
|
|
describe('getRepoForceRebase', () => {
|
|
|
|
it('should return false', () => {
|
|
|
|
expect(gitlab.getRepoForceRebase()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2017-07-06 08:26:18 +00:00
|
|
|
describe('setBaseBranch(branchName)', () => {
|
|
|
|
it('sets the base branch', async () => {
|
|
|
|
await gitlab.setBaseBranch('some-branch');
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.mock.calls).toMatchSnapshot();
|
2017-07-06 08:26:18 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-25 04:00:07 +00:00
|
|
|
describe('getFileList', () => {
|
2017-10-18 06:25:42 +00:00
|
|
|
it('returns empty array if error', async () => {
|
|
|
|
get.mockImplementationOnce(() => {
|
|
|
|
throw new Error('some error');
|
|
|
|
});
|
2017-10-25 04:00:07 +00:00
|
|
|
const files = await gitlab.getFileList();
|
2017-10-18 06:25:42 +00:00
|
|
|
expect(files).toEqual([]);
|
|
|
|
});
|
2017-10-16 09:59:59 +00:00
|
|
|
it('warns if truncated result', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({
|
2017-10-16 09:59:59 +00:00
|
|
|
body: [],
|
|
|
|
}));
|
2017-10-25 04:00:07 +00:00
|
|
|
const files = await gitlab.getFileList();
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(files).toHaveLength(0);
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
2017-10-16 09:59:59 +00:00
|
|
|
it('caches the result', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({
|
2017-10-16 09:59:59 +00:00
|
|
|
body: [],
|
|
|
|
}));
|
2017-10-25 04:00:07 +00:00
|
|
|
let files = await gitlab.getFileList();
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(files).toHaveLength(0);
|
2017-10-25 04:00:07 +00:00
|
|
|
files = await gitlab.getFileList();
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(files).toHaveLength(0);
|
2017-10-16 09:59:59 +00:00
|
|
|
});
|
|
|
|
it('should return the files matching the fileName', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({
|
2017-10-16 09:59:59 +00:00
|
|
|
body: [
|
2017-10-22 18:24:01 +00:00
|
|
|
{ type: 'blob', path: 'symlinks/package.json', mode: '120000' },
|
2017-10-16 09:59:59 +00:00
|
|
|
{ type: 'blob', path: 'package.json' },
|
|
|
|
{
|
|
|
|
type: 'blob',
|
|
|
|
path: 'some-dir/package.json.some-thing-else',
|
|
|
|
},
|
|
|
|
{ type: 'blob', path: 'src/app/package.json' },
|
|
|
|
{ type: 'blob', path: 'src/otherapp/package.json' },
|
|
|
|
],
|
|
|
|
}));
|
2017-10-25 04:00:07 +00:00
|
|
|
const files = await gitlab.getFileList();
|
2017-10-16 09:59:59 +00:00
|
|
|
expect(files).toMatchSnapshot();
|
|
|
|
});
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
|
|
|
describe('branchExists(branchName)', () => {
|
|
|
|
it('should return true if 200 OK', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({ statusCode: 200 }));
|
2017-06-22 19:35:32 +00:00
|
|
|
const branchExists = await gitlab.branchExists('foo');
|
|
|
|
expect(branchExists).toBe(true);
|
|
|
|
});
|
|
|
|
it('should return false if not 200 OK', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => ({ statusCode: 500 }));
|
2017-06-22 19:35:32 +00:00
|
|
|
const branchExists = await gitlab.branchExists('foo');
|
|
|
|
expect(branchExists).toBe(false);
|
|
|
|
});
|
|
|
|
it('should return false if 404 error received', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() =>
|
2017-06-22 19:35:32 +00:00
|
|
|
Promise.reject({
|
|
|
|
statusCode: 404,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const branchExists = await gitlab.branchExists('foo');
|
|
|
|
expect(branchExists).toBe(false);
|
|
|
|
});
|
|
|
|
it('should return error if non-404 error thrown', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() =>
|
2017-06-22 19:35:32 +00:00
|
|
|
Promise.reject({
|
|
|
|
statusCode: 500,
|
|
|
|
})
|
|
|
|
);
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(gitlab.branchExists('foo')).rejects.toEqual({
|
|
|
|
statusCode: 500,
|
|
|
|
});
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|
|
|
|
});
|
2017-11-05 07:18:20 +00:00
|
|
|
describe('getAllRenovateBranches()', () => {
|
2018-02-03 11:06:25 +00:00
|
|
|
it('should return all renovate branches', async () => {
|
2019-01-28 01:39:44 +00:00
|
|
|
const search = 'renovate/';
|
|
|
|
get.mockImplementationOnce(path => {
|
|
|
|
expect(path).toBe(
|
|
|
|
'projects/undefined/repository/branches?search=^renovate%2F'
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
name: 'renovate/a',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'renovate/b',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const res = await gitlab.getAllRenovateBranches(search);
|
2018-02-03 11:06:25 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2017-11-05 07:18:20 +00:00
|
|
|
});
|
|
|
|
describe('isBranchStale()', () => {
|
2018-04-14 19:47:22 +00:00
|
|
|
it('should return false if same SHA as master', async () => {
|
|
|
|
// getBranchDetails - same as master
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
parent_ids: ['1234'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
// getBranchDetails - master
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
id: '1234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
expect(await gitlab.isBranchStale('thebranchname')).toBe(false);
|
|
|
|
});
|
|
|
|
it('should return true if SHA different from master', async () => {
|
|
|
|
// getBranchDetails - different from master
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
parent_ids: ['12345678'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
// getBranchDetails - master
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
id: '1234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
expect(await gitlab.isBranchStale('thebranchname')).toBe(true);
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('getBranchPr(branchName)', () => {
|
2018-02-28 03:43:30 +00:00
|
|
|
it('should return null if branch does not exist', async () => {
|
|
|
|
get.mockReturnValueOnce({ statusCode: 500 }); // branchExists
|
|
|
|
const pr = await gitlab.getBranchPr('somebranch');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(pr).toBeNull();
|
2018-02-28 03:43:30 +00:00
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
it('should return null if no PR exists', async () => {
|
2018-02-28 03:43:30 +00:00
|
|
|
get.mockReturnValueOnce({ statusCode: 200 }); // branchExists
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
// branchExists
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [],
|
2018-02-28 03:43:30 +00:00
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
const pr = await gitlab.getBranchPr('somebranch');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(pr).toBeNull();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
it('should return the PR object', async () => {
|
2018-02-28 03:43:30 +00:00
|
|
|
get.mockReturnValueOnce({ statusCode: 200 }); // branchExists
|
2017-11-05 07:18:20 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [{ number: 91, source_branch: 'somebranch' }],
|
2017-11-05 07:18:20 +00:00
|
|
|
});
|
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: {
|
2017-08-31 19:06:19 +00:00
|
|
|
iid: 91,
|
2018-11-08 22:41:52 +00:00
|
|
|
state: 'opened',
|
2017-06-25 05:11:24 +00:00
|
|
|
additions: 1,
|
|
|
|
deletions: 1,
|
|
|
|
commits: 1,
|
2017-08-31 19:06:19 +00:00
|
|
|
source_branch: 'some-branch',
|
2017-06-25 05:11:24 +00:00
|
|
|
base: {
|
|
|
|
sha: '1234',
|
|
|
|
},
|
|
|
|
},
|
2017-11-05 07:18:20 +00:00
|
|
|
});
|
2018-11-07 12:19:20 +00:00
|
|
|
get.mockReturnValueOnce({ body: [] }); // get branch commit
|
|
|
|
get.mockReturnValueOnce({ body: [{ status: 'success' }] }); // get commit statuses
|
2017-11-05 07:18:20 +00:00
|
|
|
get.mockReturnValueOnce({ body: 'foo' });
|
2017-06-25 05:11:24 +00:00
|
|
|
const pr = await gitlab.getBranchPr('somebranch');
|
|
|
|
expect(pr).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2017-07-05 05:02:25 +00:00
|
|
|
describe('getBranchStatus(branchName, requiredStatusChecks)', () => {
|
2017-06-25 05:11:24 +00:00
|
|
|
beforeEach(() => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2017-07-05 05:02:25 +00:00
|
|
|
it('returns success if requiredStatusChecks null', async () => {
|
|
|
|
const res = await gitlab.getBranchStatus('somebranch', null);
|
|
|
|
expect(res).toEqual('success');
|
|
|
|
});
|
|
|
|
it('return failed if unsupported requiredStatusChecks', async () => {
|
|
|
|
const res = await gitlab.getBranchStatus('somebranch', ['foo']);
|
|
|
|
expect(res).toEqual('failed');
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
it('returns pending if no results', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [],
|
|
|
|
});
|
2017-07-05 05:02:25 +00:00
|
|
|
const res = await gitlab.getBranchStatus('somebranch', []);
|
2017-06-25 05:11:24 +00:00
|
|
|
expect(res).toEqual('pending');
|
|
|
|
});
|
|
|
|
it('returns success if all are success', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [{ status: 'success' }, { status: 'success' }],
|
|
|
|
});
|
2017-07-05 05:02:25 +00:00
|
|
|
const res = await gitlab.getBranchStatus('somebranch', []);
|
2017-06-25 05:11:24 +00:00
|
|
|
expect(res).toEqual('success');
|
|
|
|
});
|
2018-03-05 20:02:00 +00:00
|
|
|
it('returns success if optional jobs fail', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2018-03-05 20:02:00 +00:00
|
|
|
body: [
|
|
|
|
{ status: 'success' },
|
|
|
|
{ status: 'failed', allow_failure: true },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getBranchStatus('somebranch', []);
|
|
|
|
expect(res).toEqual('success');
|
|
|
|
});
|
|
|
|
it('returns failure if any mandatory jobs fails', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [
|
|
|
|
{ status: 'success' },
|
|
|
|
{ status: 'failed', allow_failure: true },
|
|
|
|
{ status: 'failed' },
|
|
|
|
],
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2017-07-05 05:02:25 +00:00
|
|
|
const res = await gitlab.getBranchStatus('somebranch', []);
|
2017-06-25 05:11:24 +00:00
|
|
|
expect(res).toEqual('failure');
|
|
|
|
});
|
|
|
|
it('returns custom statuses', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [{ status: 'success' }, { status: 'foo' }],
|
|
|
|
});
|
2017-07-05 05:02:25 +00:00
|
|
|
const res = await gitlab.getBranchStatus('somebranch', []);
|
2017-06-25 05:11:24 +00:00
|
|
|
expect(res).toEqual('foo');
|
|
|
|
});
|
|
|
|
});
|
2017-08-08 21:03:52 +00:00
|
|
|
describe('getBranchStatusCheck', () => {
|
|
|
|
beforeEach(() => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-08 21:03:52 +00:00
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns null if no results', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-08 21:03:52 +00:00
|
|
|
body: [],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getBranchStatusCheck(
|
|
|
|
'somebranch',
|
|
|
|
'some-context'
|
|
|
|
);
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2017-08-08 21:03:52 +00:00
|
|
|
});
|
|
|
|
it('returns null if no matching results', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-08 21:03:52 +00:00
|
|
|
body: [{ name: 'context-1', status: 'pending' }],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getBranchStatusCheck(
|
|
|
|
'somebranch',
|
|
|
|
'some-context'
|
|
|
|
);
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2017-08-08 21:03:52 +00:00
|
|
|
});
|
|
|
|
it('returns status if name found', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-08 21:03:52 +00:00
|
|
|
body: [
|
|
|
|
{ name: 'context-1', state: 'pending' },
|
|
|
|
{ name: 'some-context', state: 'success' },
|
|
|
|
{ name: 'context-3', state: 'failed' },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getBranchStatusCheck(
|
|
|
|
'somebranch',
|
|
|
|
'some-context'
|
|
|
|
);
|
|
|
|
expect(res).toEqual('success');
|
|
|
|
});
|
|
|
|
});
|
2017-08-06 13:38:10 +00:00
|
|
|
describe('setBranchStatus', () => {
|
|
|
|
it('sets branch status', async () => {
|
|
|
|
// getBranchCommit
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-06 13:38:10 +00:00
|
|
|
body: {
|
|
|
|
commit: {
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await gitlab.setBranchStatus(
|
|
|
|
'some-branch',
|
|
|
|
'some-context',
|
|
|
|
'some-description',
|
|
|
|
'some-state',
|
|
|
|
'some-url'
|
|
|
|
);
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(1);
|
2017-08-06 13:38:10 +00:00
|
|
|
});
|
|
|
|
});
|
2018-07-02 09:27:08 +00:00
|
|
|
describe('mergeBranch(branchName)', () => {
|
|
|
|
it('should perform a branch merge', async () => {
|
|
|
|
await initRepo({
|
|
|
|
repository: 'some/repo',
|
|
|
|
token: 'token',
|
|
|
|
});
|
|
|
|
|
|
|
|
await gitlab.mergeBranch('thebranchname');
|
|
|
|
|
|
|
|
// deleteBranch
|
|
|
|
get.delete.mockImplementationOnce();
|
|
|
|
|
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
|
|
|
expect(get.delete.mock.calls).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('should throw if branch merge throws', async () => {
|
|
|
|
await initRepo({
|
|
|
|
repository: 'some/repo',
|
|
|
|
token: 'token',
|
|
|
|
});
|
|
|
|
get.post.mockImplementationOnce(() => {
|
|
|
|
throw new Error('branch-push failed');
|
|
|
|
});
|
2019-04-19 20:04:37 +00:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
gitlab.mergeBranch('thebranchname')
|
|
|
|
).rejects.toMatchSnapshot();
|
2018-07-02 09:27:08 +00:00
|
|
|
|
|
|
|
// deleteBranch
|
|
|
|
get.delete.mockImplementationOnce();
|
|
|
|
|
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
|
|
|
expect(get.delete.mock.calls).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
describe('deleteBranch(branchName)', () => {
|
|
|
|
it('should send delete', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.delete = jest.fn();
|
2017-06-25 05:11:24 +00:00
|
|
|
await gitlab.deleteBranch('some-branch');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.delete).toHaveBeenCalledTimes(1);
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2018-02-03 11:06:25 +00:00
|
|
|
it('should close PR', async () => {
|
|
|
|
get.delete = jest.fn();
|
|
|
|
get.mockReturnValueOnce({ body: [] }); // getBranchPr
|
|
|
|
await gitlab.deleteBranch('some-branch', true);
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.delete).toHaveBeenCalledTimes(1);
|
2018-02-03 11:06:25 +00:00
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2017-08-28 09:37:09 +00:00
|
|
|
describe('getBranchLastCommitTime', () => {
|
|
|
|
it('should return a Date', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-28 09:37:09 +00:00
|
|
|
body: [
|
|
|
|
{
|
|
|
|
id: 'ed899a2f4b50b4370feeea94676502b42383c746',
|
|
|
|
short_id: 'ed899a2f4b5',
|
|
|
|
title: 'Replace sanitize with escape once',
|
|
|
|
author_name: 'Dmitriy Zaporozhets',
|
|
|
|
author_email: 'dzaporozhets@sphereconsultinginc.com',
|
|
|
|
authored_date: '2012-09-20T11:50:22+03:00',
|
|
|
|
committer_name: 'Administrator',
|
|
|
|
committer_email: 'admin@example.com',
|
|
|
|
committed_date: '2012-09-20T11:50:22+03:00',
|
|
|
|
created_at: '2012-09-20T11:50:22+03:00',
|
|
|
|
message: 'Replace sanitize with escape once',
|
|
|
|
parent_ids: ['6104942438c14ec7bd21c6cd5bd995272b3faff6'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '6104942438c14ec7bd21c6cd5bd995272b3faff6',
|
|
|
|
short_id: '6104942438c',
|
|
|
|
title: 'Sanitize for network graph',
|
|
|
|
author_name: 'randx',
|
|
|
|
author_email: 'dmitriy.zaporozhets@gmail.com',
|
|
|
|
committer_name: 'Dmitriy',
|
|
|
|
committer_email: 'dmitriy.zaporozhets@gmail.com',
|
|
|
|
created_at: '2012-09-20T09:06:12+03:00',
|
|
|
|
message: 'Sanitize for network graph',
|
|
|
|
parent_ids: ['ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getBranchLastCommitTime('some-branch');
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles error', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-08-28 09:37:09 +00:00
|
|
|
body: [],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getBranchLastCommitTime('some-branch');
|
|
|
|
expect(res).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2018-10-03 13:47:03 +00:00
|
|
|
describe('findIssue()', () => {
|
|
|
|
it('returns null if no issue', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
iid: 1,
|
|
|
|
title: 'title-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
iid: 2,
|
|
|
|
title: 'title-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const res = await gitlab.findIssue('title-3');
|
|
|
|
expect(res).toBeNull();
|
|
|
|
});
|
|
|
|
it('finds issue', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
iid: 1,
|
|
|
|
title: 'title-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
iid: 2,
|
|
|
|
title: 'title-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-10-09 03:05:20 +00:00
|
|
|
get.mockReturnValueOnce({ body: { description: 'new-content' } });
|
2018-10-03 13:47:03 +00:00
|
|
|
const res = await gitlab.findIssue('title-2');
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
2018-06-21 06:39:24 +00:00
|
|
|
describe('ensureIssue()', () => {
|
|
|
|
it('creates issue', async () => {
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: [
|
|
|
|
{
|
2018-10-03 13:47:03 +00:00
|
|
|
iid: 1,
|
2018-06-21 06:39:24 +00:00
|
|
|
title: 'title-1',
|
|
|
|
},
|
|
|
|
{
|
2018-10-03 13:47:03 +00:00
|
|
|
iid: 2,
|
2018-06-21 06:39:24 +00:00
|
|
|
title: 'title-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
const res = await gitlab.ensureIssue('new-title', 'new-content');
|
|
|
|
expect(res).toEqual('created');
|
|
|
|
});
|
|
|
|
it('updates issue', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [
|
|
|
|
{
|
2018-10-03 13:47:03 +00:00
|
|
|
iid: 1,
|
2018-06-21 06:39:24 +00:00
|
|
|
title: 'title-1',
|
|
|
|
},
|
|
|
|
{
|
2018-10-03 13:47:03 +00:00
|
|
|
iid: 2,
|
2018-06-21 06:39:24 +00:00
|
|
|
title: 'title-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-10-09 03:05:20 +00:00
|
|
|
get.mockReturnValueOnce({ body: { description: 'new-content' } });
|
2018-06-21 06:39:24 +00:00
|
|
|
const res = await gitlab.ensureIssue('title-2', 'newer-content');
|
|
|
|
expect(res).toEqual('updated');
|
|
|
|
});
|
|
|
|
it('skips update if unchanged', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
number: 1,
|
|
|
|
title: 'title-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: 2,
|
|
|
|
title: 'title-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-10-09 03:05:20 +00:00
|
|
|
get.mockReturnValueOnce({ body: { description: 'newer-content' } });
|
2018-06-21 06:39:24 +00:00
|
|
|
const res = await gitlab.ensureIssue('title-2', 'newer-content');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2018-06-21 06:39:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('ensureIssueClosing()', () => {
|
|
|
|
it('closes issue', async () => {
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
number: 1,
|
|
|
|
title: 'title-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: 2,
|
|
|
|
title: 'title-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
await gitlab.ensureIssueClosing('title-2');
|
|
|
|
});
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
describe('addAssignees(issueNo, assignees)', () => {
|
|
|
|
it('should add the given assignees to the issue', async () => {
|
2017-11-10 08:59:12 +00:00
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [{ id: 123 }],
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
await gitlab.addAssignees(42, ['someuser']);
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.put.mock.calls).toMatchSnapshot();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2017-11-10 08:59:12 +00:00
|
|
|
it('should warn if more than one assignee', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [{ id: 123 }],
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
await gitlab.addAssignees(42, ['someuser', 'someotheruser']);
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.put.mock.calls).toMatchSnapshot();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2017-11-10 08:59:12 +00:00
|
|
|
it('should swallow error', async () => {
|
|
|
|
get.mockImplementationOnce({});
|
|
|
|
await gitlab.addAssignees(42, ['someuser', 'someotheruser']);
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.put).toHaveBeenCalledTimes(0);
|
2017-11-10 08:59:12 +00:00
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
describe('addReviewers(issueNo, reviewers)', () => {
|
|
|
|
it('should add the given reviewers to the PR', async () => {
|
|
|
|
await gitlab.addReviewers(42, ['someuser', 'someotheruser']);
|
|
|
|
});
|
|
|
|
});
|
2017-10-18 13:28:51 +00:00
|
|
|
describe('ensureComment', () => {
|
2018-06-12 05:18:28 +00:00
|
|
|
it('add comment if not found', async () => {
|
|
|
|
await initRepo({ repository: 'some/repo', token: 'token' });
|
|
|
|
get.mockReturnValueOnce({ body: [] });
|
|
|
|
await gitlab.ensureComment(42, 'some-subject', 'some\ncontent');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(1);
|
2018-06-12 05:18:28 +00:00
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('add updates comment if necessary', async () => {
|
|
|
|
await initRepo({ repository: 'some/repo', token: 'token' });
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [{ id: 1234, body: '### some-subject\n\nblablabla' }],
|
|
|
|
});
|
2017-10-18 13:28:51 +00:00
|
|
|
await gitlab.ensureComment(42, 'some-subject', 'some\ncontent');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(0);
|
|
|
|
expect(get.put).toHaveBeenCalledTimes(1);
|
2018-10-25 17:01:39 +00:00
|
|
|
expect(get.put.mock.calls).toMatchSnapshot();
|
2018-06-12 05:18:28 +00:00
|
|
|
});
|
|
|
|
it('skips comment', async () => {
|
|
|
|
await initRepo({ repository: 'some/repo', token: 'token' });
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [{ id: 1234, body: '### some-subject\n\nsome\ncontent' }],
|
|
|
|
});
|
|
|
|
await gitlab.ensureComment(42, 'some-subject', 'some\ncontent');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(0);
|
|
|
|
expect(get.put).toHaveBeenCalledTimes(0);
|
2018-06-12 05:18:28 +00:00
|
|
|
});
|
|
|
|
it('handles comment with no description', async () => {
|
|
|
|
await initRepo({ repository: 'some/repo', token: 'token' });
|
|
|
|
get.mockReturnValueOnce({ body: [{ id: 1234, body: '!merge' }] });
|
|
|
|
await gitlab.ensureComment(42, null, '!merge');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(0);
|
|
|
|
expect(get.put).toHaveBeenCalledTimes(0);
|
2017-10-18 13:28:51 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-19 11:30:26 +00:00
|
|
|
describe('ensureCommentRemoval', () => {
|
2018-06-12 05:18:28 +00:00
|
|
|
it('deletes comment if found', async () => {
|
|
|
|
await initRepo({ repository: 'some/repo', token: 'token' });
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [{ id: 1234, body: '### some-subject\n\nblablabla' }],
|
|
|
|
});
|
2017-10-19 11:30:26 +00:00
|
|
|
await gitlab.ensureCommentRemoval(42, 'some-subject');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.delete).toHaveBeenCalledTimes(1);
|
2017-10-19 11:30:26 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
describe('findPr(branchName, prTitle, state)', () => {
|
2017-11-14 08:55:05 +00:00
|
|
|
it('returns true if no title and all state', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [
|
|
|
|
{
|
2017-11-14 08:55:05 +00:00
|
|
|
number: 1,
|
|
|
|
source_branch: 'branch-a',
|
|
|
|
title: 'branch a pr',
|
|
|
|
state: 'opened',
|
2017-06-25 05:11:24 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2017-11-14 08:55:05 +00:00
|
|
|
const res = await gitlab.findPr('branch-a', null);
|
|
|
|
expect(res).toBeDefined();
|
2017-11-24 06:31:20 +00:00
|
|
|
});
|
|
|
|
it('returns true if not open', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
number: 1,
|
|
|
|
source_branch: 'branch-a',
|
|
|
|
title: 'branch a pr',
|
|
|
|
state: 'merged',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const res = await gitlab.findPr('branch-a', null, '!open');
|
|
|
|
expect(res).toBeDefined();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2017-11-14 08:55:05 +00:00
|
|
|
it('caches pr list', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: [
|
|
|
|
{
|
2017-11-14 08:55:05 +00:00
|
|
|
number: 1,
|
|
|
|
source_branch: 'branch-a',
|
|
|
|
title: 'branch a pr',
|
|
|
|
state: 'opened',
|
2017-06-25 05:11:24 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2017-11-14 08:55:05 +00:00
|
|
|
let res = await gitlab.findPr('branch-a', null);
|
|
|
|
expect(res).toBeDefined();
|
|
|
|
res = await gitlab.findPr('branch-a', 'branch a pr');
|
|
|
|
expect(res).toBeDefined();
|
|
|
|
res = await gitlab.findPr('branch-a', 'branch a pr', 'open');
|
|
|
|
expect(res).toBeDefined();
|
|
|
|
res = await gitlab.findPr('branch-b');
|
|
|
|
expect(res).not.toBeDefined();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('createPr(branchName, title, body)', () => {
|
|
|
|
it('returns the PR', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.post.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: {
|
|
|
|
id: 1,
|
|
|
|
iid: 12345,
|
|
|
|
},
|
|
|
|
});
|
2017-11-05 07:18:20 +00:00
|
|
|
const pr = await gitlab.createPr(
|
|
|
|
'some-branch',
|
|
|
|
'some-title',
|
|
|
|
'the-body',
|
|
|
|
null
|
|
|
|
);
|
2017-06-25 05:11:24 +00:00
|
|
|
expect(pr).toMatchSnapshot();
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
2017-07-06 12:12:52 +00:00
|
|
|
});
|
|
|
|
it('uses default branch', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.post.mockReturnValueOnce({
|
2017-07-06 12:12:52 +00:00
|
|
|
body: {
|
|
|
|
id: 1,
|
|
|
|
iid: 12345,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const pr = await gitlab.createPr(
|
|
|
|
'some-branch',
|
|
|
|
'some-title',
|
|
|
|
'the-body',
|
2017-11-05 07:18:20 +00:00
|
|
|
[],
|
2017-07-06 12:12:52 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
expect(pr).toMatchSnapshot();
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('getPr(prNo)', () => {
|
|
|
|
it('returns the PR', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: {
|
|
|
|
id: 1,
|
|
|
|
iid: 12345,
|
|
|
|
description: 'a merge request',
|
|
|
|
state: 'merged',
|
|
|
|
merge_status: 'cannot_be_merged',
|
2018-10-31 14:05:25 +00:00
|
|
|
diverged_commits_count: 5,
|
2017-08-31 19:06:19 +00:00
|
|
|
source_branch: 'some-branch',
|
2017-06-25 05:11:24 +00:00
|
|
|
},
|
|
|
|
});
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: {
|
|
|
|
commit: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const pr = await gitlab.getPr(12345);
|
|
|
|
expect(pr).toMatchSnapshot();
|
|
|
|
});
|
2018-02-28 03:43:30 +00:00
|
|
|
it('returns the PR with nonexisting branch', async () => {
|
|
|
|
get.mockImplementationOnce(() => ({
|
|
|
|
body: {
|
|
|
|
id: 1,
|
|
|
|
iid: 12345,
|
|
|
|
description: 'a merge request',
|
|
|
|
state: 'open',
|
|
|
|
merge_status: 'cannot_be_merged',
|
2018-10-31 14:05:25 +00:00
|
|
|
diverged_commits_count: 2,
|
2018-02-28 03:43:30 +00:00
|
|
|
source_branch: 'some-branch',
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
get.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 404,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const pr = await gitlab.getPr(12345);
|
|
|
|
expect(pr).toMatchSnapshot();
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
2018-03-06 11:18:35 +00:00
|
|
|
describe('getPrFiles()', () => {
|
2018-06-19 11:39:25 +00:00
|
|
|
it('should return empty if no mrNo is passed', async () => {
|
|
|
|
const prFiles = await gitlab.getPrFiles(null);
|
2018-03-06 11:18:35 +00:00
|
|
|
expect(prFiles).toEqual([]);
|
|
|
|
});
|
2018-06-19 11:39:25 +00:00
|
|
|
it('returns files', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
2018-11-07 12:17:32 +00:00
|
|
|
body: {
|
|
|
|
changes: [
|
|
|
|
{ new_path: 'renovate.json' },
|
|
|
|
{ new_path: 'not renovate.json' },
|
|
|
|
],
|
|
|
|
},
|
2018-06-19 11:39:25 +00:00
|
|
|
});
|
|
|
|
const prFiles = await gitlab.getPrFiles(123);
|
|
|
|
expect(prFiles).toMatchSnapshot();
|
|
|
|
expect(prFiles).toHaveLength(2);
|
|
|
|
});
|
2018-03-06 11:18:35 +00:00
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
describe('updatePr(prNo, title, body)', () => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
it('updates the PR', async () => {
|
2017-06-28 08:10:40 +00:00
|
|
|
await gitlab.updatePr(1, 'title', 'body');
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.put.mock.calls.length).toEqual(1);
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('mergePr(pr)', () => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
it('merges the PR', async () => {
|
|
|
|
await gitlab.mergePr({ number: 1 });
|
2017-10-17 05:15:01 +00:00
|
|
|
expect(get.put.mock.calls.length).toEqual(1);
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
2018-10-09 03:02:58 +00:00
|
|
|
const prBody = `https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5
|
|
|
|
|
|
|
|
Pull Requests are the best, here are some PRs.
|
|
|
|
|
|
|
|
## Open
|
|
|
|
|
|
|
|
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
|
|
|
|
|
|
|
|
- [ ] <!-- rebase-branch=renovate/major-got-packages -->[build(deps): update got packages (major)](../pull/2433) (\`gh-got\`, \`gl-got\`, \`got\`)
|
|
|
|
`;
|
2018-07-22 05:47:23 +00:00
|
|
|
describe('getPrBody(input)', () => {
|
|
|
|
it('returns updated pr body', () => {
|
2018-10-09 03:02:58 +00:00
|
|
|
expect(gitlab.getPrBody(prBody)).toMatchSnapshot();
|
2018-07-22 05:47:23 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
describe('getFile(filePath, branchName)', () => {
|
2017-12-23 07:03:16 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
get.mockReturnValueOnce({ body: [{ type: 'blob', path: 'some-path' }] });
|
|
|
|
await gitlab.getFileList();
|
|
|
|
});
|
2017-11-01 09:36:58 +00:00
|
|
|
it('gets the file', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-06-25 05:11:24 +00:00
|
|
|
body: {
|
|
|
|
content: 'foo',
|
|
|
|
},
|
|
|
|
});
|
2017-11-08 11:23:32 +00:00
|
|
|
const res = await gitlab.getFile('some-path');
|
2017-06-25 05:11:24 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2017-12-23 07:03:16 +00:00
|
|
|
it('short cuts 404', async () => {
|
|
|
|
const res = await gitlab.getFile('some-missing-path');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2017-12-23 07:03:16 +00:00
|
|
|
});
|
2017-06-25 05:11:24 +00:00
|
|
|
it('returns null for 404', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 }));
|
2017-11-08 11:23:32 +00:00
|
|
|
const res = await gitlab.getFile('some-path', 'some-branch');
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
it('throws error for non-404', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockImplementationOnce(() => Promise.reject({ statusCode: 403 }));
|
2019-04-19 20:04:37 +00:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
gitlab.getFile('some-path', 'some-branch')
|
|
|
|
).rejects.toMatchSnapshot();
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
2017-11-05 07:18:20 +00:00
|
|
|
describe('commitFilesToBranch(branchName, files, message, parentBranch)', () => {
|
2018-02-12 05:20:20 +00:00
|
|
|
it('creates file', async () => {
|
2018-02-12 05:58:33 +00:00
|
|
|
get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); // file exists
|
|
|
|
get.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 404,
|
|
|
|
})
|
|
|
|
); // branch exists
|
2018-03-13 19:33:22 +00:00
|
|
|
get.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 404,
|
|
|
|
})
|
|
|
|
); // branch exists
|
2017-11-05 07:18:20 +00:00
|
|
|
const file = {
|
2018-02-12 05:20:20 +00:00
|
|
|
name: 'some-new-file',
|
|
|
|
contents: 'some new-contents',
|
2017-11-05 07:18:20 +00:00
|
|
|
};
|
|
|
|
await gitlab.commitFilesToBranch(
|
2018-02-03 10:04:27 +00:00
|
|
|
'renovate/something',
|
2017-11-05 07:18:20 +00:00
|
|
|
[file],
|
2018-02-12 05:20:20 +00:00
|
|
|
'Create something'
|
2017-11-05 07:18:20 +00:00
|
|
|
);
|
2018-02-12 05:20:20 +00:00
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(1);
|
2017-07-27 07:36:36 +00:00
|
|
|
});
|
2018-02-12 05:20:20 +00:00
|
|
|
it('updates multiple files', async () => {
|
2018-02-12 05:58:33 +00:00
|
|
|
// Two files exist
|
2018-02-12 05:20:20 +00:00
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: {
|
|
|
|
content: 'foo',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: {
|
|
|
|
content: 'foo',
|
|
|
|
},
|
|
|
|
});
|
2018-02-12 05:58:33 +00:00
|
|
|
// branch exists
|
|
|
|
get.mockImplementationOnce(() => ({ statusCode: 200 }));
|
2018-03-13 19:33:22 +00:00
|
|
|
get.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 404,
|
|
|
|
})
|
|
|
|
); // branch exists
|
2018-02-12 05:20:20 +00:00
|
|
|
const files = [
|
|
|
|
{
|
|
|
|
name: 'some-existing-file',
|
|
|
|
contents: 'updated content',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'some-other-existing-file',
|
|
|
|
contents: 'other updated content',
|
|
|
|
},
|
|
|
|
];
|
2017-11-05 07:18:20 +00:00
|
|
|
await gitlab.commitFilesToBranch(
|
2018-02-12 05:20:20 +00:00
|
|
|
'renovate/something',
|
|
|
|
files,
|
|
|
|
'Update something'
|
2017-11-05 07:18:20 +00:00
|
|
|
);
|
2018-02-12 05:20:20 +00:00
|
|
|
expect(get.post.mock.calls).toMatchSnapshot();
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(get.post).toHaveBeenCalledTimes(1);
|
2017-06-25 05:11:24 +00:00
|
|
|
});
|
|
|
|
});
|
2017-07-07 05:54:09 +00:00
|
|
|
describe('getCommitMessages()', () => {
|
|
|
|
it('returns commits messages', async () => {
|
2017-10-17 05:15:01 +00:00
|
|
|
get.mockReturnValueOnce({
|
2017-07-07 05:54:09 +00:00
|
|
|
body: [
|
|
|
|
{
|
|
|
|
title: 'foo',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'bar',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const res = await gitlab.getCommitMessages();
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-07-28 06:47:49 +00:00
|
|
|
describe('getVulnerabilityAlerts()', () => {
|
|
|
|
it('returns empty', async () => {
|
|
|
|
const res = await gitlab.getVulnerabilityAlerts();
|
|
|
|
expect(res).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:01:10 +00:00
|
|
|
describe('deleteLabel(issueNo, label)', () => {
|
|
|
|
it('should delete the label', async () => {
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: {
|
|
|
|
id: 1,
|
|
|
|
iid: 12345,
|
|
|
|
description: 'a merge request',
|
|
|
|
state: 'merged',
|
|
|
|
merge_status: 'cannot_be_merged',
|
|
|
|
diverged_commits_count: 5,
|
|
|
|
source_branch: 'some-branch',
|
|
|
|
labels: ['foo', 'renovate', 'rebase'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
get.mockReturnValueOnce({
|
|
|
|
body: {
|
|
|
|
commit: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await gitlab.deleteLabel(42, 'rebase');
|
|
|
|
expect(get.put.mock.calls).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2017-06-22 19:35:32 +00:00
|
|
|
});
|