Commit 69845546 authored by Robert Speicher's avatar Robert Speicher

Merge remote-tracking branch 'ce/8-2-stable' into 8-2-stable-ee

parents 5779f04b dbcd6462
......@@ -73,7 +73,7 @@ class @AwardsHandler
getImage: (emoji, custom_path) ->
if custom_path
$(".awards-menu li").first().html().replace(/emoji\/.*\.png/, custom_path)
$("<img>").attr({src: custom_path, width: 20, height: 20}).wrap("<div>").parent().html()
else
$("li[data-emoji='" + emoji + "']").html()
......
......@@ -136,7 +136,7 @@ class Projects::NotesController < Projects::ApplicationController
discussion_id: note.discussion_id,
html: note_to_html(note),
award: note.is_award,
emoji_path: note.is_award ? ::AwardEmoji.path_to_emoji_image(note.note) : "",
emoji_path: note.is_award ? view_context.image_url(::AwardEmoji.path_to_emoji_image(note.note)) : "",
note: note.note,
discussion_html: note_to_discussion_html(note),
discussion_with_diff_html: note_to_discussion_with_diff_html(note)
......
......@@ -89,6 +89,16 @@ module Issuable
opened? || reopened?
end
# Deprecated. Still exists to preserve API compatibility.
def downvotes
0
end
# Deprecated. Still exists to preserve API compatibility.
def upvotes
0
end
def subscribed?(user)
subscription = subscriptions.find_by_user_id(user.id)
......
......@@ -545,7 +545,7 @@ class MergeRequest < ActiveRecord::Base
end
def ci_commit
if last_commit
if last_commit and source_project
source_project.ci_commit(last_commit.id)
end
end
......
......@@ -335,6 +335,16 @@ class Note < ActiveRecord::Base
read_attribute(:system)
end
# Deprecated. Still exists to preserve API compatibility.
def downvote?
false
end
# Deprecated. Still exists to preserve API compatibility.
def upvote?
false
end
def editable?
!system?
end
......
require_relative 'base_service'
class CreateReleaseService < BaseService
def execute(tag_name, release_description)
repository = project.repository
existing_tag = repository.find_tag(tag_name)
# Only create a release if the tag exists
if existing_tag
release = project.releases.find_by(tag: tag_name)
if release
error('Release already exists', 409)
else
release = project.releases.new({ tag: tag_name, description: release_description })
release.save
success(release)
end
else
error('Tag does not exist', 404)
end
end
def success(release)
out = super()
out[:release] = release
out
end
end
......@@ -19,16 +19,16 @@ class CreateTagService < BaseService
new_tag = repository.find_tag(tag_name)
if new_tag
if release_description
release = project.releases.find_or_initialize_by(tag: tag_name)
release.update_attributes(description: release_description)
end
push_data = create_push_data(project, current_user, new_tag)
EventCreateService.new.push(project, current_user, push_data)
project.execute_hooks(push_data.dup, :tag_push_hooks)
project.execute_services(push_data.dup, :tag_push_hooks)
if release_description
CreateReleaseService.new(@project, @current_user).
execute(tag_name, release_description)
end
success(new_tag)
else
error('Invalid reference name')
......
require_relative 'base_service'
class UpdateReleaseService < BaseService
def execute(tag_name, release_description)
repository = project.repository
existing_tag = repository.find_tag(tag_name)
if existing_tag
release = project.releases.find_by(tag: tag_name)
if release
release.update_attributes(description: release_description)
success(release)
else
error('Release does not exist', 404)
end
else
error('Tag does not exist', 404)
end
end
def success(release)
out = super()
out[:release] = release
out
end
end
......@@ -3,8 +3,9 @@
## List merge requests
Get all merge requests for this project.
The `state` parameter can be used to get only merge requests with a given state (`opened`, `closed`, or `merged`) or all of them (`all`).
The pagination parameters `page` and `per_page` can be used to restrict the list of merge requests.
The `state` parameter can be used to get only merge requests with a given state (`opened`, `closed`, or `merged`) or all of them (`all`).
The pagination parameters `page` and `per_page` can be used to restrict the list of merge requests. With GitLab 8.2 the return fields `upvotes` and
`downvotes` are deprecated and always return `0`.
```
GET /projects/:id/merge_requests
......@@ -31,6 +32,8 @@ Parameters:
"project_id": 3,
"title": "test1",
"state": "opened",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "admin",
......@@ -55,7 +58,7 @@ Parameters:
## Get single MR
Shows information about a single merge request.
Shows information about a single merge request. With GitLab 8.2 the return fields `upvotes` and `downvotes` are deprecated and always return `0`.
```
GET /projects/:id/merge_request/:merge_request_id
......@@ -75,6 +78,8 @@ Parameters:
"project_id": 3,
"title": "test1",
"state": "merged",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "admin",
......@@ -98,7 +103,9 @@ Parameters:
## Get single MR changes
Shows information about the merge request including its files and changes
Shows information about the merge request including its files and changes.
With GitLab 8.2 the return fields `upvotes` and `downvotes` are deprecated and
always return `0`.
```
GET /projects/:id/merge_request/:merge_request_id/changes
......@@ -122,6 +129,8 @@ Parameters:
"updated_at": "2015-02-02T20:08:49.959Z",
"target_branch": "secret_token",
"source_branch": "version-1-9",
"upvotes": 0,
"downvotes": 0,
"author": {
"name": "Chad Hamill",
"username": "jarrett",
......@@ -167,7 +176,8 @@ Parameters:
## Create MR
Creates a new merge request.
Creates a new merge request. With GitLab 8.2 the return fields `upvotes` and `
downvotes` are deprecated and always return `0`.
```
POST /projects/:id/merge_requests
......@@ -192,6 +202,8 @@ Parameters:
"project_id": 3,
"title": "test1",
"state": "opened",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "admin",
......@@ -217,7 +229,8 @@ If an error occurs, an error number and a message explaining the reason is retur
## Update MR
Updates an existing merge request. You can change the target branch, title, or even close the MR.
Updates an existing merge request. You can change the target branch, title, or even close the MR. With GitLab 8.2 the return fields `upvotes` and `downvotes`
are deprecated and always return `0`.
```
PUT /projects/:id/merge_request/:merge_request_id
......@@ -242,6 +255,8 @@ Parameters:
"title": "test1",
"description": "description1",
"state": "opened",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "admin",
......@@ -266,7 +281,8 @@ If an error occurs, an error number and a message explaining the reason is retur
## Accept MR
Merge changes submitted with MR using this API.
Merge changes submitted with MR using this API. With GitLab 8.2 the return
fields `upvotes` and `downvotes` are deprecated and always return `0`.
If merge success you get `200 OK`.
......@@ -294,6 +310,8 @@ Parameters:
"project_id": 3,
"title": "test1",
"state": "merged",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "admin",
......
......@@ -6,7 +6,8 @@ Notes are comments on snippets, issues or merge requests.
### List project issue notes
Gets a list of all notes for a single issue.
Gets a list of all notes for a single issue. With GitLab 8.2 the return fields
`upvote` and `downvote` are deprecated and always return `false`.
```
GET /projects/:id/issues/:issue_id/notes
......@@ -32,7 +33,9 @@ Parameters:
"created_at": "2013-09-30T13:46:01Z"
},
"created_at": "2013-10-02T09:22:45Z",
"system": true
"system": true,
"upvote": false,
"downvote": false
},
{
"id": 305,
......@@ -47,7 +50,9 @@ Parameters:
"created_at": "2013-09-30T13:46:01Z"
},
"created_at": "2013-10-02T09:56:03Z",
"system": false
"system": true,
"upvote": false,
"downvote": false
}
]
```
......
......@@ -29,7 +29,7 @@ Parameters:
]
},
"release": {
"tag": "1.0.0",
"tag_name": "1.0.0",
"description": "Amazing release. Wow"
},
"name": "v1.0.0",
......@@ -70,7 +70,7 @@ Parameters:
]
},
"release": {
"tag": "1.0.0",
"tag_name": "1.0.0",
"description": "Amazing release. Wow"
},
"name": "v1.0.0",
......@@ -84,23 +84,48 @@ It returns 200 if the operation succeed. In case of an error,
405 with an explaining error message is returned.
## New release
## Create a new release
Add release notes to the existing git tag
Add release notes to the existing git tag. It returns 201 if the release is
created successfully. If the tag does not exist, 404 is returned. If there
already exists a release for the given tag, 409 is returned.
```
PUT /projects/:id/repository/:tag/release
POST /projects/:id/repository/tags/:tag_name/release
```
Parameters:
- `id` (required) - The ID of a project
- `tag` (required) - The name of a tag
- `tag_name` (required) - The name of a tag
- `description` (required) - Release notes with markdown support
```json
{
"tag": "1.0.0",
"tag_name": "1.0.0",
"description": "Amazing release. Wow"
}
```
## Update a release
Updates the release notes of a given release. It returns 200 if the release is
successfully updated. If the tag or the release does not exist, it returns 404
with a proper error message.
```
PUT /projects/:id/repository/tags/:tag_name/release
```
Parameters:
- `id` (required) - The ID of a project
- `tag_name` (required) - The name of a tag
- `description` (required) - Release notes with markdown support
```json
{
"tag_name": "1.0.0",
"description": "Amazing release. Wow"
}
```
\ No newline at end of file
......@@ -173,6 +173,8 @@ module API
class MergeRequest < ProjectEntity
expose :target_branch, :source_branch
# deprecated, always returns 0
expose :upvotes, :downvotes
expose :author, :assignee, using: Entities::UserBasic
expose :source_project_id, :target_project_id
expose :label_names, as: :labels
......@@ -202,6 +204,9 @@ module API
expose :author, using: Entities::UserBasic
expose :created_at
expose :system?, as: :system
# upvote? and downvote? are deprecated, always return false
expose :upvote?, as: :upvote
expose :downvote?, as: :downvote
end
class MRNote < Grape::Entity
......@@ -340,7 +345,8 @@ module API
end
class Release < Grape::Entity
expose :tag, :description
expose :tag, as: :tag_name
expose :description
end
class RepoTag < Grape::Entity
......
......@@ -44,17 +44,42 @@ module API
#
# Parameters:
# id (required) - The ID of a project
# tag (required) - The name of the tag
# tag_name (required) - The name of the tag
# description (required) - Release notes with markdown support
# Example Request:
# POST /projects/:id/repository/tags/:tag_name/release
post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.*/ } do
authorize_push_project
required_attributes! [:description]
result = CreateReleaseService.new(user_project, current_user).
execute(params[:tag_name], params[:description])
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], result[:http_status])
end
end
# Updates a release notes of a tag
#
# Parameters:
# id (required) - The ID of a project
# tag_name (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
# PUT /projects/:id/repository/tags/:tag_name/release
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.*/ } do
authorize_push_project
required_attributes! [:description]
release = user_project.releases.find_or_initialize_by(tag: params[:tag])
release.update_attributes(description: params[:description])
result = UpdateReleaseService.new(user_project, current_user).
execute(params[:tag_name], params[:description])
present release, with: Entities::Release
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], result[:http_status])
end
end
end
end
......
......@@ -234,4 +234,29 @@ describe MergeRequest do
it_behaves_like 'a Taskable' do
subject { create :merge_request, :simple }
end
describe '#ci_commit' do
describe 'when the source project exists' do
it 'returns the latest commit' do
commit = double(:commit, id: '123abc')
ci_commit = double(:ci_commit)
allow(subject).to receive(:last_commit).and_return(commit)
expect(subject.source_project).to receive(:ci_commit).
with('123abc').
and_return(ci_commit)
expect(subject.ci_commit).to eq(ci_commit)
end
end
describe 'when the source project does not exist' do
it 'returns nil' do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.ci_commit).to be_nil
end
end
end
end
......@@ -28,10 +28,10 @@ describe API::API, api: true do
before do
release = project.releases.find_or_initialize_by(tag: tag_name)
release.update_attributes(description: description)
get api("/projects/#{project.id}/repository/tags", user)
end
it "should return an array of project tags with release info" do
get api("/projects/#{project.id}/repository/tags", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name)
......@@ -119,17 +119,78 @@ describe API::API, api: true do
end
end
describe 'PUT /projects/:id/repository/:tag/release' do
describe 'POST /projects/:id/repository/tags/:tag_name/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),
post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: description
expect(response.status).to eq(200)
expect(json_response['tag']).to eq(tag_name)
expect(response.status).to eq(201)
expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(description)
end
it 'should return 404 if the tag does not exist' do
post api("/projects/#{project.id}/repository/tags/foobar/release", user),
description: description
expect(response.status).to eq(404)
expect(json_response['message']).to eq('Tag does not exist')
end
context 'on tag with existing release' do
before do
release = project.releases.find_or_initialize_by(tag: tag_name)
release.update_attributes(description: description)
end
it 'should return 409 if there is already a release' do
post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: description
expect(response.status).to eq(409)
expect(json_response['message']).to eq('Release already exists')
end
end
end
describe 'PUT id/repository/tags/:tag_name/release' do
let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' }
let(:new_description) { 'The best release!' }
context 'on tag with existing release' do
before do
release = project.releases.find_or_initialize_by(tag: tag_name)
release.update_attributes(description: description)
end
it 'should update the release description' do
put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: new_description
expect(response.status).to eq(200)
expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(new_description)
end
end
it 'should return 404 if the tag does not exist' do
put api("/projects/#{project.id}/repository/tags/foobar/release", user),
description: new_description
expect(response.status).to eq(404)
expect(json_response['message']).to eq('Tag does not exist')
end
it 'should return 404 if the release does not exist' do
put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: new_description
expect(response.status).to eq(404)
expect(json_response['message']).to eq('Release does not exist')
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