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
7e115252
Commit
7e115252
authored
Dec 29, 2016
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'grapify-push-rules' into 'master'
Grapify the push rules API See merge request !1005
parents
daced567
497af21c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
49 deletions
+41
-49
lib/api/project_push_rule.rb
lib/api/project_push_rule.rb
+40
-48
spec/requests/api/project_push_rule_spec.rb
spec/requests/api/project_push_rule_spec.rb
+1
-1
No files found.
lib/api/project_push_rule.rb
View file @
7e115252
...
@@ -4,72 +4,64 @@ module API
...
@@ -4,72 +4,64 @@ module API
before
{
authenticate!
}
before
{
authenticate!
}
before
{
authorize_admin_project
}
before
{
authorize_admin_project
}
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
# Get project push rule
helpers
do
#
params
:push_rule_params
do
# Parameters:
optional
:commit_message_regex
,
type:
String
,
desc:
'The commit message regex'
# id (required) - The ID of a project
optional
:deny_delete_tag
,
type:
Boolean
,
desc:
'Deny deleting a tag'
# Example Request:
at_least_one_of
:commit_message_regex
,
:deny_delete_tag
# GET /projects/:id/push_rule
end
end
desc
'Get project push rule'
do
success
Entities
::
ProjectPushRule
end
get
":id/push_rule"
do
get
":id/push_rule"
do
@
push_rule
=
user_project
.
push_rule
push_rule
=
user_project
.
push_rule
present
@
push_rule
,
with:
Entities
::
ProjectPushRule
present
push_rule
,
with:
Entities
::
ProjectPushRule
end
end
# Add push rule to project
desc
'Add a push rule to a project'
do
#
success
Entities
::
ProjectPushRule
# Parameters:
end
# id (required) - The ID of a project
params
do
# Example Request:
use
:push_rule_params
# POST /projects/:id/push_rule
end
post
":id/push_rule"
do
post
":id/push_rule"
do
attrs
=
attributes_for_keys
[
:commit_message_regex
,
:deny_delete_tag
]
if
user_project
.
push_rule
if
user_project
.
push_rule
error!
(
"Project push rule exists"
,
422
)
error!
(
"Project push rule exists"
,
422
)
else
else
@push_rule
=
user_project
.
create_push_rule
(
attr
s
)
push_rule
=
user_project
.
create_push_rule
(
declared_param
s
)
present
@
push_rule
,
with:
Entities
::
ProjectPushRule
present
push_rule
,
with:
Entities
::
ProjectPushRule
end
end
end
end
# Update an existing project push rule
desc
'Update an existing project push rule'
do
#
success
Entities
::
ProjectPushRule
# Parameters:
end
# id (required) - The ID of a project
params
do
# Example Request:
use
:push_rule_params
# PUT /projects/:id/push_rule
end
put
":id/push_rule"
do
put
":id/push_rule"
do
@push_rule
=
user_project
.
push_rule
push_rule
=
user_project
.
push_rule
not_found!
(
'Push Rule'
)
unless
push_rule
attrs
=
attributes_for_keys
[
:commit_message_regex
,
:deny_delete_tag
]
if
@push_rule
&&
@push_rule
.
update_attributes
(
attrs
)
if
push_rule
.
update_attributes
(
declared_params
(
include_missing:
false
)
)
present
@
push_rule
,
with:
Entities
::
ProjectPushRule
present
push_rule
,
with:
Entities
::
ProjectPushRule
else
else
not_found!
render_validation_error!
(
push_rule
)
end
end
end
end
# Deletes project push rule. This is an idempotent function.
desc
'Deletes project push rule'
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# DELETE /projects/:id/push_rule
delete
":id/push_rule"
do
delete
":id/push_rule"
do
@push_rule
=
user_project
.
push_rule
push_rule
=
user_project
.
push_rule
if
@push_rule
not_found!
(
'Push Rule'
)
unless
push_rule
@push_rule
.
destroy
else
push_rule
.
destroy
not_found!
end
end
end
end
end
end
end
...
...
spec/requests/api/project_push_rule_spec.rb
View file @
7e115252
...
@@ -128,7 +128,7 @@ describe API::ProjectPushRule, 'ProjectPushRule', api: true do
...
@@ -128,7 +128,7 @@ describe API::ProjectPushRule, 'ProjectPushRule', api: true do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'message'
]).
to
eq
(
"404 Not Found"
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Push Rule Not Found'
)
end
end
it
"returns a 403 error if not authorized"
do
it
"returns a 403 error if not authorized"
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