Skip to content

Commit

Permalink
Add v4-endpoint to fetch all merge_requests for a milestone (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
joren authored and asedge committed Mar 27, 2017
1 parent 054a93b commit a8812eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Add issues subscribe/unsubscribe (@newellista)
- Add merge_requests subscribe/unsubscribe (@newellista)
- Updated `deploy_key` endpoints (@epintozzi)
- Add milestone/merge_requests (API V4 only) (@joren)

### 3.7.0 (16/08/2016)

Expand Down
14 changes: 14 additions & 0 deletions lib/gitlab/client/milestones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ def milestone_issues(project, milestone, options={})
get("/projects/#{url_encode project}/milestones/#{milestone}/issues", query: options)
end

# Gets the merge_requests of a given milestone.
#
# @example
# Gitlab.milestone_merge_requests(5, 2)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer, String] milestone The ID of a milestone.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def milestone_merge_requests(project, milestone, options={})
get("/projects/#{url_encode project}/milestones/#{milestone}/merge_requests", query: options)
end

# Creates a new milestone.
#
# @example
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/milestone_merge_requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1,"iid":1,"project_id":1,"title":"lorem ipsum","description":"","state":"opened","created_at":"2017-03-24T12:23:53.918Z","updated_at":"2017-03-24T12:23:53.918Z","target_branch":"master","source_branch":"def","upvotes":0,"downvotes":0,"author":{"name":"John Doe","username":"jdoe","id":1,"state":"active","avatar_url":"","web_url":"https://gitlab.com/jdoen"},"assignee":null,"source_project_id":1,"target_project_id":1,"labels":[],"work_in_progress":false,"milestone":{"id":1,"iid":1,"project_id":1,"title":"Test","description":"","state":"active","created_at":"2017-03-24T12:23:00.560Z","updated_at":"2017-03-24T12:23:00.560Z","due_date":null,"start_date":null},"merge_when_pipeline_succeeds":false,"merge_status":"can_be_merged","sha":"aec123d1775790b2347fdd684b5ba613fdeb994b","merge_commit_sha":null,"user_notes_count":0,"approvals_before_merge":null,"should_remove_source_branch":null,"force_remove_source_branch":false,"squash":false,"web_url":"https://gitlab.com/jdoe/milestone_merge_requests_test/merge_requests/2"},{"id":2,"iid":2,"project_id":1,"title":"ipsum lorem","description":"","state":"opened","created_at":"2017-03-24T12:23:24.662Z","updated_at":"2017-03-24T12:23:33.522Z","target_branch":"master","source_branch":"test1","upvotes":0,"downvotes":0,"author":{"name":"Joren","username":"jdoe","id":1,"state":"active","":"","web_url":"https://gitlab.com/jdoe"},"assignee":null,"source_project_id":1,"target_project_id":1,"labels":[],"work_in_progress":false,"milestone":{"id":1,"iid":1,"project_id":1,"title":"Test","description":"","state":"active","created_at":"2017-03-24T12:23:00.560Z","updated_at":"2017-03-24T12:23:00.560Z","due_date":null,"start_date":null},"merge_when_pipeline_succeeds":false,"merge_status":"can_be_merged","sha":"3ee44c9b40deddae596f838b97523c6f010fd80d","merge_commit_sha":null,"user_notes_count":0,"approvals_before_merge":null,"should_remove_source_branch":null,"force_remove_source_branch":true,"squash":false,"web_url":"https://gitlab.com/jdoe/milestone_merge_requests_test/merge_requests/1"}]
16 changes: 16 additions & 0 deletions spec/gitlab/client/milestones_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
end
end

describe ".milestone_merge_requests" do
before do
stub_get("/projects/3/milestones/1/merge_requests", "milestone_merge_requests")
@milestone_merge_requests = Gitlab.milestone_merge_requests(3, 1)
end

it "should get the correct resource" do
expect(a_get("/projects/3/milestones/1/merge_requests")).to have_been_made
end

it "should return a paginated response of milestone's merge_requests" do
expect(@milestone_merge_requests).to be_a Gitlab::PaginatedResponse
expect(@milestone_merge_requests.first.milestone.id).to eq(1)
end
end

describe ".create_milestone" do
before do
stub_post("/projects/3/milestones", "milestone")
Expand Down

0 comments on commit a8812eb

Please sign in to comment.