Commit 0f5c6b6a authored by Etienne Baqué's avatar Etienne Baqué

Modified release api entity

Updated release payload to include links.
Updated rspec accordingly.
parent fc69d1cf
......@@ -1314,6 +1314,10 @@ module API
release.links.sorted
end
end
expose :_links do
expose :merge_requests
expose :issues
end
private
......@@ -1324,11 +1328,27 @@ module API
def commit_path
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
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
Gitlab::Routing.url_helpers.project_merge_requests_url(project, params_for_issues_and_mrs)
end
def issues
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
......
......@@ -36,6 +36,13 @@
}
},
"additionalProperties": false
},
"_links": {
"required": ["merge_requests", "issues"],
"properties": {
"merge_requests": { "type": "string" },
"issues": { "type": "string" }
}
}
},
"additionalProperties": false
......
......@@ -24,6 +24,13 @@
"links": { "$ref": "../../../release/links.json" }
},
"additionalProperties": false
},
"_links": {
"required": ["merge_requests", "issues"],
"properties": {
"merge_requests": { "type": "string" },
"issues": { "type": "string" }
}
}
},
"additionalProperties": false
......
......@@ -63,6 +63,30 @@ 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['tag_path']).to eq("/#{release_1.project.full_path}/-/tags/#{release_1.tag}")
end
it 'returns the merge requests and issues links' do
get api("/projects/#{project.id}/releases", maintainer)
links = json_response.first['_links']
expect(links.keys).to include('merge_requests', 'issues')
expect(links['merge_requests']).to include("/#{release_2.project.full_path}/merge_requests")
expect(links['issues']).to include("/#{release_2.project.full_path}/issues")
end
it 'returns urls with correct parameters and release tag' do
get api("/projects/#{project.id}/releases", maintainer)
links = json_response.first['_links']
release = json_response.first['tag_name']
expected_params = %w(release_tag scope state)
release_tag_param = "release_tag=#{release}"
expect(links['merge_requests'].split('?')[1]).to include(*expected_params)
expect(links['issues'].split('?')[1]).to include(*expected_params)
expect(links['merge_requests']).to include(release_tag_param)
expect(links['issues']).to include(release_tag_param)
end
end
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