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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
4e4ca27a
Commit
4e4ca27a
authored
Aug 10, 2016
by
Egor Lynko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ability to specify branches for pivotal tracker integration
parent
30f5b9a5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
6 deletions
+101
-6
CHANGELOG
CHANGELOG
+1
-0
app/models/project_services/pivotaltracker_service.rb
app/models/project_services/pivotaltracker_service.rb
+27
-4
doc/api/services.md
doc/api/services.md
+2
-2
spec/models/project_services/pivotaltracker_service_spec.rb
spec/models/project_services/pivotaltracker_service_spec.rb
+71
-0
No files found.
CHANGELOG
View file @
4e4ca27a
...
...
@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.11.0 (unreleased)
- Remove the http_parser.rb dependency by removing the tinder gem. !5758 (tbalthazar)
- Ability to specify branches for Pivotal Tracker integration (Egor Lynko)
- Fix don't pass a local variable called `i` to a partial. !20510 (herminiotorres)
- Fix rename `add_users_into_project` and `projects_ids`. !20512 (herminiotorres)
- Fix the title of the toggle dropdown button. !5515 (herminiotorres)
...
...
app/models/project_services/pivotaltracker_service.rb
View file @
4e4ca27a
class
PivotaltrackerService
<
Service
include
HTTParty
prop_accessor
:token
API_ENDPOINT
=
'https://www.pivotaltracker.com/services/v5/source_commits'
prop_accessor
:token
,
:restrict_to_branch
validates
:token
,
presence:
true
,
if: :activated?
def
title
...
...
@@ -18,7 +20,17 @@ class PivotaltrackerService < Service
def
fields
[
{
type:
'text'
,
name:
'token'
,
placeholder:
''
}
{
type:
'text'
,
name:
'token'
,
placeholder:
'Pivotal Tracker API token.'
},
{
type:
'text'
,
name:
'restrict_to_branch'
,
placeholder:
'Comma-separated list of branches which will be '
\
'automatically inspected. Leave blank to include all branches.'
}
]
end
...
...
@@ -28,8 +40,8 @@ class PivotaltrackerService < Service
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
allowed_branch?
(
data
[
:ref
])
url
=
'https://www.pivotaltracker.com/services/v5/source_commits'
data
[
:commits
].
each
do
|
commit
|
message
=
{
'source_commit'
=>
{
...
...
@@ -40,7 +52,7 @@ class PivotaltrackerService < Service
}
}
PivotaltrackerService
.
post
(
url
,
API_ENDPOINT
,
body:
message
.
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
,
...
...
@@ -49,4 +61,15 @@ class PivotaltrackerService < Service
)
end
end
private
def
allowed_branch?
(
ref
)
return
true
unless
ref
.
present?
&&
restrict_to_branch
.
present?
branch
=
Gitlab
::
Git
.
ref_name
(
ref
)
allowed_branches
=
restrict_to_branch
.
split
(
','
).
map
(
&
:strip
)
branch
.
present?
&&
allowed_branches
.
include?
(
branch
)
end
end
doc/api/services.md
View file @
4e4ca27a
...
...
@@ -355,7 +355,7 @@ PUT /projects/:id/services/gemnasium
Parameters:
-
`api_key`
(
**required**
) - Your personal API KEY on gemnasium.com
-
`api_key`
(
**required**
) - Your personal API KEY on gemnasium.com
-
`token`
(
**required**
) - The project's slug on gemnasium.com
### Delete Gemnasium service
...
...
@@ -503,6 +503,7 @@ PUT /projects/:id/services/pivotaltracker
Parameters:
-
`token`
(
**required**
)
-
`restrict_to_branch`
(optional) - Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches.
### Delete PivotalTracker service
...
...
@@ -661,4 +662,3 @@ Get JetBrains TeamCity CI service settings for a project.
```
GET /projects/:id/services/teamcity
```
spec/models/project_services/pivotaltracker_service_spec.rb
View file @
4e4ca27a
...
...
@@ -39,4 +39,75 @@ describe PivotaltrackerService, models: true do
it
{
is_expected
.
not_to
validate_presence_of
(
:token
)
}
end
end
describe
'Execute'
do
let
(
:service
)
do
PivotaltrackerService
.
new
.
tap
do
|
service
|
service
.
token
=
'secret_api_token'
end
end
let
(
:url
)
{
PivotaltrackerService
::
API_ENDPOINT
}
def
push_data
(
branch:
'master'
)
{
object_kind:
'push'
,
ref:
"refs/heads/
#{
branch
}
"
,
commits:
[
{
id:
'21c12ea'
,
author:
{
name:
'Some User'
},
url:
'https://example.com/commit'
,
message:
'commit message'
,
}
]
}
end
before
do
WebMock
.
stub_request
(
:post
,
url
)
end
it
'should post correct message'
do
service
.
execute
(
push_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
url
).
with
(
body:
{
'source_commit'
=>
{
'commit_id'
=>
'21c12ea'
,
'author'
=>
'Some User'
,
'url'
=>
'https://example.com/commit'
,
'message'
=>
'commit message'
}
},
headers:
{
'Content-Type'
=>
'application/json'
,
'X-TrackerToken'
=>
'secret_api_token'
}
).
once
end
context
'when allowed branches is specified'
do
let
(
:service
)
do
super
().
tap
do
|
service
|
service
.
restrict_to_branch
=
'master,v10'
end
end
it
'should post message if branch is in the list'
do
service
.
execute
(
push_data
(
branch:
'master'
))
service
.
execute
(
push_data
(
branch:
'v10'
))
expect
(
WebMock
).
to
have_requested
(
:post
,
url
).
twice
end
it
'should not post message if branch is not in the list'
do
service
.
execute
(
push_data
(
branch:
'mas'
))
service
.
execute
(
push_data
(
branch:
'v11'
))
expect
(
WebMock
).
not_to
have_requested
(
:post
,
url
)
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