Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
34a14532
Commit
34a14532
authored
Feb 25, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
046fcf59
c6b9ac86
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
273 additions
and
16 deletions
+273
-16
app/models/ci/build.rb
app/models/ci/build.rb
+8
-5
app/presenters/ci/build_runner_presenter.rb
app/presenters/ci/build_runner_presenter.rb
+42
-0
app/services/projects/fork_service.rb
app/services/projects/fork_service.rb
+10
-2
changelogs/unreleased/40795-set-project-name-on-fork-api.yml
changelogs/unreleased/40795-set-project-name-on-fork-api.yml
+5
-0
changelogs/unreleased/expose-merge-ref-to-runner.yml
changelogs/unreleased/expose-merge-ref-to-runner.yml
+5
-0
doc/api/projects.md
doc/api/projects.md
+2
-0
doc/development/code_review.md
doc/development/code_review.md
+4
-1
lib/api/entities.rb
lib/api/entities.rb
+3
-7
lib/api/projects.rb
lib/api/projects.rb
+2
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+1
-0
spec/presenters/ci/build_runner_presenter_spec.rb
spec/presenters/ci/build_runner_presenter_spec.rb
+68
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+48
-0
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+75
-1
No files found.
app/models/ci/build.rb
View file @
34a14532
...
...
@@ -46,6 +46,7 @@ module Ci
delegate
:terminal_specification
,
to: :runner_session
,
allow_nil:
true
delegate
:gitlab_deploy_token
,
to: :project
delegate
:trigger_short_token
,
to: :trigger_request
,
allow_nil:
true
delegate
:merge_request?
,
to: :pipeline
##
# Since Gitlab 11.5, deployments records started being created right after
...
...
@@ -441,12 +442,14 @@ module Ci
# All variables, including persisted environment variables.
#
def
variables
strong_memoize
(
:variables
)
do
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
concat
(
persisted_variables
)
.
concat
(
scoped_variables
)
.
concat
(
persisted_environment_variables
)
.
to_runner_variables
end
end
##
# Regular Ruby hash of scoped variables, without duplicates that are
...
...
app/presenters/ci/build_runner_presenter.rb
View file @
34a14532
...
...
@@ -2,6 +2,11 @@
module
Ci
class
BuildRunnerPresenter
<
SimpleDelegator
include
Gitlab
::
Utils
::
StrongMemoize
RUNNER_REMOTE_TAG_PREFIX
=
'refs/tags/'
.
freeze
RUNNER_REMOTE_BRANCH_PREFIX
=
'refs/remotes/origin/'
.
freeze
def
artifacts
return
unless
options
[
:artifacts
]
...
...
@@ -11,6 +16,35 @@ module Ci
list
.
flatten
.
compact
end
def
ref_type
if
tag
'tag'
else
'branch'
end
end
def
git_depth
strong_memoize
(
:git_depth
)
do
git_depth
=
variables
&
.
find
{
|
variable
|
variable
[
:key
]
==
'GIT_DEPTH'
}
&
.
dig
(
:value
)
git_depth
.
to_i
end
end
def
refspecs
specs
=
[]
if
git_depth
>
0
specs
<<
refspec_for_branch
(
ref
)
if
branch?
||
merge_request?
specs
<<
refspec_for_tag
(
ref
)
if
tag?
else
specs
<<
refspec_for_branch
specs
<<
refspec_for_tag
end
specs
end
private
def
create_archive
(
artifacts
)
...
...
@@ -41,5 +75,13 @@ module Ci
}
end
end
def
refspec_for_branch
(
ref
=
'*'
)
"+
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
ref
}
:
#{
RUNNER_REMOTE_BRANCH_PREFIX
}#{
ref
}
"
end
def
refspec_for_tag
(
ref
=
'*'
)
"+
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}#{
ref
}
:
#{
RUNNER_REMOTE_TAG_PREFIX
}#{
ref
}
"
end
end
end
app/services/projects/fork_service.rb
View file @
34a14532
...
...
@@ -38,8 +38,8 @@ module Projects
new_params
=
{
visibility_level:
allowed_visibility_level
,
description:
@project
.
description
,
name:
@project
.
name
,
path:
@project
.
path
,
name:
target_
name
,
path:
target_
path
,
shared_runners_enabled:
@project
.
shared_runners_enabled
,
namespace_id:
target_namespace
.
id
,
fork_network:
fork_network
,
...
...
@@ -94,6 +94,14 @@ module Projects
Projects
::
ForksCountService
.
new
(
@project
).
refresh_cache
end
def
target_path
@target_path
||=
@params
[
:path
]
||
@project
.
path
end
def
target_name
@target_name
||=
@params
[
:name
]
||
@project
.
name
end
def
target_namespace
@target_namespace
||=
@params
[
:namespace
]
||
current_user
.
namespace
end
...
...
changelogs/unreleased/40795-set-project-name-on-fork-api.yml
0 → 100644
View file @
34a14532
---
title
:
Add ability to set path and name for project on fork using API
merge_request
:
25363
author
:
type
:
added
changelogs/unreleased/expose-merge-ref-to-runner.yml
0 → 100644
View file @
34a14532
---
title
:
Expose refspecs and depth to runner
merge_request
:
25233
author
:
type
:
added
doc/api/projects.md
View file @
34a14532
...
...
@@ -805,6 +805,8 @@ POST /projects/:id/fork
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
|
|
`namespace`
| integer/string | yes | The ID or path of the namespace that the project will be forked to |
|
`path`
| string | no | The path that will be assigned to the resultant project after forking |
|
`name`
| string | no | The name that will be assigned to the resultant project after forking |
## List Forks of a project
...
...
doc/development/code_review.md
View file @
34a14532
...
...
@@ -203,7 +203,10 @@ first time.
-
Extract unrelated changes and refactorings into future merge requests/issues.
-
Seek to understand the reviewer's perspective.
-
Try to respond to every comment.
-
Let the reviewer select the "Resolve discussion" buttons.
-
The merge request author resolves only the discussions they have fully
addressed. If there's an open reply, an open discussion, a suggestion,
a question, or anything else, the discussion should be left to be resolved
by the reviewer.
-
Push commits based on earlier rounds of feedback as isolated commits to the
branch. Do not squash until the branch is ready to merge. Reviewers should be
able to read individual updates based on their earlier feedback.
...
...
lib/api/entities.rb
View file @
34a14532
...
...
@@ -1387,13 +1387,9 @@ module API
class
GitInfo
<
Grape
::
Entity
expose
:repo_url
,
:ref
,
:sha
,
:before_sha
expose
:ref_type
do
|
model
|
if
model
.
tag
'tag'
else
'branch'
end
end
expose
:ref_type
expose
:refspecs
expose
:git_depth
,
as: :depth
end
class
RunnerInfo
<
Grape
::
Entity
...
...
lib/api/projects.rb
View file @
34a14532
...
...
@@ -260,6 +260,8 @@ module API
end
params
do
optional
:namespace
,
type:
String
,
desc:
'The ID or name of the namespace that the project will be forked into'
optional
:path
,
type:
String
,
desc:
'The path that will be assigned to the fork'
optional
:name
,
type:
String
,
desc:
'The name that will be assigned to the fork'
end
post
':id/fork'
do
Gitlab
::
QueryLimiting
.
whitelist
(
'https://gitlab.com/gitlab-org/gitlab-ce/issues/42284'
)
...
...
spec/models/ci/build_spec.rb
View file @
34a14532
...
...
@@ -24,6 +24,7 @@ describe Ci::Build do
it
{
is_expected
.
to
validate_presence_of
(
:ref
)
}
it
{
is_expected
.
to
respond_to
(
:has_trace?
)
}
it
{
is_expected
.
to
respond_to
(
:trace
)
}
it
{
is_expected
.
to
delegate_method
(
:merge_request?
).
to
(
:pipeline
)
}
it
{
is_expected
.
to
be_a
(
ArtifactMigratable
)
}
...
...
spec/presenters/ci/build_runner_presenter_spec.rb
View file @
34a14532
...
...
@@ -98,4 +98,72 @@ describe Ci::BuildRunnerPresenter do
end
end
end
describe
'#ref_type'
do
subject
{
presenter
.
ref_type
}
let
(
:build
)
{
create
(
:ci_build
,
tag:
tag
)
}
let
(
:tag
)
{
true
}
it
'returns the correct ref type'
do
is_expected
.
to
eq
(
'tag'
)
end
context
'when tag is false'
do
let
(
:tag
)
{
false
}
it
'returns the correct ref type'
do
is_expected
.
to
eq
(
'branch'
)
end
end
end
describe
'#git_depth'
do
subject
{
presenter
.
git_depth
}
let
(
:build
)
{
create
(
:ci_build
)
}
it
'returns the correct git depth'
do
is_expected
.
to
eq
(
0
)
end
context
'when GIT_DEPTH variable is specified'
do
before
do
create
(
:ci_pipeline_variable
,
key:
'GIT_DEPTH'
,
value:
1
,
pipeline:
build
.
pipeline
)
end
it
'returns the correct git depth'
do
is_expected
.
to
eq
(
1
)
end
end
end
describe
'#refspecs'
do
subject
{
presenter
.
refspecs
}
let
(
:build
)
{
create
(
:ci_build
)
}
it
'returns the correct refspecs'
do
is_expected
.
to
contain_exactly
(
'+refs/tags/*:refs/tags/*'
,
'+refs/heads/*:refs/remotes/origin/*'
)
end
context
'when GIT_DEPTH variable is specified'
do
before
do
create
(
:ci_pipeline_variable
,
key:
'GIT_DEPTH'
,
value:
1
,
pipeline:
build
.
pipeline
)
end
it
'returns the correct refspecs'
do
is_expected
.
to
contain_exactly
(
"+refs/heads/
#{
build
.
ref
}
:refs/remotes/origin/
#{
build
.
ref
}
"
)
end
context
'when ref is tag'
do
let
(
:build
)
{
create
(
:ci_build
,
:tag
)
}
it
'returns the correct refspecs'
do
is_expected
.
to
contain_exactly
(
"+refs/tags/
#{
build
.
ref
}
:refs/tags/
#{
build
.
ref
}
"
)
end
end
end
end
end
spec/requests/api/projects_spec.rb
View file @
34a14532
...
...
@@ -2061,6 +2061,11 @@ describe API::Projects do
let
(
:project
)
do
create
(
:project
,
:repository
,
creator:
user
,
namespace:
user
.
namespace
)
end
let
(
:project2
)
do
create
(
:project
,
:repository
,
creator:
user
,
namespace:
user
.
namespace
)
end
let
(
:group
)
{
create
(
:group
)
}
let
(
:group2
)
do
group
=
create
(
:group
,
name:
'group2_name'
)
...
...
@@ -2076,6 +2081,7 @@ describe API::Projects do
before
do
project
.
add_reporter
(
user2
)
project2
.
add_reporter
(
user2
)
end
context
'when authenticated'
do
...
...
@@ -2190,6 +2196,48 @@ describe API::Projects do
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'namespace'
][
'name'
]).
to
eq
(
group
.
name
)
end
it
'accepts a path for the target project'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
params:
{
path:
'foobar'
}
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
'foobar'
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
expect
(
json_response
[
'namespace'
][
'id'
]).
to
eq
(
user2
.
namespace
.
id
)
expect
(
json_response
[
'forked_from_project'
][
'id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
[
'import_status'
]).
to
eq
(
'scheduled'
)
expect
(
json_response
).
to
include
(
"import_error"
)
end
it
'fails to fork if path is already taken'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
params:
{
path:
'foobar'
}
post
api
(
"/projects/
#{
project2
.
id
}
/fork"
,
user2
),
params:
{
path:
'foobar'
}
expect
(
response
).
to
have_gitlab_http_status
(
409
)
expect
(
json_response
[
'message'
][
'path'
]).
to
eq
([
'has already been taken'
])
end
it
'accepts a name for the target project'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
params:
{
name:
'My Random Project'
}
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'My Random Project'
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
expect
(
json_response
[
'namespace'
][
'id'
]).
to
eq
(
user2
.
namespace
.
id
)
expect
(
json_response
[
'forked_from_project'
][
'id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
[
'import_status'
]).
to
eq
(
'scheduled'
)
expect
(
json_response
).
to
include
(
"import_error"
)
end
it
'fails to fork if name is already taken'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
params:
{
name:
'My Random Project'
}
post
api
(
"/projects/
#{
project2
.
id
}
/fork"
,
user2
),
params:
{
name:
'My Random Project'
}
expect
(
response
).
to
have_gitlab_http_status
(
409
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
'has already been taken'
])
end
end
context
'when unauthenticated'
do
...
...
spec/requests/api/runner_spec.rb
View file @
34a14532
...
...
@@ -417,7 +417,9 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
'ref'
=>
job
.
ref
,
'sha'
=>
job
.
sha
,
'before_sha'
=>
job
.
before_sha
,
'ref_type'
=>
'branch'
}
'ref_type'
=>
'branch'
,
'refspecs'
=>
%w[+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*]
,
'depth'
=>
0
}
end
let
(
:expected_steps
)
do
...
...
@@ -489,6 +491,29 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'ref_type'
]).
to
eq
(
'tag'
)
end
context
'when GIT_DEPTH is specified'
do
before
do
create
(
:ci_pipeline_variable
,
key:
'GIT_DEPTH'
,
value:
1
,
pipeline:
pipeline
)
end
it
'specifies refspecs'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'refspecs'
]).
to
include
(
"+refs/tags/
#{
job
.
ref
}
:refs/tags/
#{
job
.
ref
}
"
)
end
end
context
'when GIT_DEPTH is not specified'
do
it
'specifies refspecs'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'refspecs'
])
.
to
contain_exactly
(
'+refs/tags/*:refs/tags/*'
,
'+refs/heads/*:refs/remotes/origin/*'
)
end
end
end
context
'when job is made for branch'
do
...
...
@@ -498,6 +523,55 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'ref_type'
]).
to
eq
(
'branch'
)
end
context
'when GIT_DEPTH is specified'
do
before
do
create
(
:ci_pipeline_variable
,
key:
'GIT_DEPTH'
,
value:
1
,
pipeline:
pipeline
)
end
it
'specifies refspecs'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'refspecs'
]).
to
include
(
"+refs/heads/
#{
job
.
ref
}
:refs/remotes/origin/
#{
job
.
ref
}
"
)
end
end
context
'when GIT_DEPTH is not specified'
do
it
'specifies refspecs'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'refspecs'
])
.
to
contain_exactly
(
'+refs/tags/*:refs/tags/*'
,
'+refs/heads/*:refs/remotes/origin/*'
)
end
end
end
context
'when job is made for merge request'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline_without_jobs
,
source: :merge_request
,
project:
project
,
ref:
'feature'
,
merge_request:
merge_request
)
}
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'spinach'
,
ref:
'feature'
,
stage:
'test'
,
stage_idx:
0
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it
'sets branch as ref_type'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'ref_type'
]).
to
eq
(
'branch'
)
end
context
'when GIT_DEPTH is specified'
do
before
do
create
(
:ci_pipeline_variable
,
key:
'GIT_DEPTH'
,
value:
1
,
pipeline:
pipeline
)
end
it
'returns the overwritten git depth for merge request refspecs'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'git_info'
][
'depth'
]).
to
eq
(
1
)
end
end
end
it
'updates runner info'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment