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
f324bb20
Commit
f324bb20
authored
Nov 06, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support ref-scope / static host name GitHub status contexts
parent
52c187e5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
14 deletions
+67
-14
ee/app/models/project_services/github_service.rb
ee/app/models/project_services/github_service.rb
+1
-1
ee/app/models/project_services/github_service/status_message.rb
.../models/project_services/github_service/status_message.rb
+9
-4
ee/spec/models/project_services/github_service/status_message_spec.rb
...ls/project_services/github_service/status_message_spec.rb
+57
-9
No files found.
ee/app/models/project_services/github_service.rb
View file @
f324bb20
...
@@ -64,7 +64,7 @@ class GithubService < Service
...
@@ -64,7 +64,7 @@ class GithubService < Service
def
execute
(
data
)
def
execute
(
data
)
return
if
disabled?
return
if
disabled?
status_message
=
StatusMessage
.
from_pipeline_data
(
project
,
data
)
status_message
=
StatusMessage
.
from_pipeline_data
(
project
,
self
,
data
)
update_status
(
status_message
)
update_status
(
status_message
)
end
end
...
...
ee/app/models/project_services/github_service/status_message.rb
View file @
f324bb20
...
@@ -4,8 +4,9 @@ class GithubService
...
@@ -4,8 +4,9 @@ class GithubService
attr_reader
:sha
attr_reader
:sha
def
initialize
(
project
,
params
)
def
initialize
(
project
,
service
,
params
)
@project
=
project
@project
=
project
@service
=
service
@gitlab_status
=
params
[
:status
]
@gitlab_status
=
params
[
:status
]
@detailed_status
=
params
[
:detailed_status
]
@detailed_status
=
params
[
:detailed_status
]
@pipeline_id
=
params
[
:id
]
@pipeline_id
=
params
[
:id
]
...
@@ -14,7 +15,11 @@ class GithubService
...
@@ -14,7 +15,11 @@ class GithubService
end
end
def
context
def
context
"ci/gitlab"
if
@service
.
static_context?
"ci/gitlab/
#{
::
Gitlab
.
config
.
gitlab
.
host
}
"
else
"ci/gitlab/
#{
@ref_name
}
"
.
truncate
(
255
)
end
end
end
def
description
def
description
...
@@ -50,8 +55,8 @@ class GithubService
...
@@ -50,8 +55,8 @@ class GithubService
}
}
end
end
def
self
.
from_pipeline_data
(
project
,
data
)
def
self
.
from_pipeline_data
(
project
,
service
,
data
)
new
(
project
,
data
[
:object_attributes
])
new
(
project
,
service
,
data
[
:object_attributes
])
end
end
end
end
end
end
ee/spec/models/project_services/github_service/status_message_spec.rb
View file @
f324bb20
...
@@ -4,17 +4,22 @@ describe GithubService::StatusMessage do
...
@@ -4,17 +4,22 @@ describe GithubService::StatusMessage do
include
Rails
.
application
.
routes
.
url_helpers
include
Rails
.
application
.
routes
.
url_helpers
let
(
:project
)
{
double
(
:project
,
namespace:
"me"
,
to_s:
'example_project'
)
}
let
(
:project
)
{
double
(
:project
,
namespace:
"me"
,
to_s:
'example_project'
)
}
let
(
:service
)
{
double
(
:service
,
:static_context?
=>
false
)
}
before
do
stub_config_setting
(
host:
'instance-host'
)
end
describe
'#description'
do
describe
'#description'
do
it
'includes human readable gitlab status'
do
it
'includes human readable gitlab status'
do
subject
=
described_class
.
new
(
project
,
detailed_status:
'passed'
)
subject
=
described_class
.
new
(
project
,
service
,
detailed_status:
'passed'
)
expect
(
subject
.
description
).
to
eq
"Pipeline passed on GitLab"
expect
(
subject
.
description
).
to
eq
"Pipeline passed on GitLab"
end
end
it
'gets truncated to 140 chars'
do
it
'gets truncated to 140 chars'
do
dummy_text
=
'a'
*
500
dummy_text
=
'a'
*
500
subject
=
described_class
.
new
(
project
,
detailed_status:
dummy_text
)
subject
=
described_class
.
new
(
project
,
service
,
detailed_status:
dummy_text
)
expect
(
subject
.
description
.
length
).
to
eq
140
expect
(
subject
.
description
.
length
).
to
eq
140
end
end
...
@@ -36,7 +41,7 @@ describe GithubService::StatusMessage do
...
@@ -36,7 +41,7 @@ describe GithubService::StatusMessage do
with_them
do
with_them
do
it
'transforms status'
do
it
'transforms status'
do
subject
=
described_class
.
new
(
project
,
status:
gitlab_status
)
subject
=
described_class
.
new
(
project
,
s
ervice
,
s
tatus:
gitlab_status
)
expect
(
subject
.
status
).
to
eq
github_status
expect
(
subject
.
status
).
to
eq
github_status
end
end
...
@@ -44,7 +49,7 @@ describe GithubService::StatusMessage do
...
@@ -44,7 +49,7 @@ describe GithubService::StatusMessage do
end
end
describe
'#status_options'
do
describe
'#status_options'
do
let
(
:subject
)
{
described_class
.
new
(
project
,
id:
1
)
}
let
(
:subject
)
{
described_class
.
new
(
project
,
service
,
id:
1
)
}
it
'includes context'
do
it
'includes context'
do
expect
(
subject
.
status_options
[
:context
]).
to
be_a
String
expect
(
subject
.
status_options
[
:context
]).
to
be_a
String
...
@@ -59,11 +64,40 @@ describe GithubService::StatusMessage do
...
@@ -59,11 +64,40 @@ describe GithubService::StatusMessage do
end
end
end
end
describe
'#context'
do
subject
do
described_class
.
new
(
project
,
service
,
ref:
'some-ref'
)
end
context
'when status context is supposed to be dynamic'
do
before
do
allow
(
service
).
to
receive
(
:static_context?
).
and_return
(
false
)
end
it
'appends pipeline reference to the status context'
do
expect
(
subject
.
context
).
to
eq
'ci/gitlab/some-ref'
end
end
context
'when status context is supposed to be static'
do
before
do
allow
(
service
).
to
receive
(
:static_context?
).
and_return
(
true
)
end
it
'appends instance hostname to the status context'
do
expect
(
subject
.
context
).
to
eq
'ci/gitlab/instance-host'
end
end
end
describe
'.from_pipeline_data'
do
describe
'.from_pipeline_data'
do
let
(
:p
ipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:p
roject
)
{
create
(
:project
)
}
let
(
:p
roject
)
{
pipeline
.
project
}
let
(
:p
ipeline
)
{
create
(
:ci_pipeline
,
ref:
'some-ref'
,
project:
project
)
}
let
(
:sample_data
)
{
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
}
let
(
:sample_data
)
{
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
}
let
(
:subject
)
{
described_class
.
from_pipeline_data
(
project
,
sample_data
)
}
subject
do
described_class
.
from_pipeline_data
(
project
,
service
,
sample_data
)
end
it
'builds an instance of GithubService::StatusMessage'
do
it
'builds an instance of GithubService::StatusMessage'
do
expect
(
subject
).
to
be_a
described_class
expect
(
subject
).
to
be_a
described_class
...
@@ -87,16 +121,30 @@ describe GithubService::StatusMessage do
...
@@ -87,16 +121,30 @@ describe GithubService::StatusMessage do
end
end
specify
'context'
do
specify
'context'
do
expect
(
subject
.
context
).
to
eq
"ci/gitlab"
expect
(
subject
.
context
).
to
eq
"ci/gitlab
/some-ref
"
end
end
context
'
blocked pipeline
'
do
context
'
when pipeline is blocked
'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:blocked
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:blocked
)
}
it
'uses human readable status which can be used in a sentence'
do
it
'uses human readable status which can be used in a sentence'
do
expect
(
subject
.
description
).
to
eq
'Pipeline waiting for manual action on GitLab'
expect
(
subject
.
description
).
to
eq
'Pipeline waiting for manual action on GitLab'
end
end
end
end
context
'when static context has been configured'
do
before
do
allow
(
service
).
to
receive
(
:static_context?
).
and_return
(
true
)
end
subject
do
described_class
.
from_pipeline_data
(
project
,
service
,
sample_data
)
end
it
'appends instance name to the context name'
do
expect
(
subject
.
context
).
to
eq
'ci/gitlab/instance-host'
end
end
end
end
end
end
end
end
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