Skip to content

Commit 3ce6ba7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into show-commit-status-from-latest-pipeline
* upstream/master: (39 commits) Improve build status specs contexts descriptions Add some missing tests for detailed status methods Remove trailing blank line from Allowable module Update manual build icon SVG Make it possible to mix `Gitlab::Routing` in Extract abilities checking module from ability model Extend tests for pipeline detailed status helpers Add tests for common build detailed status helpers Add missing tests for build `cancelable?` method Add tests for detailed build statuses factory Make it possible to retry build that was canceled Make build retryable only if complete and executed Improve readability in methods for detailed status Add tests for build cancelable/retryable statuses Extend specs for build play/stop detailed statuses Refine build stop/play extended status specs Use manual build icon in play/stop build statuses Adds manual action icon and case to show it Fix detailed status specs for pipeline stage model Fix detailed status badge for generic commit status ...
2 parents 367024f + 3e90aa1 commit 3ce6ba7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1125
-170
lines changed

app/helpers/ci_status_helper.rb

+1-19
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,7 @@ def ci_status_path(pipeline)
44
builds_namespace_project_commit_path(project.namespace, project, pipeline.sha)
55
end
66

7-
def ci_status_with_icon(status, target = nil)
8-
content = ci_icon_for_status(status) + ci_text_for_status(status)
9-
klass = "ci-status ci-#{status}"
10-
11-
if target
12-
link_to content, target, class: klass
13-
else
14-
content_tag :span, content, class: klass
15-
end
16-
end
17-
18-
def ci_text_for_status(status)
19-
if detailed_status?(status)
20-
status.text
21-
else
22-
status
23-
end
24-
end
25-
7+
# Is used by Commit and Merge Request Widget
268
def ci_label_for_status(status)
279
if detailed_status?(status)
2810
return status.label

app/models/ci/build.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ def retry(build, user = nil)
100100
end
101101
end
102102

103+
def detailed_status(current_user)
104+
Gitlab::Ci::Status::Build::Factory
105+
.new(self, current_user)
106+
.fabricate!
107+
end
108+
103109
def manual?
104110
self.when == 'manual'
105111
end
@@ -123,8 +129,13 @@ def play(current_user = nil)
123129
end
124130
end
125131

132+
def cancelable?
133+
active?
134+
end
135+
126136
def retryable?
127-
project.builds_enabled? && commands.present? && complete?
137+
project.builds_enabled? && commands.present? &&
138+
(success? || failed? || canceled?)
128139
end
129140

130141
def retried?
@@ -148,7 +159,7 @@ def stops_environment?
148159
end
149160

150161
def environment_action
151-
self.options.fetch(:environment, {}).fetch(:action, 'start')
162+
self.options.fetch(:environment, {}).fetch(:action, 'start') if self.options
152163
end
153164

154165
def outdated_deployment?

app/models/ci/pipeline.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,10 @@ def merge_requests
346346
.select { |merge_request| merge_request.head_pipeline.try(:id) == self.id }
347347
end
348348

349-
def detailed_status
350-
Gitlab::Ci::Status::Pipeline::Factory.new(self).fabricate!
349+
def detailed_status(current_user)
350+
Gitlab::Ci::Status::Pipeline::Factory
351+
.new(self, current_user)
352+
.fabricate!
351353
end
352354

353355
private

app/models/ci/stage.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ def status
2222
@status ||= statuses.latest.status
2323
end
2424

25-
def detailed_status
26-
Gitlab::Ci::Status::Stage::Factory.new(self).fabricate!
25+
def detailed_status(current_user)
26+
Gitlab::Ci::Status::Stage::Factory
27+
.new(self, current_user)
28+
.fabricate!
2729
end
2830

2931
def statuses

app/models/commit_status.rb

+6
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ def stuck?
131131
def has_trace?
132132
false
133133
end
134+
135+
def detailed_status(current_user)
136+
Gitlab::Ci::Status::Factory
137+
.new(self, current_user)
138+
.fabricate!
139+
end
134140
end

app/views/admin/runners/show.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
%strong ##{build.id}
9292

9393
%td.status
94-
= ci_status_with_icon(build.status)
94+
= render 'ci/status/badge', status: build.detailed_status(current_user)
9595

9696
%td.status
9797
- if project

app/views/ci/status/_badge.html.haml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- status = local_assigns.fetch(:status)
2+
3+
- if status.has_details?
4+
= link_to status.details_path, class: "ci-status ci-#{status}" do
5+
= custom_icon(status.icon)
6+
= status.text
7+
- else
8+
%span{ class: "ci-status ci-#{status}" }
9+
= custom_icon(status.icon)
10+
= status.text

app/views/projects/builds/_header.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.content-block.build-header
22
.header-content
3-
= ci_status_with_icon(@build.status)
3+
= render 'ci/status/badge', status: @build.detailed_status(current_user)
44
Build
55
%strong ##{@build.id}
66
in pipeline

