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
d2c83de2
Commit
d2c83de2
authored
Apr 07, 2020
by
Fabio Pitino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feedback from review
parent
0519ef27
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
50 deletions
+52
-50
ee/app/services/ci/external_pull_requests/process_github_event_service.rb
...ci/external_pull_requests/process_github_event_service.rb
+50
-0
ee/app/services/ci/process_github_pull_request_event_service.rb
.../services/ci/process_github_pull_request_event_service.rb
+0
-48
ee/lib/api/project_mirror.rb
ee/lib/api/project_mirror.rb
+1
-1
ee/spec/services/ci/external_pull_requests/process_github_event_service_spec.rb
...ternal_pull_requests/process_github_event_service_spec.rb
+1
-1
No files found.
ee/app/services/ci/external_pull_requests/process_github_event_service.rb
0 → 100644
View file @
d2c83de2
# frozen_string_literal: true
module
Ci
module
ExternalPullRequests
class
ProcessGithubEventService
<
::
BaseService
# All possible statuses available here:
# https://developer.github.com/v3/activity/events/types/#pullrequestevent
GITHUB_ACTIONS_TO_STATUS
=
{
'opened'
=>
:open
,
'reopened'
=>
:open
,
'synchronize'
=>
:open
,
'closed'
=>
:closed
}.
freeze
def
execute
(
webhook_params
)
return
unless
project
.
github_external_pull_request_pipelines_available?
params
=
params_from_webhook
(
webhook_params
)
return
unless
params
[
:status
]
# Save pull request info for later. when mirror update will run
# and the pipeline is created for all newly pushed branches.
# At that point we will be able to reference it back if a pull request
# was created.
::
ExternalPullRequest
.
create_or_update_from_params
(
params
).
tap
do
|
pull_request
|
if
pull_request
.
errors
.
empty?
Ci
::
ExternalPullRequests
::
CreatePipelineService
.
new
(
project
,
current_user
)
.
execute
(
pull_request
)
end
end
end
private
def
params_from_webhook
(
params
)
{
project_id:
project
.
id
,
pull_request_iid:
params
.
dig
(
:pull_request
,
:number
),
source_branch:
params
.
dig
(
:pull_request
,
:head
,
:ref
),
source_sha:
params
.
dig
(
:pull_request
,
:head
,
:sha
),
source_repository:
params
.
dig
(
:pull_request
,
:head
,
:repo
,
:full_name
),
target_branch:
params
.
dig
(
:pull_request
,
:base
,
:ref
),
target_sha:
params
.
dig
(
:pull_request
,
:base
,
:sha
),
target_repository:
params
.
dig
(
:pull_request
,
:base
,
:repo
,
:full_name
),
status:
GITHUB_ACTIONS_TO_STATUS
[
params
[
:action
]]
}
end
end
end
end
ee/app/services/ci/process_github_pull_request_event_service.rb
deleted
100644 → 0
View file @
0519ef27
# frozen_string_literal: true
module
Ci
class
ProcessGithubPullRequestEventService
<
::
BaseService
# All possible statuses available here:
# https://developer.github.com/v3/activity/events/types/#pullrequestevent
GITHUB_ACTIONS_TO_STATUS
=
{
'opened'
=>
:open
,
'reopened'
=>
:open
,
'synchronize'
=>
:open
,
'closed'
=>
:closed
}.
freeze
def
execute
(
webhook_params
)
return
unless
project
.
github_external_pull_request_pipelines_available?
params
=
params_from_webhook
(
webhook_params
)
return
unless
params
[
:status
]
# Save pull request info for later. when mirror update will run
# and the pipeline is created for all newly pushed branches.
# At that point we will be able to reference it back if a pull request
# was created.
::
ExternalPullRequest
.
create_or_update_from_params
(
params
).
tap
do
|
pull_request
|
if
pull_request
.
errors
.
empty?
Ci
::
ExternalPullRequests
::
CreatePipelineService
.
new
(
project
,
current_user
)
.
execute
(
pull_request
)
end
end
end
private
def
params_from_webhook
(
params
)
{
project_id:
project
.
id
,
pull_request_iid:
params
.
dig
(
:pull_request
,
:number
),
source_branch:
params
.
dig
(
:pull_request
,
:head
,
:ref
),
source_sha:
params
.
dig
(
:pull_request
,
:head
,
:sha
),
source_repository:
params
.
dig
(
:pull_request
,
:head
,
:repo
,
:full_name
),
target_branch:
params
.
dig
(
:pull_request
,
:base
,
:ref
),
target_sha:
params
.
dig
(
:pull_request
,
:base
,
:sha
),
target_repository:
params
.
dig
(
:pull_request
,
:base
,
:repo
,
:full_name
),
status:
GITHUB_ACTIONS_TO_STATUS
[
params
[
:action
]]
}
end
end
end
ee/lib/api/project_mirror.rb
View file @
d2c83de2
...
...
@@ -49,7 +49,7 @@ module API
end
def
process_pull_request
external_pull_request
=
Ci
::
ProcessGithubPullRequest
EventService
.
new
(
project
,
mirror_user
).
execute
(
params
)
external_pull_request
=
Ci
::
ExternalPullRequests
::
ProcessGithub
EventService
.
new
(
project
,
mirror_user
).
execute
(
params
)
if
external_pull_request
render_validation_error!
(
external_pull_request
)
...
...
ee/spec/services/ci/
process_github_pull_request
_event_service_spec.rb
→
ee/spec/services/ci/
external_pull_requests/process_github
_event_service_spec.rb
View file @
d2c83de2
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
Ci
::
ProcessGithubPullRequest
EventService
do
describe
Ci
::
ExternalPullRequests
::
ProcessGithub
EventService
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:action
)
{
'opened'
}
...
...
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