Commit 14f5d1727aa68318aadae4c867cc07842dde8520
Exists in
master
and in
4 other branches
Merge branch 'milestone_api' of https://github.com/tsigo/gitlabhq into tsigo-milestone_api
Conflicts: spec/requests/api/issues_spec.rb
Showing
5 changed files
with
131 additions
and
6 deletions
Show diff stats
lib/api.rb
lib/api/issues.rb
| @@ -95,7 +95,7 @@ module Gitlab | @@ -95,7 +95,7 @@ module Gitlab | ||
| 95 | end | 95 | end |
| 96 | end | 96 | end |
| 97 | 97 | ||
| 98 | - # Delete a project issue | 98 | + # Delete a project issue (deprecated) |
| 99 | # | 99 | # |
| 100 | # Parameters: | 100 | # Parameters: |
| 101 | # id (required) - The ID or code name of a project | 101 | # id (required) - The ID or code name of a project |
| @@ -103,8 +103,7 @@ module Gitlab | @@ -103,8 +103,7 @@ module Gitlab | ||
| 103 | # Example Request: | 103 | # Example Request: |
| 104 | # DELETE /projects/:id/issues/:issue_id | 104 | # DELETE /projects/:id/issues/:issue_id |
| 105 | delete ":id/issues/:issue_id" do | 105 | delete ":id/issues/:issue_id" do |
| 106 | - @issue = user_project.issues.find(params[:issue_id]) | ||
| 107 | - @issue.destroy | 106 | + error!({'message' => 'method not allowed'}, 405) |
| 108 | end | 107 | end |
| 109 | end | 108 | end |
| 110 | end | 109 | end |
| @@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
| 1 | +module Gitlab | ||
| 2 | + # Milestones API | ||
| 3 | + class Milestones < Grape::API | ||
| 4 | + before { authenticate! } | ||
| 5 | + | ||
| 6 | + resource :projects do | ||
| 7 | + # Get a list of project milestones | ||
| 8 | + # | ||
| 9 | + # Parameters: | ||
| 10 | + # id (required) - The ID or code name of a project | ||
| 11 | + # Example Request: | ||
| 12 | + # GET /projects/:id/milestones | ||
| 13 | + get ":id/milestones" do | ||
| 14 | + present user_project.milestones, with: Entities::Milestone | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + # Get a single project milestone | ||
| 18 | + # | ||
| 19 | + # Parameters: | ||
| 20 | + # id (required) - The ID or code name of a project | ||
| 21 | + # milestone_id (required) - The ID of a project milestone | ||
| 22 | + # Example Request: | ||
| 23 | + # GET /projects/:id/milestones/:milestone_id | ||
| 24 | + get ":id/milestones/:milestone_id" do | ||
| 25 | + @milestone = user_project.milestones.find(params[:milestone_id]) | ||
| 26 | + present @milestone, with: Entities::Milestone | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | + # Create a new project milestone | ||
| 30 | + # | ||
| 31 | + # Parameters: | ||
| 32 | + # id (required) - The ID or code name of the project | ||
| 33 | + # title (required) - The title of the milestone | ||
| 34 | + # description (optional) - The description of the milestone | ||
| 35 | + # due_date (optional) - The due date of the milestone | ||
| 36 | + # closed (optional) - The status of the milestone | ||
| 37 | + # Example Request: | ||
| 38 | + # POST /projects/:id/milestones | ||
| 39 | + post ":id/milestones" do | ||
| 40 | + @milestone = user_project.milestones.new( | ||
| 41 | + title: params[:title], | ||
| 42 | + description: params[:description], | ||
| 43 | + due_date: params[:due_date], | ||
| 44 | + closed: (params[:closed] || false) | ||
| 45 | + ) | ||
| 46 | + | ||
| 47 | + if @milestone.save | ||
| 48 | + present @milestone, with: Entities::Milestone | ||
| 49 | + else | ||
| 50 | + error!({'message' => '404 Not found'}, 404) | ||
| 51 | + end | ||
| 52 | + end | ||
| 53 | + | ||
| 54 | + # Update an existing project milestone | ||
| 55 | + # | ||
| 56 | + # Parameters: | ||
| 57 | + # id (required) - The ID or code name of a project | ||
| 58 | + # title (optional) - The title of a milestone | ||
| 59 | + # description (optional) - The description of a milestone | ||
| 60 | + # due_date (optional) - The due date of a milestone | ||
| 61 | + # closed (optional) - The status of the milestone | ||
| 62 | + # Example Request: | ||
| 63 | + # PUT /projects/:id/milestones/:milestone_id | ||
| 64 | + put ":id/milestones/:milestone_id" do | ||
| 65 | + @milestone = user_project.milestones.find(params[:milestone_id]) | ||
| 66 | + parameters = { | ||
| 67 | + title: (params[:title] || @milestone.title), | ||
| 68 | + description: (params[:description] || @milestone.description), | ||
| 69 | + due_date: (params[:due_date] || @milestone.due_date), | ||
| 70 | + closed: (params[:closed] || @milestone.closed) | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + if @milestone.update_attributes(parameters) | ||
| 74 | + present @milestone, with: Entities::Milestone | ||
| 75 | + else | ||
| 76 | + error!({'message' => '404 Not found'}, 404) | ||
| 77 | + end | ||
| 78 | + end | ||
| 79 | + end | ||
| 80 | + end | ||
| 81 | +end |
| @@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe Gitlab::API do | ||
| 4 | + let(:user) { Factory :user } | ||
| 5 | + let!(:project) { Factory :project, owner: user } | ||
| 6 | + let!(:milestone) { Factory :milestone, project: project } | ||
| 7 | + | ||
| 8 | + before { project.add_access(user, :read) } | ||
| 9 | + | ||
| 10 | + describe "GET /projects/:id/milestones" do | ||
| 11 | + it "should return project milestones" do | ||
| 12 | + get "#{api_prefix}/projects/#{project.code}/milestones?private_token=#{user.private_token}" | ||
| 13 | + response.status.should == 200 | ||
| 14 | + json_response.should be_an Array | ||
| 15 | + json_response.first['title'].should == milestone.title | ||
| 16 | + end | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + describe "GET /projects/:id/milestones/:milestone_id" do | ||
| 20 | + it "should return a project milestone by id" do | ||
| 21 | + get "#{api_prefix}/projects/#{project.code}/milestones/#{milestone.id}?private_token=#{user.private_token}" | ||
| 22 | + response.status.should == 200 | ||
| 23 | + json_response['title'].should == milestone.title | ||
| 24 | + end | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + describe "POST /projects/:id/milestones" do | ||
| 28 | + it "should create a new project milestone" do | ||
| 29 | + post "#{api_prefix}/projects/#{project.code}/milestones?private_token=#{user.private_token}", | ||
| 30 | + title: 'new milestone' | ||
| 31 | + response.status.should == 201 | ||
| 32 | + json_response['title'].should == 'new milestone' | ||
| 33 | + json_response['description'].should be_nil | ||
| 34 | + end | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | + describe "PUT /projects/:id/milestones/:milestone_id" do | ||
| 38 | + it "should update a project milestone" do | ||
| 39 | + put "#{api_prefix}/projects/#{project.code}/milestones/#{milestone.id}?private_token=#{user.private_token}", | ||
| 40 | + title: 'updated title' | ||
| 41 | + response.status.should == 200 | ||
| 42 | + json_response['title'].should == 'updated title' | ||
| 43 | + end | ||
| 44 | + end | ||
| 45 | +end |
spec/requests/api/issues_spec.rb
| @@ -65,9 +65,8 @@ describe Gitlab::API do | @@ -65,9 +65,8 @@ describe Gitlab::API do | ||
| 65 | 65 | ||
| 66 | describe "DELETE /projects/:id/issues/:issue_id" do | 66 | describe "DELETE /projects/:id/issues/:issue_id" do |
| 67 | it "should delete a project issue" do | 67 | it "should delete a project issue" do |
| 68 | - expect { | ||
| 69 | - delete api("/projects/#{project.code}/issues/#{issue.id}", user) | ||
| 70 | - }.to change { Issue.count }.by(-1) | 68 | + delete "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}" |
| 69 | + response.status.should == 405 | ||
| 71 | end | 70 | end |
| 72 | end | 71 | end |
| 73 | end | 72 | end |