Skip to content

Commit

Permalink
Add Issue related_merge_requests endpoint
Browse files Browse the repository at this point in the history
Fix outstanding rubocop issue in cli_helpers
  • Loading branch information
ddavison committed Feb 9, 2024
1 parent dfffe94 commit b0f2179
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gitlab/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def actions
#
# @return [Gitlab::Client]
def client
@client ||= Gitlab::Client.new(endpoint: (Gitlab.endpoint || ''))
@client ||= Gitlab::Client.new(endpoint: Gitlab.endpoint || '')
end

# Returns method names and their owners
Expand Down
11 changes: 11 additions & 0 deletions lib/gitlab/client/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,16 @@ def participants_on_issue(project, id)
def merge_requests_closing_issue_on_merge(project, id)
get("/projects/#{url_encode project}/issues/#{id}/closed_by")
end

# List related merge requests
#
# @example
# Gitlab.related_merge_requests(3, 42)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of an issue.
def related_merge_requests(project, id)
get("/projects/#{url_encode project}/issues/#{id}/related_merge_requests")
end
end
end
135 changes: 135 additions & 0 deletions spec/fixtures/related_merge_requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[
{
"id": 29,
"iid": 11,
"project_id": 1,
"title": "Related MR",
"description": "Ut consequatur ipsa aspernatur quisquam voluptatum fugit. Qui harum corporis quo fuga ut incidunt veritatis. Autem necessitatibus et harum occaecati nihil ea.\r\n\r\ntwitter/flight#8",
"state": "opened",
"created_at": "2018-09-18T14:36:15.510Z",
"updated_at": "2018-09-19T07:45:13.089Z",
"closed_by": null,
"closed_at": null,
"target_branch": "v2.x",
"source_branch": "so_long_jquery",
"user_notes_count": 9,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 14,
"name": "Verna Hills",
"username": "lawanda_reinger",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/de68a91aeab1cff563795fb98a0c2cc0?s=80&d=identicon",
"web_url": "https://gitlab.example.com/lawanda_reinger"
},
"assignee": {
"id": 19,
"name": "Jody Baumbach",
"username": "felipa.kuvalis",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/6541fc75fc4e87e203529bd275fafd07?s=80&d=identicon",
"web_url": "https://gitlab.example.com/felipa.kuvalis"
},
"source_project_id": 1,
"target_project_id": 1,
"labels": [],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 27,
"iid": 2,
"project_id": 1,
"title": "v1.0",
"description": "Et tenetur voluptatem minima doloribus vero dignissimos vitae.",
"state": "active",
"created_at": "2018-09-18T14:35:44.353Z",
"updated_at": "2018-09-18T14:35:44.353Z",
"due_date": null,
"start_date": null,
"web_url": "https://gitlab.example.com/twitter/flight/milestones/2"
},
"merge_when_pipeline_succeeds": false,
"merge_status": "cannot_be_merged",
"sha": "3b7b528e9353295c1c125dad281ac5b5deae5f12",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": false,
"reference": "!11",
"web_url": "https://gitlab.example.com/twitter/flight/merge_requests/4",
"references": {
"short": "!4",
"relative": "!4",
"full": "twitter/flight!4"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"changes_count": "10",
"latest_build_started_at": "2018-12-05T01:16:41.723Z",
"latest_build_finished_at": "2018-12-05T02:35:54.046Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 38980952,
"sha": "81c6a84c7aebd45a1ac2c654aa87f11e32338e0a",
"ref": "test-branch",
"status": "success",
"web_url": "https://gitlab.com/gitlab-org/gitlab/pipelines/38980952"
},
"head_pipeline": {
"id": 38980952,
"sha": "81c6a84c7aebd45a1ac2c654aa87f11e32338e0a",
"ref": "test-branch",
"status": "success",
"web_url": "https://gitlab.example.com/twitter/flight/pipelines/38980952",
"before_sha": "3c738a37eb23cf4c0ed0d45d6ddde8aad4a8da51",
"tag": false,
"yaml_errors": null,
"user": {
"id": 19,
"name": "Jody Baumbach",
"username": "felipa.kuvalis",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/6541fc75fc4e87e203529bd275fafd07?s=80&d=identicon",
"web_url": "https://gitlab.example.com/felipa.kuvalis"
},
"created_at": "2018-12-05T01:16:13.342Z",
"updated_at": "2018-12-05T02:35:54.086Z",
"started_at": "2018-12-05T01:16:41.723Z",
"finished_at": "2018-12-05T02:35:54.046Z",
"committed_at": null,
"duration": 4436,
"coverage": "46.68",
"detailed_status": {
"icon": "status_warning",
"text": "passed",
"label": "passed with warnings",
"group": "success-with-warnings",
"tooltip": "passed",
"has_details": true,
"details_path": "/twitter/flight/pipelines/38",
"illustration": null,
"favicon": "https://gitlab.example.com/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
}
},
"diff_refs": {
"base_sha": "d052d768f0126e8cddf80afd8b1eb07f406a3fcb",
"head_sha": "81c6a84c7aebd45a1ac2c654aa87f11e32338e0a",
"start_sha": "d052d768f0126e8cddf80afd8b1eb07f406a3fcb"
},
"merge_error": null,
"user": {
"can_merge": true
}
}
]
16 changes: 16 additions & 0 deletions spec/gitlab/client/issues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,20 @@
expect(@merge_requests.size).to eq(2)
end
end

describe '.related_merge_requests' do
before do
stub_get('/projects/3/issues/33/related_merge_requests', 'related_merge_requests')
@merge_requests = Gitlab.related_merge_requests(3, 33)
end

it 'gets the correct resource' do
expect(a_get('/projects/3/issues/33/related_merge_requests')).to have_been_made
end

it 'returns list of related merge requests' do
expect(@merge_requests.first.title).to eq('Related MR')
expect(@merge_requests).to be_one
end
end
end

0 comments on commit b0f2179

Please sign in to comment.