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
f09eeae2
Commit
f09eeae2
authored
Aug 24, 2020
by
Fabian Schneider
Committed by
Grzegorz Bizon
Aug 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ignore_skipped option for pipeline status badge
parent
25f85807
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
6 deletions
+71
-6
app/controllers/projects/badges_controller.rb
app/controllers/projects/badges_controller.rb
+1
-0
changelogs/unreleased/15304-skipped-pipeline-status-badge.yml
...gelogs/unreleased/15304-skipped-pipeline-status-badge.yml
+5
-0
doc/ci/pipelines/settings.md
doc/ci/pipelines/settings.md
+8
-0
lib/gitlab/badge/pipeline/status.rb
lib/gitlab/badge/pipeline/status.rb
+5
-2
spec/controllers/projects/badges_controller_spec.rb
spec/controllers/projects/badges_controller_spec.rb
+24
-4
spec/lib/gitlab/badge/pipeline/status_spec.rb
spec/lib/gitlab/badge/pipeline/status_spec.rb
+28
-0
No files found.
app/controllers/projects/badges_controller.rb
View file @
f09eeae2
...
...
@@ -9,6 +9,7 @@ class Projects::BadgesController < Projects::ApplicationController
def
pipeline
pipeline_status
=
Gitlab
::
Badge
::
Pipeline
::
Status
.
new
(
project
,
params
[
:ref
],
opts:
{
ignore_skipped:
params
[
:ignore_skipped
],
key_text:
params
[
:key_text
],
key_width:
params
[
:key_width
]
})
...
...
changelogs/unreleased/15304-skipped-pipeline-status-badge.yml
0 → 100644
View file @
f09eeae2
---
title
:
Add ignore_skipped option for pipeline status badge
merge_request
:
28288
author
:
Fabian Schneider @fabsrc
type
:
added
doc/ci/pipelines/settings.md
View file @
f09eeae2
...
...
@@ -266,6 +266,14 @@ You can access a pipeline status badge image using the following link:
https://gitlab.example.com/<namespace>/<project>/badges/<branch>/pipeline.svg
```
#### Display only non-skipped status
If you want the pipeline status badge to only display the last non-skipped status, you can use the
`?ignore_skipped=true`
query parameter:
```
plaintext
https://example.gitlab.com/<namespace>/<project>/badges/<branch>/pipeline.svg?ignore_skipped=true
```
### Test coverage report badge
GitLab makes it possible to define the regular expression for
[
coverage report
](
#test-coverage-parsing
)
,
...
...
lib/gitlab/badge/pipeline/status.rb
View file @
f09eeae2
...
...
@@ -12,6 +12,7 @@ module Gitlab
def
initialize
(
project
,
ref
,
opts:
{})
@project
=
project
@ref
=
ref
@ignore_skipped
=
Gitlab
::
Utils
.
to_boolean
(
opts
[
:ignore_skipped
],
default:
false
)
@customization
=
{
key_width:
opts
[
:key_width
].
to_i
,
key_text:
opts
[
:key_text
]
...
...
@@ -26,9 +27,11 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def
status
@project
.
ci_pipelines
pipelines
=
@project
.
ci_pipelines
.
where
(
sha:
@sha
)
.
latest_status
(
@ref
)
||
'unknown'
relation
=
@ignore_skipped
?
pipelines
.
without_statuses
([
:skipped
])
:
pipelines
relation
.
latest_status
(
@ref
)
||
'unknown'
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
spec/controllers/projects/badges_controller_spec.rb
View file @
f09eeae2
...
...
@@ -3,9 +3,9 @@
require
'spec_helper'
RSpec
.
describe
Projects
::
BadgesController
do
let
(
:project
)
{
pipeline
.
project
}
let
!
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:repository
)
}
let
_it_be
(
:pipeline
,
reload:
true
)
{
create
(
:ci_empty_pipeline
,
project:
project
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
shared_examples
'a badge resource'
do
|
badge_type
|
context
'when pipelines are public'
do
...
...
@@ -137,6 +137,26 @@ RSpec.describe Projects::BadgesController do
describe
'#pipeline'
do
it_behaves_like
'a badge resource'
,
:pipeline
context
'with ignore_skipped param'
do
render_views
before
do
pipeline
.
update!
(
status: :skipped
)
project
.
add_maintainer
(
user
)
sign_in
(
user
)
end
it
'returns skipped badge if set to false'
do
get_badge
(
:pipeline
,
ignore_skipped:
false
)
expect
(
response
.
body
).
to
include
(
'skipped'
)
end
it
'does not return skipped badge if set to true'
do
get_badge
(
:pipeline
,
ignore_skipped:
true
)
expect
(
response
.
body
).
to
include
(
'unknown'
)
end
end
end
describe
'#coverage'
do
...
...
@@ -148,7 +168,7 @@ RSpec.describe Projects::BadgesController do
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
ref:
pipeline
.
ref
}.
merge
(
args
.
slice
(
:style
,
:key_text
,
:key_width
))
}.
merge
(
args
.
slice
(
:style
,
:key_text
,
:key_width
,
:ignore_skipped
))
get
badge
,
params:
params
,
format: :svg
end
...
...
spec/lib/gitlab/badge/pipeline/status_spec.rb
View file @
f09eeae2
...
...
@@ -78,6 +78,34 @@ RSpec.describe Gitlab::Badge::Pipeline::Status do
expect
(
badge
.
status
).
to
eq
'success'
end
end
context
'when ignored_skipped is set to true'
do
let
(
:new_badge
)
{
described_class
.
new
(
project
,
branch
,
opts:
{
ignore_skipped:
true
})
}
before
do
pipeline
.
skip!
end
describe
'#status'
do
it
'uses latest non-skipped status'
do
expect
(
new_badge
.
status
).
not_to
eq
'skipped'
end
end
end
context
'when ignored_skipped is set to false'
do
let
(
:new_badge
)
{
described_class
.
new
(
project
,
branch
,
opts:
{
ignore_skipped:
false
})
}
before
do
pipeline
.
skip!
end
describe
'#status'
do
it
'uses latest status'
do
expect
(
new_badge
.
status
).
to
eq
'skipped'
end
end
end
end
context
'build does not exist'
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