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
9cdcc230
Commit
9cdcc230
authored
Nov 30, 2017
by
Francisco Javier López
Committed by
Douwe Maan
Nov 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `push` web hook events for pull mirroring
parent
1724b6a3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
175 additions
and
14 deletions
+175
-14
changelogs/unreleased-ee/fj-3821-push-web-hook-event.yml
changelogs/unreleased-ee/fj-3821-push-web-hook-event.yml
+5
-0
doc/api/projects.md
doc/api/projects.md
+12
-0
ee/app/controllers/projects/mirrors_controller.rb
ee/app/controllers/projects/mirrors_controller.rb
+1
-2
ee/app/helpers/ee/projects_helper.rb
ee/app/helpers/ee/projects_helper.rb
+0
-7
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+2
-0
ee/app/views/shared/_mirror_update_button.html.haml
ee/app/views/shared/_mirror_update_button.html.haml
+0
-5
lib/api/projects.rb
lib/api/projects.rb
+11
-0
spec/factories/projects.rb
spec/factories/projects.rb
+4
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+140
-0
No files found.
changelogs/unreleased-ee/fj-3821-push-web-hook-event.yml
0 → 100644
View file @
9cdcc230
---
title
:
Added enpoint that triggers the pull mirroring process
merge_request
:
3453
author
:
type
:
added
doc/api/projects.md
View file @
9cdcc230
...
...
@@ -1427,3 +1427,15 @@ Read more in the [Branches](branches.md) documentation.
## Project members
Read more in the
[
Project members
](
members.md
)
documentation.
## Start the pull mirroring process for a Project
> Introduced in GitLab 10.3. **Note:** Available in [GitLab Enterprise Edition Starter](https://about.gitlab.com/gitlab-ee).
```
POST /projects/:id/mirror/pull
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
|
ee/app/controllers/projects/mirrors_controller.rb
View file @
9cdcc230
...
...
@@ -2,8 +2,7 @@ class Projects::MirrorsController < Projects::ApplicationController
include
RepositorySettingsRedirect
include
SafeMirrorParams
# Authorize
before_action
:authorize_admin_project!
,
except:
[
:update_now
]
before_action
:authorize_push_code!
,
only:
[
:update_now
]
before_action
:authorize_admin_project!
before_action
:remote_mirror
,
only:
[
:update
]
before_action
:check_repository_mirrors_available!
...
...
ee/app/helpers/ee/projects_helper.rb
View file @
9cdcc230
module
EE
module
ProjectsHelper
def
can_force_update_mirror?
(
project
)
return
true
if
project
.
mirror_hard_failed?
return
true
unless
project
.
mirror_last_update_at
Time
.
now
-
project
.
mirror_last_update_at
>=
5
.
minutes
end
def
can_change_push_rule?
(
push_rule
,
rule
)
return
true
if
push_rule
.
global?
...
...
ee/app/models/ee/project.rb
View file @
9cdcc230
...
...
@@ -229,6 +229,8 @@ module EE
end
def
force_import_job!
return
if
scheduled_mirror?
||
updating_mirror?
mirror_data
=
self
.
mirror_data
mirror_data
.
set_next_execution_to_now
...
...
ee/app/views/shared/_mirror_update_button.html.haml
View file @
9cdcc230
...
...
@@ -8,11 +8,6 @@
%span
.btn.disabled
=
icon
(
"refresh spin"
)
Updating
…
-
elsif
!
can_force_update_mirror?
(
@project
)
%span
.btn.disabled
{
data:
{
toggle:
'tooltip'
,
placement:
'auto top'
},
style:
'cursor: default'
,
title:
'You can only force update once every five minutes.'
}
=
icon
(
"refresh"
)
Update Now
-
else
=
link_to
update_now_project_mirror_path
(
@project
),
method: :post
,
class:
'btn'
do
=
icon
(
"refresh"
)
...
...
lib/api/projects.rb
View file @
9cdcc230
...
...
@@ -477,6 +477,17 @@ module API
conflict!
(
error
.
message
)
end
end
desc
'Triggers a pull mirror operation'
post
":id/mirror/pull"
do
authorize_admin_project
return
render_api_error!
(
'The project is not mirrored'
,
400
)
unless
user_project
.
mirror?
user_project
.
force_import_job!
status
200
end
end
end
end
spec/factories/projects.rb
View file @
9cdcc230
...
...
@@ -61,6 +61,10 @@ FactoryGirl.define do
visibility_level
Gitlab
::
VisibilityLevel
::
PRIVATE
end
trait
:import_none
do
import_status
:none
end
trait
:import_scheduled
do
import_status
:scheduled
...
...
spec/requests/api/projects_spec.rb
View file @
9cdcc230
...
...
@@ -1932,6 +1932,146 @@ describe API::Projects do
end
end
describe
'POST /projects/:id/mirror/pull'
do
context
'when the project is not mirrored'
do
it
'returns error'
do
allow
(
project
).
to
receive
(
:mirror?
).
and_return
(
false
)
post
api
(
"/projects/
#{
project
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
context
'when the project is mirrored'
do
before
do
allow_any_instance_of
(
Projects
::
UpdateMirrorService
).
to
receive
(
:execute
).
and_return
(
status: :success
)
end
context
'when import state is'
do
def
project_in_state
(
state
)
project
=
create
(
:project
,
:repository
,
:mirror
,
state
,
namespace:
user
.
namespace
)
project
.
mirror_data
.
update_attributes
(
next_execution_timestamp:
10
.
minutes
.
from_now
)
project
end
it
'none it triggers the pull mirroring operation'
do
project
=
project_in_state
(
:import_none
)
expect
(
UpdateAllMirrorsWorker
).
to
receive
(
:perform_async
).
once
post
api
(
"/projects/
#{
project
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'failed it triggers the pull mirroring operation'
do
project
=
project_in_state
(
:import_failed
)
expect
(
UpdateAllMirrorsWorker
).
to
receive
(
:perform_async
).
once
post
api
(
"/projects/
#{
project
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'finished it triggers the pull mirroring operation'
do
project
=
project_in_state
(
:import_finished
)
expect
(
UpdateAllMirrorsWorker
).
to
receive
(
:perform_async
).
once
post
api
(
"/projects/
#{
project
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'scheduled does not trigger the pull mirroring operation and returns 200'
do
project
=
project_in_state
(
:import_scheduled
)
expect
(
UpdateAllMirrorsWorker
).
not_to
receive
(
:perform_async
)
post
api
(
"/projects/
#{
project
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'started does not trigger the pull mirroring operation and returns 200'
do
project
=
project_in_state
(
:import_started
)
expect
(
UpdateAllMirrorsWorker
).
not_to
receive
(
:perform_async
)
post
api
(
"/projects/
#{
project
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
context
'when user'
do
let
(
:project_mirrored
)
{
create
(
:project
,
:repository
,
:mirror
,
:import_finished
,
namespace:
user
.
namespace
)
}
def
project_member
(
role
,
user
)
create
(
:project_member
,
role
,
user:
user
,
project:
project_mirrored
)
end
context
'is unauthenticated'
do
it
'returns authentication error'
do
post
api
(
"/projects/
#{
project_mirrored
.
id
}
/mirror/pull"
)
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'is authenticated as developer'
do
it
'returns forbidden error'
do
project_member
(
:developer
,
user3
)
post
api
(
"/projects/
#{
project_mirrored
.
id
}
/mirror/pull"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'is authenticated as reporter'
do
it
'returns forbidden error'
do
project_member
(
:reporter
,
user3
)
post
api
(
"/projects/
#{
project_mirrored
.
id
}
/mirror/pull"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'is authenticated as guest'
do
it
'returns forbidden error'
do
project_member
(
:guest
,
user3
)
post
api
(
"/projects/
#{
project_mirrored
.
id
}
/mirror/pull"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'is authenticated as master'
do
it
'triggers the pull mirroring operation'
do
project_member
(
:master
,
user3
)
post
api
(
"/projects/
#{
project_mirrored
.
id
}
/mirror/pull"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
context
'is authenticated as owner'
do
it
'triggers the pull mirroring operation'
do
post
api
(
"/projects/
#{
project_mirrored
.
id
}
/mirror/pull"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
end
end
end
it_behaves_like
'custom attributes endpoints'
,
'projects'
do
let
(
:attributable
)
{
project
}
let
(
:other_attributable
)
{
project2
}
...
...
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