app/views/projects/ci/builds/_build.html.haml

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
%tr.build.commit{class: ('retried' if retried)}
1111
%td.status
12-
- if can?(current_user, :read_build, build)
13-
= ci_status_with_icon(build.status, namespace_project_build_url(http://github.com/build.project.namespace,%20build.project,%20build))
14-
- else
15-
= ci_status_with_icon(build.status)
12+
= render "ci/status/badge", status: build.detailed_status(current_user)
1613

1714
%td.branch-commit
1815
- if can?(current_user, :read_build, build)

app/views/projects/ci/pipelines/_pipeline.html.haml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
- status = pipeline.status
2-
- detailed_status = pipeline.detailed_status
32
- show_commit = local_assigns.fetch(:show_commit, true)
43
- show_branch = local_assigns.fetch(:show_branch, true)
54

65
%tr.commit
76
%td.commit-link
8-
= link_to namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id), class: "ci-status ci-#{detailed_status}" do
9-
= ci_icon_for_status(detailed_status)
10-
= ci_text_for_status(detailed_status)
7+
= render 'ci/status/badge', status: pipeline.detailed_status(current_user)
118

129
%td
1310
= link_to namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id) do

app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
%tr.generic_commit_status{class: ('retried' if retried)}
1010
%td.status
11-
- if can?(current_user, :read_commit_status, generic_commit_status) && generic_commit_status.target_url
12-
= ci_status_with_icon(generic_commit_status.status, generic_commit_status.target_url)
13-
- else
14-
= ci_status_with_icon(generic_commit_status.status)
11+
= render 'ci/status/badge', status: generic_commit_status.detailed_status(current_user)
1512

1613
%td.generic_commit_status-link
1714
- if can?(current_user, :read_commit_status, generic_commit_status) && generic_commit_status.target_url

app/views/projects/pipelines/_info.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.page-content-header
22
.header-main-content
3-
= ci_status_with_icon(@pipeline.detailed_status)
3+
= render 'ci/status/badge', status: @pipeline.detailed_status(current_user)
44
%strong Pipeline ##{@commit.pipelines.last.id}
55
triggered #{time_ago_with_tooltip(@commit.authored_date)} by
66
= author_avatar(@commit, size: 24)

app/views/projects/stage/_graph.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
%li.build
2020
.curve
2121
.dropdown.inline.build-content
22-
= render "projects/stage/in_stage_group", name: group_name, subject: grouped_statuses
22+
= render 'projects/stage/in_stage_group', name: group_name, subject: grouped_statuses
Loading

lib/gitlab/allowable.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Gitlab
2+
module Allowable
3+
def can?(user, action, subject)
4+
Ability.allowed?(user, action, subject)
5+
end
6+
end
7+
end
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Gitlab
2+
module Ci
3+
module Status
4+
module Build
5+
class Cancelable < SimpleDelegator
6+
include Status::Extended
7+
8+
def has_action?
9+
can?(user, :update_build, subject)
10+
end
11+
12+
def action_icon
13+
'ban'
14+
end
15+
16+
def action_path
17+
cancel_namespace_project_build_path(subject.project.namespace,
18+
subject.project,
19+
subject)
20+
end
21+
22+
def action_method
23+
:post
24+
end
25+
26+
def action_title
27+
'Cancel'
28+
end
29+
30+
def self.matches?(build, user)
31+
build.cancelable?
32+
end
33+
end
34+
end
35+
end
36+
end
37+
end

lib/gitlab/ci/status/build/common.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Gitlab
2+
module Ci
3+
module Status
4+
module Build
5+
module Common
6+
def has_details?
7+
can?(user, :read_build, subject)
8+
end
9+
10+
def details_path
11+
namespace_project_build_path(subject.project.namespace,
12+
subject.project,
13+
subject)
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end

lib/gitlab/ci/status/build/factory.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Gitlab
2+
module Ci
3+
module Status
4+
module Build
5+
class Factory < Status::Factory
6+
def self.extended_statuses
7+
[Status::Build::Stop, Status::Build::Play,
8+
Status::Build::Cancelable, Status::Build::Retryable]
9+
end
10+
11+
def self.common_helpers
12+
Status::Build::Common
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end

lib/gitlab/ci/status/build/play.rb

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Gitlab
2+
module Ci
3+
module Status
4+
module Build
5+
class Play < SimpleDelegator
6+
include Status::Extended
7+
8+
def text
9+
'manual'
10+
end
11+
12+
def label
13+
'manual play action'
14+
end
15+
16+
def icon
17+
'icon_status_manual'
18+
end
19+
20+
def has_action?
21+
can?(user, :update_build, subject)
22+
end
23+
24+
def action_icon
25+
'play'
26+
end
27+
28+
def action_title
29+
'Play'
30+
end
31+
32+
def action_class
33+
'ci-play-icon'
34+
end
35+
36+
def action_path
37+
play_namespace_project_build_path(subject.project.namespace,
38+
subject.project,
39+
subject)
40+
end
41+
42+
def action_method
43+
:post
44+
end
45+
46+
def self.matches?(build, user)
47+
build.playable? && !build.stops_environment?
48+
end
49+
end
50+
end
51+
end
52+
end
53+
end
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Gitlab
2+
module Ci
3+
module Status
4+
module Build
5+
class Retryable < SimpleDelegator
6+
include Status::Extended
7+
8+
def has_action?
9+
can?(user, :update_build, subject)
10+
end
11+
12+
def action_icon
13+
'refresh'
14+
end
15+
16+
def action_title
17+
'Retry'
18+
end
19+
20+
def action_path
21+
retry_namespace_project_build_path(subject.project.namespace,
22+
subject.project,
23+
subject)
24+
end
25+
26+
def action_method
27+
:post
28+
end
29+
30+
def self.matches?(build, user)
31+
build.retryable?
32+
end
33+
end
34+
end
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)