Commit 4a072be2d775d5ce59573cfb447ddab940854d54
1 parent
13155362
Exists in
master
and in
4 other branches
API: commits belong to project repository
Showing
8 changed files
with
77 additions
and
102 deletions
Show diff stats
doc/api/commits.md
| ... | ... | @@ -1,38 +0,0 @@ |
| 1 | -## List Commits | |
| 2 | - | |
| 3 | -Get a list of project commits. | |
| 4 | - | |
| 5 | -``` | |
| 6 | -GET /projects/:id/commits | |
| 7 | -``` | |
| 8 | - | |
| 9 | -Parameters: | |
| 10 | - | |
| 11 | -+ `id` (required) - The ID or code name of a project | |
| 12 | -+ `ref_name` (optional) - branch/tag name | |
| 13 | -+ `page` (optional) | |
| 14 | -+ `per_page` (optional) | |
| 15 | - | |
| 16 | - | |
| 17 | -```json | |
| 18 | - | |
| 19 | -[ | |
| 20 | - { | |
| 21 | - "id": "ed899a2f4b50b4370feeea94676502b42383c746", | |
| 22 | - "short_id": "ed899a2f4b5", | |
| 23 | - "title": "Replace sanitize with escape once", | |
| 24 | - "author_name": "Dmitriy Zaporozhets", | |
| 25 | - "author_email": "dzaporozhets@sphereconsultinginc.com", | |
| 26 | - "created_at": "2012-09-20T11:50:22+03:00" | |
| 27 | - }, | |
| 28 | - { | |
| 29 | - "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", | |
| 30 | - "short_id": "6104942438c", | |
| 31 | - "title": "Sanitize for network graph", | |
| 32 | - "author_name": "randx", | |
| 33 | - "author_email": "dmitriy.zaporozhets@gmail.com", | |
| 34 | - "created_at": "2012-09-20T09:06:12+03:00" | |
| 35 | - } | |
| 36 | -] | |
| 37 | - | |
| 38 | -``` |
doc/api/projects.md
| ... | ... | @@ -355,6 +355,40 @@ Parameters: |
| 355 | 355 | ] |
| 356 | 356 | ``` |
| 357 | 357 | |
| 358 | +## Project repository commits | |
| 359 | + | |
| 360 | +Get a list of repository commits in a project. | |
| 361 | + | |
| 362 | +``` | |
| 363 | +GET /projects/:id/repository/commits | |
| 364 | +``` | |
| 365 | + | |
| 366 | +Parameters: | |
| 367 | + | |
| 368 | ++ `id` (required) - The ID or code name of a project | |
| 369 | ++ `ref_name` (optional) - The name of a repository branch or tag | |
| 370 | + | |
| 371 | +```json | |
| 372 | +[ | |
| 373 | + { | |
| 374 | + "id": "ed899a2f4b50b4370feeea94676502b42383c746", | |
| 375 | + "short_id": "ed899a2f4b5", | |
| 376 | + "title": "Replace sanitize with escape once", | |
| 377 | + "author_name": "Dmitriy Zaporozhets", | |
| 378 | + "author_email": "dzaporozhets@sphereconsultinginc.com", | |
| 379 | + "created_at": "2012-09-20T11:50:22+03:00" | |
| 380 | + }, | |
| 381 | + { | |
| 382 | + "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", | |
| 383 | + "short_id": "6104942438c", | |
| 384 | + "title": "Sanitize for network graph", | |
| 385 | + "author_name": "randx", | |
| 386 | + "author_email": "dmitriy.zaporozhets@gmail.com", | |
| 387 | + "created_at": "2012-09-20T09:06:12+03:00" | |
| 388 | + } | |
| 389 | +] | |
| 390 | +``` | |
| 391 | + | |
| 358 | 392 | ## Raw blob content |
| 359 | 393 | |
| 360 | 394 | Get the raw file contents for a file. | ... | ... |
lib/api.rb
lib/api/commits.rb
| ... | ... | @@ -1,29 +0,0 @@ |
| 1 | -module Gitlab | |
| 2 | - # Commits API | |
| 3 | - class Commits < Grape::API | |
| 4 | - before { authenticate! } | |
| 5 | - | |
| 6 | - resource :projects do | |
| 7 | - # Get a list of project commits | |
| 8 | - # | |
| 9 | - # Parameters: | |
| 10 | - # id (required) - The ID or code name of a project | |
| 11 | - # ref_name (optional) - Name of branch or tag | |
| 12 | - # page (optional) - default is 0 | |
| 13 | - # per_page (optional) - default is 20 | |
| 14 | - # Example Request: | |
| 15 | - # GET /projects/:id/commits | |
| 16 | - get ":id/commits" do | |
| 17 | - authorize! :download_code, user_project | |
| 18 | - | |
| 19 | - page = params[:page] || 0 | |
| 20 | - per_page = params[:per_page] || 20 | |
| 21 | - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' | |
| 22 | - | |
| 23 | - commits = user_project.commits(ref, nil, per_page, page * per_page) | |
| 24 | - | |
| 25 | - present CommitDecorator.decorate(commits), with: Entities::Commit | |
| 26 | - end | |
| 27 | - end | |
| 28 | - end | |
| 29 | -end |
lib/api/entities.rb
| ... | ... | @@ -17,11 +17,6 @@ module Gitlab |
| 17 | 17 | expose :id, :url |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | - class Commit < Grape::Entity | |
| 21 | - expose :id, :short_id, :title, | |
| 22 | - :author_name, :author_email, :created_at | |
| 23 | - end | |
| 24 | - | |
| 25 | 20 | class Project < Grape::Entity |
| 26 | 21 | expose :id, :code, :name, :description, :path, :default_branch |
| 27 | 22 | expose :owner, using: Entities::UserBasic |
| ... | ... | @@ -39,6 +34,10 @@ module Gitlab |
| 39 | 34 | expose :name, :commit |
| 40 | 35 | end |
| 41 | 36 | |
| 37 | + class RepoCommit < Grape::Entity | |
| 38 | + expose :id, :short_id, :title, :author_name, :author_email, :created_at | |
| 39 | + end | |
| 40 | + | |
| 42 | 41 | class ProjectSnippet < Grape::Entity |
| 43 | 42 | expose :id, :title, :file_name |
| 44 | 43 | expose :author, using: Entities::UserBasic | ... | ... |
lib/api/projects.rb
| ... | ... | @@ -211,6 +211,24 @@ module Gitlab |
| 211 | 211 | present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject |
| 212 | 212 | end |
| 213 | 213 | |
| 214 | + # Get a project repository commits | |
| 215 | + # | |
| 216 | + # Parameters: | |
| 217 | + # id (required) - The ID or code name of a project | |
| 218 | + # ref_name (optional) - The name of a repository branch or tag | |
| 219 | + # Example Request: | |
| 220 | + # GET /projects/:id/repository/commits | |
| 221 | + get ":id/repository/commits" do | |
| 222 | + authorize! :download_code, user_project | |
| 223 | + | |
| 224 | + page = params[:page] || 0 | |
| 225 | + per_page = params[:per_page] || 20 | |
| 226 | + ref = params[:ref_name] || user_project.try(:default_branch) || 'master' | |
| 227 | + | |
| 228 | + commits = user_project.commits(ref, nil, per_page, page * per_page) | |
| 229 | + present CommitDecorator.decorate(commits), with: Entities::RepoCommit | |
| 230 | + end | |
| 231 | + | |
| 214 | 232 | # Get a project snippet |
| 215 | 233 | # |
| 216 | 234 | # Parameters: | ... | ... |
spec/requests/api/commits_spec.rb
| ... | ... | @@ -1,29 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe Gitlab::API do | |
| 4 | - include ApiHelpers | |
| 5 | - | |
| 6 | - let(:user) { Factory :user } | |
| 7 | - let!(:project) { Factory :project, owner: user } | |
| 8 | - | |
| 9 | - describe "GET /projects/:id/commits" do | |
| 10 | - context "authorized user" do | |
| 11 | - before { project.add_access(user, :read) } | |
| 12 | - | |
| 13 | - it "should return project commits" do | |
| 14 | - get api("/projects/#{project.code}/commits", user) | |
| 15 | - response.status.should == 200 | |
| 16 | - | |
| 17 | - json_response.should be_an Array | |
| 18 | - json_response.first['id'].should == project.commit.id | |
| 19 | - end | |
| 20 | - end | |
| 21 | - | |
| 22 | - context "unauthorized user" do | |
| 23 | - it "should return project commits" do | |
| 24 | - get api("/projects/#{project.code}/commits") | |
| 25 | - response.status.should == 401 | |
| 26 | - end | |
| 27 | - end | |
| 28 | - end | |
| 29 | -end |
spec/requests/api/projects_spec.rb
| ... | ... | @@ -199,6 +199,27 @@ describe Gitlab::API do |
| 199 | 199 | end |
| 200 | 200 | end |
| 201 | 201 | |
| 202 | + describe "GET /projects/:id/repository/commits" do | |
| 203 | + context "authorized user" do | |
| 204 | + before { project.add_access(user2, :read) } | |
| 205 | + | |
| 206 | + it "should return project commits" do | |
| 207 | + get api("/projects/#{project.code}/repository/commits", user) | |
| 208 | + response.status.should == 200 | |
| 209 | + | |
| 210 | + json_response.should be_an Array | |
| 211 | + json_response.first['id'].should == project.commit.id | |
| 212 | + end | |
| 213 | + end | |
| 214 | + | |
| 215 | + context "unauthorized user" do | |
| 216 | + it "should not return project commits" do | |
| 217 | + get api("/projects/#{project.code}/repository/commits") | |
| 218 | + response.status.should == 401 | |
| 219 | + end | |
| 220 | + end | |
| 221 | + end | |
| 222 | + | |
| 202 | 223 | describe "GET /projects/:id/snippets/:snippet_id" do |
| 203 | 224 | it "should return a project snippet" do |
| 204 | 225 | get api("/projects/#{project.code}/snippets/#{snippet.id}", user) | ... | ... |