Fix Error 500 when using closes_issues API with an external issue tracker
Closes #18484
This commit is contained in:
parent
ff345f8ba1
commit
a85dde9182
6 changed files with 42 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
Please view this file on the master branch, on stable branches it's out of date.
|
Please view this file on the master branch, on stable branches it's out of date.
|
||||||
|
|
||||||
v 8.9.0 (unreleased)
|
v 8.9.0 (unreleased)
|
||||||
|
- Fix Error 500 when using closes_issues API with an external issue tracker
|
||||||
- Bulk assign/unassign labels to issues.
|
- Bulk assign/unassign labels to issues.
|
||||||
- Ability to prioritize labels !4009 / !3205 (Thijs Wouters)
|
- Ability to prioritize labels !4009 / !3205 (Thijs Wouters)
|
||||||
- Fix endless redirections when accessing user OAuth applications when they are disabled
|
- Fix endless redirections when accessing user OAuth applications when they are disabled
|
||||||
|
|
|
@ -572,7 +572,7 @@ GET /projects/:id/merge_requests/:merge_request_id/closes_issues
|
||||||
curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/76/merge_requests/1/closes_issues
|
curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/76/merge_requests/1/closes_issues
|
||||||
```
|
```
|
||||||
|
|
||||||
Example response:
|
Example response when the GitLab issue tracker is used:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
|
@ -618,6 +618,17 @@ Example response:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example response when an external issue tracker (e.g. JIRA) is used:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id" : "PROJECT-123",
|
||||||
|
"title" : "Title of this issue"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## Subscribe to a merge request
|
## Subscribe to a merge request
|
||||||
|
|
||||||
Subscribes the authenticated user to a merge request to receive notification. If
|
Subscribes the authenticated user to a merge request to receive notification. If
|
||||||
|
|
|
@ -179,6 +179,11 @@ module API
|
||||||
expose :upvotes, :downvotes
|
expose :upvotes, :downvotes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ExternalIssue < Grape::Entity
|
||||||
|
expose :title
|
||||||
|
expose :id
|
||||||
|
end
|
||||||
|
|
||||||
class MergeRequest < ProjectEntity
|
class MergeRequest < ProjectEntity
|
||||||
expose :target_branch, :source_branch
|
expose :target_branch, :source_branch
|
||||||
expose :upvotes, :downvotes
|
expose :upvotes, :downvotes
|
||||||
|
|
|
@ -418,5 +418,13 @@ module API
|
||||||
def send_git_archive(repository, ref:, format:)
|
def send_git_archive(repository, ref:, format:)
|
||||||
header(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format))
|
header(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def issue_entity(project)
|
||||||
|
if project.has_external_issue_tracker?
|
||||||
|
Entities::ExternalIssue
|
||||||
|
else
|
||||||
|
Entities::Issue
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -329,7 +329,7 @@ module API
|
||||||
get "#{path}/closes_issues" do
|
get "#{path}/closes_issues" do
|
||||||
merge_request = user_project.merge_requests.find(params[:merge_request_id])
|
merge_request = user_project.merge_requests.find(params[:merge_request_id])
|
||||||
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
|
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
|
||||||
present paginate(issues), with: Entities::Issue, current_user: current_user
|
present paginate(issues), with: issue_entity(user_project), current_user: current_user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -563,6 +563,21 @@ describe API::API, api: true do
|
||||||
expect(json_response).to be_an Array
|
expect(json_response).to be_an Array
|
||||||
expect(json_response.length).to eq(0)
|
expect(json_response.length).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'handles external issues' do
|
||||||
|
jira_project = create(:jira_project, :public, name: 'JIR_EXT1')
|
||||||
|
issue = ExternalIssue.new("#{jira_project.name}-123", jira_project)
|
||||||
|
merge_request = create(:merge_request, :simple, author: user, assignee: user, source_project: jira_project)
|
||||||
|
merge_request.update_attribute(:description, "Closes #{issue.to_reference(jira_project)}")
|
||||||
|
|
||||||
|
get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(json_response).to be_an Array
|
||||||
|
expect(json_response.length).to eq(1)
|
||||||
|
expect(json_response.first['title']).to eq(issue.title)
|
||||||
|
expect(json_response.first['id']).to eq(issue.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST :id/merge_requests/:merge_request_id/subscription' do
|
describe 'POST :id/merge_requests/:merge_request_id/subscription' do
|
||||||
|
|
Loading…
Reference in a new issue