This repository has been archived by the owner on May 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fork_support' into 'master'
Support for forks https://dev.gitlab.org/gitlab/gitlab-ci/issues/187 !!! GitLab side MR - https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/499 See merge request !56
- Loading branch information
Showing
10 changed files
with
181 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Forks API | ||
|
||
This API is intended to aid in the setup and configuration of | ||
forked projects on Gitlab CI. | ||
|
||
__Authentication is done by GitLab user token & GitLab project token__ | ||
|
||
## Forks | ||
|
||
### Create fork for project | ||
|
||
|
||
|
||
``` | ||
POST /forks | ||
``` | ||
|
||
Parameters: | ||
|
||
project_id (required) - The ID of a project | ||
project_token (requires) - Project token | ||
private_token(required) - User private token | ||
data (required) - GitLab project data (name_with_namespace, web_url, default_branch, ssh_url_to_repo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,6 @@ class API < Grape::API | |
mount Commits | ||
mount Runners | ||
mount Projects | ||
mount Forks | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module API | ||
class Forks < Grape::API | ||
resource :forks do | ||
# Create a fork | ||
# | ||
# Parameters: | ||
# project_id (required) - The ID of a project | ||
# project_token (requires) - Project token | ||
# private_token(required) - User private token | ||
# data (required) - GitLab project data (name_with_namespace, web_url, default_branch, ssh_url_to_repo) | ||
# | ||
# | ||
# Example Request: | ||
# POST /forks | ||
post do | ||
required_attributes! [:project_id, :data, :project_token, :private_token] | ||
project = Project.find_by!(gitlab_id: params[:project_id]) | ||
authenticate_project_token!(project) | ||
|
||
user_session = UserSession.new | ||
user = user_session.authenticate_by_token(private_token: params[:private_token], url: GitlabCi.config.gitlab_server.url) | ||
|
||
fork = CreateProjectService.new.execute( | ||
user, | ||
params[:data], | ||
RoutesHelper.project_url(":project_id"), | ||
project | ||
) | ||
|
||
if fork | ||
present fork, with: Entities::Project | ||
else | ||
not_found! | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe API::API do | ||
include ApiHelpers | ||
|
||
let(:project) { FactoryGirl.create(:project) } | ||
let(:gitlab_url) { GitlabCi.config.gitlab_server.url } | ||
let(:auth_opts) { | ||
{ | ||
email: "test@test.com", | ||
password: "123456" | ||
} | ||
} | ||
let(:private_token) { Network.new.authenticate(gitlab_url, auth_opts)["private_token"] } | ||
|
||
let(:options) { | ||
{ | ||
private_token: private_token, | ||
url: gitlab_url | ||
} | ||
} | ||
|
||
before { | ||
stub_gitlab_calls | ||
} | ||
|
||
|
||
describe "POST /forks" do | ||
let(:project_info) { | ||
{ | ||
project_id: project.gitlab_id, | ||
project_token: project.token, | ||
data: { | ||
id: 2, | ||
name_with_namespace: "Gitlab.org / Underscore", | ||
web_url: "http://example.com/gitlab-org/underscore", | ||
default_branch: "master", | ||
ssh_url_to_repo: "git@example.com:gitlab-org/underscore" | ||
} | ||
} | ||
} | ||
|
||
context "with valid info" do | ||
before do | ||
options.merge!(project_info) | ||
end | ||
|
||
it "should create a project with valid data" do | ||
post api("/forks"), options | ||
response.status.should == 201 | ||
json_response['name'].should == "Gitlab.org / Underscore" | ||
end | ||
end | ||
|
||
context "with invalid project info" do | ||
before do | ||
options.merge!({}) | ||
end | ||
|
||
it "should error with invalid data" do | ||
post api("/forks"), options | ||
response.status.should == 400 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters