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
7e2d97df
Commit
7e2d97df
authored
Mar 05, 2021
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates handling of `sha` being `nil`
* Adds helper for finding a sha so it can return nil
parent
f699bbc9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+9
-1
lib/gitlab/ci/lint.rb
lib/gitlab/ci/lint.rb
+1
-1
spec/requests/api/lint_spec.rb
spec/requests/api/lint_spec.rb
+18
-0
No files found.
lib/gitlab/ci/config.rb
View file @
7e2d97df
...
...
@@ -99,10 +99,18 @@ module Gitlab
initial_config
end
def
find_sha
(
project
)
branches
=
project
&
.
repository
&
.
branches
||
[]
unless
branches
.
empty?
project
.
repository
.
root_ref_sha
end
end
def
build_context
(
project
:,
sha
:,
user
:,
parent_pipeline
:)
Config
::
External
::
Context
.
new
(
project:
project
,
sha:
sha
||
project
&
.
repository
&
.
root_ref_sha
,
sha:
sha
||
find_sha
(
project
)
,
user:
user
,
parent_pipeline:
parent_pipeline
,
variables:
project
&
.
predefined_variables
&
.
to_runner_variables
)
...
...
lib/gitlab/ci/lint.rb
View file @
7e2d97df
...
...
@@ -21,7 +21,7 @@ module Gitlab
def
initialize
(
project
:,
current_user
:,
sha:
nil
)
@project
=
project
@current_user
=
current_user
@sha
=
sha
||
project
.
repository
.
commit
.
sha
@sha
=
sha
||
project
.
repository
.
commit
&
.
sha
end
def
validate
(
content
,
dry_run:
false
)
...
...
spec/requests/api/lint_spec.rb
View file @
7e2d97df
...
...
@@ -406,6 +406,24 @@ RSpec.describe API::Lint do
end
end
context
'with an empty repository'
do
let_it_be
(
:empty_project
)
{
create
(
:project_empty_repo
)
}
let_it_be
(
:yaml_content
)
do
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
end
before
do
empty_project
.
add_developer
(
api_user
)
end
it
'passes validation without errors'
do
post
api
(
"/projects/
#{
empty_project
.
id
}
/ci/lint"
,
api_user
),
params:
{
content:
yaml_content
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'valid'
]).
to
eq
(
true
)
expect
(
json_response
[
'errors'
]).
to
eq
([])
end
end
context
'when unauthenticated'
do
let_it_be
(
:api_user
)
{
nil
}
...
...
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