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
7cee6139
Commit
7cee6139
authored
Jul 17, 2019
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find build by sha from ref
Adds ability to find builds by sha when only specifying a ref.
parent
d892e80b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
5 deletions
+24
-5
app/controllers/projects/artifacts_controller.rb
app/controllers/projects/artifacts_controller.rb
+4
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+6
-1
app/models/project.rb
app/models/project.rb
+12
-1
spec/features/projects/artifacts/user_downloads_artifacts_spec.rb
...tures/projects/artifacts/user_downloads_artifacts_spec.rb
+2
-2
No files found.
app/controllers/projects/artifacts_controller.rb
View file @
7cee6139
...
...
@@ -92,7 +92,10 @@ class Projects::ArtifactsController < Projects::ApplicationController
def
build_from_ref
return
unless
@ref_name
project
.
latest_successful_build_for
(
params
[
:job
],
@ref_name
)
commit
=
project
.
commit
(
@ref_name
)
return
unless
commit
project
.
latest_successful_build_for_sha
(
params
[
:job
],
commit
.
id
)
end
def
artifacts_file
...
...
app/models/ci/pipeline.rb
View file @
7cee6139
...
...
@@ -230,9 +230,10 @@ module Ci
# ref - The name (or names) of the branch(es)/tag(s) to limit the list of
# pipelines to.
# limit - This limits a backlog search, default to 100.
def
self
.
newest_first
(
ref:
nil
,
limit:
100
)
def
self
.
newest_first
(
ref:
nil
,
sha:
nil
,
limit:
100
)
relation
=
order
(
id: :desc
)
relation
=
relation
.
where
(
ref:
ref
)
if
ref
relation
=
relation
.
where
(
sha:
sha
)
if
sha
if
limit
ids
=
relation
.
limit
(
limit
).
select
(
:id
)
...
...
@@ -252,6 +253,10 @@ module Ci
newest_first
(
ref:
ref
).
success
.
take
end
def
self
.
latest_successful_for_sha
(
sha
)
newest_first
(
sha:
sha
).
success
.
take
end
def
self
.
latest_successful_for_refs
(
refs
)
relation
=
newest_first
(
ref:
refs
).
success
...
...
app/models/project.rb
View file @
7cee6139
...
...
@@ -719,14 +719,25 @@ class Project < ApplicationRecord
repository
.
commits_by
(
oids:
oids
)
end
# ref can't be HEAD, can only be branch/tag name
or SHA
# ref can't be HEAD, can only be branch/tag name
def
latest_successful_build_for
(
job_name
,
ref
=
default_branch
)
return
unless
ref
latest_pipeline
=
ci_pipelines
.
latest_successful_for
(
ref
)
return
unless
latest_pipeline
latest_pipeline
.
builds
.
latest
.
with_artifacts_archive
.
find_by
(
name:
job_name
)
end
def
latest_successful_build_for_sha
(
job_name
,
sha
=
commit
(
default_branch
).
id
)
return
unless
sha
latest_pipeline
=
ci_pipelines
.
latest_successful_for_sha
(
sha
)
return
unless
latest_pipeline
latest_pipeline
.
builds
.
latest
.
with_artifacts_archive
.
find_by
(
name:
job_name
)
end
def
latest_successful_build_for!
(
job_name
,
ref
=
default_branch
)
latest_successful_build_for
(
job_name
,
ref
)
||
raise
(
ActiveRecord
::
RecordNotFound
.
new
(
"Couldn't find job
#{
job_name
}
"
))
end
...
...
spec/features/projects/artifacts/user_downloads_artifacts_spec.rb
View file @
7cee6139
require
"spec_helper"
describe
"User downloads artifacts"
do
set
(
:project
)
{
create
(
:project
,
:public
)
}
set
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status: :success
,
project:
project
)
}
set
(
:project
)
{
create
(
:project
,
:
repository
,
:
public
)
}
set
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status: :success
,
sha:
project
.
commit
.
id
,
project:
project
)
}
set
(
:job
)
{
create
(
:ci_build
,
:artifacts
,
:success
,
pipeline:
pipeline
)
}
shared_examples
"downloading"
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