BigW Consortium Gitlab

Add releases api

parent d343d9d8
......@@ -341,5 +341,9 @@ module API
expose :user_oauth_applications
expose :after_sign_out_path
end
class Release < Grape::Entity
expose :tag, :description
end
end
end
module API
# Releases API
# Git Tags API
class Tags < Grape::API
before { authenticate! }
before { authorize! :download_code, user_project }
......@@ -39,6 +39,23 @@ module API
render_api_error!(result[:message], 400)
end
end
# Add release notes to tag
#
# Parameters:
# id (required) - The ID of a project
# tag (required) - The name of the tag
# description (required) - Release notes with markdown support
# Example Request:
# PUT /projects/:id/repository/tags
put ':id/repository/:tag/release', requirements: { tag: /.*/ } do
authorize_push_project
required_attributes! [:description]
release = user_project.releases.find_or_initialize_by(tag: params[:tag])
release.update_attributes(description: params[:description])
present release, with: Entities::Release
end
end
end
end
......@@ -11,7 +11,6 @@ describe API::API, api: true do
let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) }
describe "GET /projects/:id/repository/tags" do
it "should return an array of project tags" do
get api("/projects/#{project.id}/repository/tags", user)
......@@ -86,4 +85,18 @@ describe API::API, api: true do
expect(json_response['message']).to eq('Invalid reference name')
end
end
describe 'PUT /projects/:id/repository/:tag/release' do
let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' }
it 'should create description for existing git tag' do
put api("/projects/#{project.id}/repository/#{tag_name}/release", user),
description: description
expect(response.status).to eq(200)
expect(json_response['tag']).to eq(tag_name)
expect(json_response['description']).to eq(description)
end
end
end
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