summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2019-06-19 15:46:01 +0000
committerFilipa Lacerda <filipa@gitlab.com>2019-06-19 15:46:01 +0000
commit49480d8e0556d2dc96b0b460ef749c60d5231ebb (patch)
tree6ae3d8945efea65b854a76bd00ee439281c84daf
parente999e1de7baadc34e7fccf76e76991a7adf31b0e (diff)
parent778c705ffd99df0877159c10c39f0ab6964a52a7 (diff)
downloadgitlab-ce-49480d8e0556d2dc96b0b460ef749c60d5231ebb.tar.gz
Merge branch 'api-js-forked-projects' into 'master'
Added forked projects API call function See merge request gitlab-org/gitlab-ce!29841
-rw-r--r--app/assets/javascripts/api.js16
-rw-r--r--spec/frontend/api_spec.js23
2 files changed, 39 insertions, 0 deletions
diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js
index 7cebb88f3a4..4f66a5d080c 100644
--- a/app/assets/javascripts/api.js
+++ b/app/assets/javascripts/api.js
@@ -12,6 +12,7 @@ const Api = {
groupProjectsPath: '/api/:version/groups/:id/projects.json',
projectsPath: '/api/:version/projects.json',
projectPath: '/api/:version/projects/:id',
+ forkedProjectsPath: '/api/:version/projects/:id/forks',
projectLabelsPath: '/:namespace_path/:project_path/-/labels',
projectMergeRequestsPath: '/api/:version/projects/:id/merge_requests',
projectMergeRequestPath: '/api/:version/projects/:id/merge_requests/:mrid',
@@ -114,6 +115,21 @@ const Api = {
},
/**
+ * Get all projects for a forked relationship to a specified project
+ * @param {string} projectPath - Path or ID of a project
+ * @param {Object} params - Get request parameters
+ * @returns {Promise} - Request promise
+ */
+ projectForks(projectPath, params) {
+ const url = Api.buildUrl(Api.forkedProjectsPath).replace(
+ ':id',
+ encodeURIComponent(projectPath),
+ );
+
+ return axios.get(url, { params });
+ },
+
+ /**
* Get all Merge Requests for a project, eventually filtering based on
* supplied parameters
* @param projectPath
diff --git a/spec/frontend/api_spec.js b/spec/frontend/api_spec.js
index 6010488d9e0..0188d12a57d 100644
--- a/spec/frontend/api_spec.js
+++ b/spec/frontend/api_spec.js
@@ -474,4 +474,27 @@ describe('Api', () => {
.catch(done.fail);
});
});
+
+ describe('projectForks', () => {
+ it('gets forked projects', done => {
+ const dummyProjectPath = 'gitlab-org/gitlab-ce';
+ const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
+ dummyProjectPath,
+ )}/forks`;
+
+ jest.spyOn(axios, 'get');
+
+ mock.onGet(expectedUrl).replyOnce(200, ['fork']);
+
+ Api.projectForks(dummyProjectPath, { visibility: 'private' })
+ .then(({ data }) => {
+ expect(data).toEqual(['fork']);
+ expect(axios.get).toHaveBeenCalledWith(expectedUrl, {
+ params: { visibility: 'private' },
+ });
+ })
+ .then(done)
+ .catch(done.fail);
+ });
+ });
});