summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2016-08-23 13:29:59 -0400
committerBen Boeckel <ben.boeckel@kitware.com>2016-08-31 10:50:54 -0400
commit9c3db830c033750c19197fe6a3f15a7705e2aa3b (patch)
tree764c9ca94464ea1631d0deab8767cca1361de5cb
parenta181d675540d9ae571443cd9e19982af73be1ea4 (diff)
downloadgitlab-ce-9c3db830c033750c19197fe6a3f15a7705e2aa3b.tar.gz
entities: expose {,merge_commit_}sha in MergeRequest
Fixes #20456.
-rw-r--r--CHANGELOG1
-rw-r--r--doc/api/merge_requests.md24
-rw-r--r--lib/api/entities.rb2
-rw-r--r--spec/requests/api/merge_requests_spec.rb9
4 files changed, 33 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 7941a29d4ed..2484f29cff1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,7 @@ v 8.12.0 (unreleased)
- Change merge_error column from string to text type
- Reduce contributions calendar data payload (ClemMakesApps)
- Add `web_url` field to issue, merge request, and snippet API objects (Ben Boeckel)
+ - Expose `sha` and `merge_commit_sha` in merge request API (Ben Boeckel)
- Set path for all JavaScript cookies to honor GitLab's subdirectory setting !5627 (Mike Greiling)
- Shorten task status phrase (ClemMakesApps)
- Add hover color to emoji icon (ClemMakesApps)
diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md
index f4760ceac7c..494040a1ce8 100644
--- a/doc/api/merge_requests.md
+++ b/doc/api/merge_requests.md
@@ -68,6 +68,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : false,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null,
"user_notes_count": 1,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -135,6 +137,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": "9999999999999999999999999999999999999999",
"user_notes_count": 1,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -238,6 +242,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null,
"user_notes_count": 1,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -322,6 +328,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null,
"user_notes_count": 0,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -397,6 +405,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null,
"user_notes_count": 1,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -499,6 +509,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": "9999999999999999999999999999999999999999",
"user_notes_count": 1,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -569,6 +581,8 @@ Parameters:
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
"subscribed" : true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null,
"user_notes_count": 1,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
@@ -724,7 +738,9 @@ Example response:
},
"merge_when_build_succeeds": false,
"merge_status": "cannot_be_merged",
- "subscribed": true
+ "subscribed": true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null
}
```
@@ -798,7 +814,9 @@ Example response:
},
"merge_when_build_succeeds": false,
"merge_status": "cannot_be_merged",
- "subscribed": false
+ "subscribed": false,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null
}
```
@@ -891,6 +909,8 @@ Example response:
"merge_when_build_succeeds": false,
"merge_status": "unchecked",
"subscribed": true,
+ "sha": "8888888888888888888888888888888888888888",
+ "merge_commit_sha": null,
"user_notes_count": 7,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 4335e3055ef..3b05f0487ff 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -232,6 +232,8 @@ module API
expose :milestone, using: Entities::Milestone
expose :merge_when_build_succeeds
expose :merge_status
+ expose :diff_head_sha, as: :sha
+ expose :merge_commit_sha
expose :subscribed do |merge_request, options|
merge_request.subscribed?(options[:current_user])
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index baff872e28e..a7930c59df9 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -9,7 +9,7 @@ describe API::API, api: true do
let!(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
let!(:merge_request) { create(:merge_request, :simple, author: user, assignee: user, source_project: project, target_project: project, title: "Test", created_at: base_time) }
let!(:merge_request_closed) { create(:merge_request, state: "closed", author: user, assignee: user, source_project: project, target_project: project, title: "Closed test", created_at: base_time + 1.second) }
- let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds) }
+ let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds, merge_commit_sha: '9999999999999999999999999999999999999999') }
let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") }
let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") }
let(:milestone) { create(:milestone, title: '1.0.0', project: project) }
@@ -34,6 +34,13 @@ describe API::API, api: true do
expect(json_response.length).to eq(3)
expect(json_response.last['title']).to eq(merge_request.title)
expect(json_response.last).to have_key('web_url')
+ expect(json_response.last['sha']).to eq(merge_request.diff_head_sha)
+ expect(json_response.last['merge_commit_sha']).to be_nil
+ expect(json_response.last['merge_commit_sha']).to eq(merge_request.merge_commit_sha)
+ expect(json_response.first['title']).to eq(merge_request_merged.title)
+ expect(json_response.first['sha']).to eq(merge_request_merged.diff_head_sha)
+ expect(json_response.first['merge_commit_sha']).not_to be_nil
+ expect(json_response.first['merge_commit_sha']).to eq(merge_request_merged.merge_commit_sha)
end
it "returns an array of all merge_requests" do