Commit 53573bde authored by Martin Wortschack's avatar Martin Wortschack

Merge branch...

Merge branch '191455-add-a-button-to-quickly-assign-users-who-have-commented-on-an-issue-or-merge-request-2' into 'master'

Add api.js methods to update issues and merge requests

See merge request gitlab-org/gitlab!32893
parents dc14dd09 d6fdda1d
......@@ -51,6 +51,7 @@ const Api = {
pipelinesPath: '/api/:version/projects/:id/pipelines/',
environmentsPath: '/api/:version/projects/:id/environments',
rawFilePath: '/api/:version/projects/:id/repository/files/:path/raw',
issuePath: '/api/:version/projects/:id/issues/:issue_iid',
group(groupId, callback) {
const url = Api.buildUrl(Api.groupPath).replace(':id', groupId);
......@@ -540,6 +541,22 @@ const Api = {
return axios.get(url, { params });
},
updateIssue(project, issue, data = {}) {
const url = Api.buildUrl(Api.issuePath)
.replace(':id', encodeURIComponent(project))
.replace(':issue_iid', encodeURIComponent(issue));
return axios.put(url, data);
},
updateMergeRequest(project, mergeRequest, data = {}) {
const url = Api.buildUrl(Api.projectMergeRequestPath)
.replace(':id', encodeURIComponent(project))
.replace(':mrid', encodeURIComponent(mergeRequest));
return axios.put(url, data);
},
buildUrl(url) {
return joinPaths(gon.relative_url_root || '', url.replace(':version', gon.api_version));
},
......
---
title: Add api.js methods to update issues and merge requests
merge_request: 32893
author:
type: added
......@@ -691,4 +691,38 @@ describe('Api', () => {
});
});
});
describe('updateIssue', () => {
it('update an issue with the given payload', done => {
const projectId = 8;
const issue = 1;
const expectedArray = [1, 2, 3];
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/issues/${issue}`;
mock.onPut(expectedUrl).reply(200, { assigneeIds: expectedArray });
Api.updateIssue(projectId, issue, { assigneeIds: expectedArray })
.then(({ data }) => {
expect(data.assigneeIds).toEqual(expectedArray);
done();
})
.catch(done.fail);
});
});
describe('updateMergeRequest', () => {
it('update an issue with the given payload', done => {
const projectId = 8;
const mergeRequest = 1;
const expectedArray = [1, 2, 3];
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/merge_requests/${mergeRequest}`;
mock.onPut(expectedUrl).reply(200, { assigneeIds: expectedArray });
Api.updateMergeRequest(projectId, mergeRequest, { assigneeIds: expectedArray })
.then(({ data }) => {
expect(data.assigneeIds).toEqual(expectedArray);
done();
})
.catch(done.fail);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment