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
bb49be3c
Commit
bb49be3c
authored
Dec 04, 2020
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
b31fbcbf
a3c102b8
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
417 additions
and
251 deletions
+417
-251
.gitlab/ci/docs.gitlab-ci.yml
.gitlab/ci/docs.gitlab-ci.yml
+2
-2
Gemfile
Gemfile
+1
-1
Gemfile.lock
Gemfile.lock
+2
-2
config/feature_flags/development/diff_check_with_paths_changed_rpc.yml
...e_flags/development/diff_check_with_paths_changed_rpc.yml
+8
-0
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+4
-12
ee/lib/ee/gitlab/checks/diff_check.rb
ee/lib/ee/gitlab/checks/diff_check.rb
+23
-7
ee/spec/lib/gitlab/checks/diff_check_spec.rb
ee/spec/lib/gitlab/checks/diff_check_spec.rb
+230
-218
lib/gitlab/checks/diff_check.rb
lib/gitlab/checks/diff_check.rb
+15
-6
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+12
-0
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+17
-0
spec/lib/gitlab/checks/diff_check_spec.rb
spec/lib/gitlab/checks/diff_check_spec.rb
+18
-3
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+60
-0
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+25
-0
No files found.
.gitlab/ci/docs.gitlab-ci.yml
View file @
bb49be3c
...
...
@@ -70,8 +70,8 @@ docs-lint links:
# Don't delete the documentation/index.md, which is a false positive for the simple grep.
-
grep -rl "redirect_to:" /tmp/gitlab-docs/content/ee/ | grep -v "development/documentation/index.md" | xargs rm -f
-
bundle exec nanoc
-
echo -e "\e[96mThe following test fails when a doc links to a redirect file."
-
echo -e "\e[96mMake sure all links point to the correct page."
-
echo -e "\e[
1;
96mThe following test fails when a doc links to a redirect file."
-
echo -e "\e[
1;
96mMake sure all links point to the correct page."
-
bundle exec nanoc check internal_links
# Check the internal anchor links
-
bundle exec nanoc check internal_anchors
...
...
Gemfile
View file @
bb49be3c
...
...
@@ -466,7 +466,7 @@ group :ed25519 do
end
# Gitaly GRPC protocol definitions
gem
'
gitaly
'
,
'~> 13.
6.
1'
gem
'
gitaly
'
,
'~> 13.
7.0.pre.rc
1'
gem
'
grpc
'
,
'~> 1.30.2'
...
...
Gemfile.lock
View file @
bb49be3c
...
...
@@ -422,7 +422,7 @@ GEM
rails (>= 3.2.0)
git (1.7.0)
rchardet (~> 1.8)
gitaly (13.
6.
1)
gitaly (13.
7.0.pre.rc
1)
grpc (~> 1.0)
github-markup (1.7.0)
gitlab-chronic (0.10.5)
...
...
@@ -1349,7 +1349,7 @@ DEPENDENCIES
gettext (~> 3.3)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3)
gitaly (~> 13.
6.
1)
gitaly (~> 13.
7.0.pre.rc
1)
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-fog-azure-rm (~> 1.0)
...
...
config/feature_flags/development/diff_check_with_paths_changed_rpc.yml
0 → 100644
View file @
bb49be3c
---
name
:
diff_check_with_paths_changed_rpc
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/46116
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/288827
milestone
:
'
13.7'
type
:
development
group
:
group::code review
default_enabled
:
false
doc/ci/yaml/README.md
View file @
bb49be3c
...
...
@@ -1004,9 +1004,6 @@ docker build:
allow_failure
:
true
```
Additional job configuration may be added to rules in the future. If something
useful is not available, please
[
open an issue
](
https://gitlab.com/gitlab-org/gitlab/-/issues
)
.
#### Rules clauses
Available rule clauses are:
...
...
@@ -1612,8 +1609,8 @@ Feature.enable(:allow_unsafe_ruby_regexp)
### `only`/`except` (advanced)
GitLab supports
both simple and complex strategies, so
it's possible to use an
array
and
a hash configuration scheme.
GitLab supports
multiple strategies, and
it's possible to use an
array
or
a hash configuration scheme.
Four keys are available:
...
...
@@ -2556,9 +2553,6 @@ To follow progress on support for GitLab-managed clusters, see the
#### Dynamic environments
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/21971) in GitLab 8.12 and GitLab Runner 1.6.
> - The `$CI_ENVIRONMENT_SLUG` was [introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/22864) in GitLab 8.15.
Use CI/CD
[
variables
](
../variables/README.md
)
to dynamically name environments.
For example:
...
...
@@ -3273,8 +3267,6 @@ and bring back the old behavior.
### `coverage`
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/20428) in GitLab 8.17.
Use
`coverage`
to configure how code coverage is extracted from the
job output.
...
...
@@ -3513,9 +3505,9 @@ In [GitLab 13.5](https://gitlab.com/gitlab-org/gitlab/-/issues/201938) and later
can use
[
`when:manual`
](
#whenmanual
)
in the same job as
`trigger`
. In GitLab 13.4 and
earlier, using them together causes the error
`jobs:#{job-name} when should be on_success, on_failure or always`
.
####
Simple
`trigger` syntax for multi-project pipelines
####
Basic
`trigger` syntax for multi-project pipelines
The simplest way to configure a downstream trigger is to us
e
`trigger`
keyword
You can configure a downstream trigger by using th
e
`trigger`
keyword
with a full path to a downstream project:
```
yaml
...
...
ee/lib/ee/gitlab/checks/diff_check.rb
View file @
bb49be3c
...
...
@@ -58,10 +58,14 @@ module EE
def
path_locks_validation
lambda
do
|
diff
|
path
=
if
diff
.
renamed_file?
diff
.
old_
path
path
=
if
::
Feature
.
enabled?
(
:diff_check_with_paths_changed_rpc
,
project
)
diff
.
path
else
diff
.
new_path
||
diff
.
old_path
if
diff
.
renamed_file?
diff
.
old_path
else
diff
.
new_path
||
diff
.
old_path
end
end
lock_info
=
project
.
find_path_lock
(
path
)
...
...
@@ -72,12 +76,24 @@ module EE
end
end
def
new_file?
(
path
)
path
.
status
==
:ADDED
end
def
file_name_validation
lambda
do
|
diff
|
if
(
diff
.
renamed_file
||
diff
.
new_file
)
&&
blacklisted_regex
=
push_rule
.
filename_denylisted?
(
diff
.
new_path
)
return
unless
blacklisted_regex
.
present?
"File name
#{
diff
.
new_path
}
was blacklisted by the pattern
#{
blacklisted_regex
}
."
if
::
Feature
.
enabled?
(
:diff_check_with_paths_changed_rpc
,
project
)
if
new_file?
(
diff
)
&&
denylisted_regex
=
push_rule
.
filename_denylisted?
(
diff
.
path
)
return
unless
denylisted_regex
.
present?
"File name
#{
diff
.
path
}
was blacklisted by the pattern
#{
denylisted_regex
}
."
end
else
if
(
diff
.
renamed_file
||
diff
.
new_file
)
&&
denylisted_regex
=
push_rule
.
filename_denylisted?
(
diff
.
new_path
)
return
unless
denylisted_regex
.
present?
"File name
#{
diff
.
new_path
}
was blacklisted by the pattern
#{
denylisted_regex
}
."
end
end
rescue
::
PushRule
::
MatchError
=>
e
raise
::
Gitlab
::
GitAccess
::
ForbiddenError
,
e
.
message
...
...
ee/spec/lib/gitlab/checks/diff_check_spec.rb
View file @
bb49be3c
This diff is collapsed.
Click to expand it.
lib/gitlab/checks/diff_check.rb
View file @
bb49be3c
...
...
@@ -17,17 +17,26 @@ module Gitlab
file_paths
=
[]
process_commits
do
|
commit
|
validate_once
(
commit
)
do
commit
.
raw_deltas
.
each
do
|
diff
|
file_paths
.
concat
([
diff
.
new_path
,
diff
.
old_path
].
compact
)
if
::
Feature
.
enabled?
(
:diff_check_with_paths_changed_rpc
,
project
)
paths
=
project
.
repository
.
find_changed_paths
(
commits
.
map
(
&
:sha
))
paths
.
each
do
|
path
|
file_paths
.
concat
([
path
.
path
]
)
validate_diff
(
diff
)
validate_diff
(
path
)
end
else
process_commits
do
|
commit
|
validate_once
(
commit
)
do
commit
.
raw_deltas
.
each
do
|
diff
|
file_paths
.
concat
([
diff
.
new_path
,
diff
.
old_path
].
compact
)
validate_diff
(
diff
)
end
end
end
end
validate_file_paths
(
file_paths
)
validate_file_paths
(
file_paths
.
uniq
)
end
private
...
...
lib/gitlab/git/repository.rb
View file @
bb49be3c
...
...
@@ -467,6 +467,18 @@ module Gitlab
empty_diff_stats
end
def
find_changed_paths
(
commits
)
processed_commits
=
commits
.
reject
{
|
ref
|
ref
.
blank?
||
Gitlab
::
Git
.
blank_ref?
(
ref
)
}
return
[]
if
processed_commits
.
empty?
wrapped_gitaly_errors
do
gitaly_commit_client
.
find_changed_paths
(
processed_commits
)
end
rescue
CommandError
,
TypeError
,
NoRepository
[]
end
# Returns a RefName for a given SHA
def
ref_name_for_sha
(
ref_path
,
sha
)
raise
ArgumentError
,
"sha can't be empty"
unless
sha
.
present?
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
bb49be3c
...
...
@@ -216,6 +216,23 @@ module Gitlab
response
.
flat_map
(
&
:stats
)
end
def
find_changed_paths
(
commits
)
request
=
Gitaly
::
FindChangedPathsRequest
.
new
(
repository:
@gitaly_repo
,
commits:
commits
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:diff_service
,
:find_changed_paths
,
request
,
timeout:
GitalyClient
.
medium_timeout
)
response
.
flat_map
do
|
msg
|
msg
.
paths
.
map
do
|
path
|
OpenStruct
.
new
(
status:
path
.
status
,
path:
EncodingHelper
.
encode!
(
path
.
path
)
)
end
end
end
def
find_all_commits
(
opts
=
{})
request
=
Gitaly
::
FindAllCommitsRequest
.
new
(
repository:
@gitaly_repo
,
...
...
spec/lib/gitlab/checks/diff_check_spec.rb
View file @
bb49be3c
...
...
@@ -7,7 +7,6 @@ RSpec.describe Gitlab::Checks::DiffCheck do
describe
'#validate!'
do
let
(
:owner
)
{
create
(
:user
)
}
let!
(
:lock
)
{
create
(
:lfs_file_lock
,
user:
owner
,
project:
project
,
path:
'README'
)
}
before
do
allow
(
project
.
repository
).
to
receive
(
:new_commits
).
and_return
(
...
...
@@ -28,13 +27,27 @@ RSpec.describe Gitlab::Checks::DiffCheck do
end
context
'with LFS enabled'
do
let!
(
:lock
)
{
create
(
:lfs_file_lock
,
user:
owner
,
project:
project
,
path:
'README'
)
}
before
do
allow
(
project
).
to
receive
(
:lfs_enabled?
).
and_return
(
true
)
end
context
'when change is sent by a different user'
do
it
'raises an error if the user is not allowed to update the file'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
"The path 'README' is locked in Git LFS by
#{
lock
.
user
.
name
}
"
)
context
'when diff check with paths rpc feature flag is true'
do
it
'raises an error if the user is not allowed to update the file'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
"The path 'README' is locked in Git LFS by
#{
lock
.
user
.
name
}
"
)
end
end
context
'when diff check with paths rpc feature flag is false'
do
before
do
stub_feature_flags
(
diff_check_with_paths_changed_rpc:
false
)
end
it
'raises an error if the user is not allowed to update the file'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
"The path 'README' is locked in Git LFS by
#{
lock
.
user
.
name
}
"
)
end
end
end
...
...
@@ -53,6 +66,8 @@ RSpec.describe Gitlab::Checks::DiffCheck do
expect_any_instance_of
(
Commit
).
to
receive
(
:raw_deltas
).
and_call_original
stub_feature_flags
(
diff_check_with_paths_changed_rpc:
false
)
subject
.
validate!
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
bb49be3c
...
...
@@ -1185,6 +1185,66 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
describe
'#find_changed_paths'
do
let
(
:commit_1
)
{
'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6'
}
let
(
:commit_2
)
{
'4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6'
}
let
(
:commit_3
)
{
'6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9'
}
let
(
:commit_1_files
)
do
[
OpenStruct
.
new
(
status: :ADDED
,
path:
"files/executables/ls"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"files/executables/touch"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"files/links/regex.rb"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"files/links/ruby-style-guide.md"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"files/links/touch"
),
OpenStruct
.
new
(
status: :MODIFIED
,
path:
".gitmodules"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"deeper/nested/six"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"nested/six"
)
]
end
let
(
:commit_2_files
)
do
[
OpenStruct
.
new
(
status: :ADDED
,
path:
"bin/executable"
)]
end
let
(
:commit_3_files
)
do
[
OpenStruct
.
new
(
status: :MODIFIED
,
path:
".gitmodules"
),
OpenStruct
.
new
(
status: :ADDED
,
path:
"gitlab-shell"
)
]
end
it
'returns a list of paths'
do
collection
=
repository
.
find_changed_paths
([
commit_1
,
commit_2
,
commit_3
])
expect
(
collection
).
to
be_a
(
Enumerable
)
expect
(
collection
.
to_a
).
to
eq
(
commit_1_files
+
commit_2_files
+
commit_3_files
)
end
it
'returns no paths when SHAs are invalid'
do
collection
=
repository
.
find_changed_paths
([
'invalid'
,
commit_1
])
expect
(
collection
).
to
be_a
(
Enumerable
)
expect
(
collection
.
to_a
).
to
be_empty
end
it
'returns a list of paths even when containing a blank ref'
do
collection
=
repository
.
find_changed_paths
([
nil
,
commit_1
])
expect
(
collection
).
to
be_a
(
Enumerable
)
expect
(
collection
.
to_a
).
to
eq
(
commit_1_files
)
end
it
'returns no paths when the commits are nil'
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
CommitService
)
.
not_to
receive
(
:find_changed_paths
)
collection
=
repository
.
find_changed_paths
([
nil
,
nil
])
expect
(
collection
).
to
be_a
(
Enumerable
)
expect
(
collection
.
to_a
).
to
be_empty
end
end
describe
"#ls_files"
do
let
(
:master_file_paths
)
{
repository
.
ls_files
(
"master"
)
}
let
(
:utf8_file_paths
)
{
repository
.
ls_files
(
"ls-files-utf8"
)
}
...
...
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
bb49be3c
...
...
@@ -145,6 +145,31 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
end
end
describe
'#find_changed_paths'
do
let
(
:commits
)
{
%w[1a0b36b3cdad1d2ee32457c102a8c0b7056fa863 cfe32cf61b73a0d5e9f13e774abde7ff789b1660]
}
it
'sends an RPC request and returns the stats'
do
request
=
Gitaly
::
FindChangedPathsRequest
.
new
(
repository:
repository_message
,
commits:
commits
)
changed_paths_response
=
Gitaly
::
FindChangedPathsResponse
.
new
(
paths:
[{
path:
"app/assets/javascripts/boards/components/project_select.vue"
,
status: :MODIFIED
}])
expect_any_instance_of
(
Gitaly
::
DiffService
::
Stub
).
to
receive
(
:find_changed_paths
)
.
with
(
request
,
kind_of
(
Hash
)).
and_return
([
changed_paths_response
])
returned_value
=
described_class
.
new
(
repository
).
find_changed_paths
(
commits
)
mapped_returned_value
=
returned_value
.
map
(
&
:to_h
)
mapped_expected_value
=
changed_paths_response
.
paths
.
map
(
&
:to_h
)
expect
(
mapped_returned_value
).
to
eq
(
mapped_expected_value
)
end
end
describe
'#tree_entries'
do
let
(
:path
)
{
'/'
}
...
...
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