Commit 3157b120 authored by Stan Hu's avatar Stan Hu

Merge branch '29020-merge-requests-issues-links' into 'master'

Provide MR and Issue links through the Release API

Closes #29020

See merge request gitlab-org/gitlab!18311
parents 657fcefd 82cda94d
...@@ -12,27 +12,11 @@ module ReleasesHelper ...@@ -12,27 +12,11 @@ module ReleasesHelper
help_page_path(DOCUMENTATION_PATH) help_page_path(DOCUMENTATION_PATH)
end end
def url_for_merge_requests
project_merge_requests_url(@project, params_for_issue_and_mr_paths)
end
def url_for_issues
project_issues_url(@project, params_for_issue_and_mr_paths)
end
def data_for_releases_page def data_for_releases_page
{ {
project_id: @project.id, project_id: @project.id,
illustration_path: illustration, illustration_path: illustration,
documentation_path: help_page, documentation_path: help_page
merge_requests_url: url_for_merge_requests,
issues_url: url_for_issues
} }
end end
private
def params_for_issue_and_mr_paths
{ scope: 'all', state: 'opened' }
end
end end
---
title: Provide Merge requests and Issue links through the Release API
merge_request: 18311
author:
type: added
...@@ -121,6 +121,10 @@ Example response: ...@@ -121,6 +121,10 @@ Example response:
"external":true "external":true
} }
] ]
},
"_links":{
"merge_requests_url": "https://gitlab.example.com/root/awesome_app/merge_requests?release_tag=v0.2&scope=all&state=opened",
"issues_url": "https://gitlab.example.com/root/awesome_app/issues?release_tag=v0.2&scope=all&state=opened"
} }
}, },
{ {
...@@ -177,6 +181,10 @@ Example response: ...@@ -177,6 +181,10 @@ Example response:
"links":[ "links":[
] ]
},
"_links":{
"merge_requests_url": "https://gitlab.example.com/root/awesome_app/merge_requests?release_tag=v0.1&scope=all&state=opened",
"issues_url": "https://gitlab.example.com/root/awesome_app/issues?release_tag=v0.1&scope=all&state=opened"
} }
} }
] ]
...@@ -288,6 +296,10 @@ Example response: ...@@ -288,6 +296,10 @@ Example response:
"links":[ "links":[
] ]
},
"_links":{
"merge_requests_url": "https://gitlab.example.com/root/awesome_app/merge_requests?release_tag=v0.1&scope=all&state=opened",
"issues_url": "https://gitlab.example.com/root/awesome_app/issues?release_tag=v0.1&scope=all&state=opened"
} }
} }
``` ```
...@@ -413,6 +425,10 @@ Example response: ...@@ -413,6 +425,10 @@ Example response:
"external":true "external":true
} }
] ]
},
"_links":{
"merge_requests_url": "https://gitlab.example.com/root/awesome_app/merge_requests?release_tag=v0.3&scope=all&state=opened",
"issues_url": "https://gitlab.example.com/root/awesome_app/issues?release_tag=v0.3&scope=all&state=opened"
} }
} }
``` ```
...@@ -514,6 +530,10 @@ Example response: ...@@ -514,6 +530,10 @@ Example response:
"links":[ "links":[
] ]
},
"_links":{
"merge_requests_url": "https://gitlab.example.com/root/awesome_app/merge_requests?release_tag=v0.1&scope=all&state=opened",
"issues_url": "https://gitlab.example.com/root/awesome_app/issues?release_tag=v0.1&scope=all&state=opened"
} }
} }
``` ```
...@@ -596,6 +616,10 @@ Example response: ...@@ -596,6 +616,10 @@ Example response:
"links":[ "links":[
] ]
},
"_links":{
"merge_requests_url": "https://gitlab.example.com/root/awesome_app/merge_requests?release_tag=v0.1&scope=all&state=opened",
"issues_url": "https://gitlab.example.com/root/awesome_app/issues?release_tag=v0.1&scope=all&state=opened"
} }
} }
``` ```
......
...@@ -1314,6 +1314,10 @@ module API ...@@ -1314,6 +1314,10 @@ module API
release.links.sorted release.links.sorted
end end
end end
expose :_links do
expose :merge_requests_url
expose :issues_url
end
private private
...@@ -1324,11 +1328,27 @@ module API ...@@ -1324,11 +1328,27 @@ module API
def commit_path def commit_path
return unless object.commit return unless object.commit
Gitlab::Routing.url_helpers.project_commit_path(object.project, object.commit.id) Gitlab::Routing.url_helpers.project_commit_path(project, object.commit.id)
end end
def tag_path def tag_path
Gitlab::Routing.url_helpers.project_tag_path(object.project, object.tag) Gitlab::Routing.url_helpers.project_tag_path(project, object.tag)
end
def merge_requests_url
Gitlab::Routing.url_helpers.project_merge_requests_url(project, params_for_issues_and_mrs)
end
def issues_url
Gitlab::Routing.url_helpers.project_issues_url(project, params_for_issues_and_mrs)
end
def params_for_issues_and_mrs
{ scope: 'all', state: 'opened', release_tag: object.tag }
end
def project
@project ||= object.project
end end
end end
......
...@@ -36,6 +36,13 @@ ...@@ -36,6 +36,13 @@
} }
}, },
"additionalProperties": false "additionalProperties": false
},
"_links": {
"required": ["merge_requests_url", "issues_url"],
"properties": {
"merge_requests_url": { "type": "string" },
"issues_url": { "type": "string" }
}
} }
}, },
"additionalProperties": false "additionalProperties": false
......
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
"links": { "$ref": "../../../release/links.json" } "links": { "$ref": "../../../release/links.json" }
}, },
"additionalProperties": false "additionalProperties": false
},
"_links": {
"required": ["merge_requests_url", "issues_url"],
"properties": {
"merge_requests_url": { "type": "string" },
"issues_url": { "type": "string" }
}
} }
}, },
"additionalProperties": false "additionalProperties": false
......
...@@ -22,23 +22,9 @@ describe ReleasesHelper do ...@@ -22,23 +22,9 @@ describe ReleasesHelper do
helper.instance_variable_set(:@project, project) helper.instance_variable_set(:@project, project)
end end
describe '#url_for_merge_requests' do
it 'returns the the correct link with the correct parameters' do
path = "#{project.group.path}/#{project.path}/merge_requests?scope=all&state=opened"
expect(helper.url_for_merge_requests).to include(path)
end
end
describe '#url_for_issues' do
it 'returns the the correct link with the correct parameters' do
path = "#{project.group.path}/#{project.path}/issues?scope=all&state=opened"
expect(helper.url_for_issues).to include(path)
end
end
describe '#data_for_releases_page' do describe '#data_for_releases_page' do
it 'has the needed data to display release blocks' do it 'has the needed data to display release blocks' do
keys = %i(project_id illustration_path documentation_path merge_requests_url issues_url) keys = %i(project_id illustration_path documentation_path)
expect(helper.data_for_releases_page.keys).to eq(keys) expect(helper.data_for_releases_page.keys).to eq(keys)
end end
end end
......
...@@ -63,6 +63,22 @@ describe API::Releases do ...@@ -63,6 +63,22 @@ describe API::Releases do
expect(json_response.second['commit_path']).to eq("/#{release_1.project.full_path}/commit/#{release_1.commit.id}") expect(json_response.second['commit_path']).to eq("/#{release_1.project.full_path}/commit/#{release_1.commit.id}")
expect(json_response.second['tag_path']).to eq("/#{release_1.project.full_path}/-/tags/#{release_1.tag}") expect(json_response.second['tag_path']).to eq("/#{release_1.project.full_path}/-/tags/#{release_1.tag}")
end end
it 'returns the merge requests and issues links, with correct query' do
get api("/projects/#{project.id}/releases", maintainer)
links = json_response.first['_links']
release = json_response.first['tag_name']
expected_query = "release_tag=#{release}&scope=all&state=opened"
path_base = "/#{project.namespace.path}/#{project.path}"
mr_uri = URI.parse(links['merge_requests_url'])
issue_uri = URI.parse(links['issues_url'])
expect(mr_uri.path).to eq("#{path_base}/merge_requests")
expect(issue_uri.path).to eq("#{path_base}/issues")
expect(mr_uri.query).to eq(expected_query)
expect(issue_uri.query).to eq(expected_query)
end
end end
it 'returns an upcoming_release status for a future release' do it 'returns an upcoming_release status for a future release' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment