Skip to content

Commit

Permalink
API: commits belong to project repository
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Sep 21, 2012
1 parent 1315536 commit 4a072be
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 102 deletions.
38 changes: 0 additions & 38 deletions doc/api/commits.md

This file was deleted.

34 changes: 34 additions & 0 deletions doc/api/projects.md
Expand Up @@ -355,6 +355,40 @@ Parameters:
]
```

## Project repository commits

Get a list of repository commits in a project.

```
GET /projects/:id/repository/commits
```

Parameters:

+ `id` (required) - The ID or code name of a project
+ `ref_name` (optional) - The name of a repository branch or tag

```json
[
{
"id": "ed899a2f4b50b4370feeea94676502b42383c746",
"short_id": "ed899a2f4b5",
"title": "Replace sanitize with escape once",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dzaporozhets@sphereconsultinginc.com",
"created_at": "2012-09-20T11:50:22+03:00"
},
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "randx",
"author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2012-09-20T09:06:12+03:00"
}
]
```

## Raw blob content

Get the raw file contents for a file.
Expand Down
1 change: 0 additions & 1 deletion lib/api.rb
Expand Up @@ -19,6 +19,5 @@ class API < Grape::API
mount Milestones
mount Keys
mount Session
mount Commits
end
end
29 changes: 0 additions & 29 deletions lib/api/commits.rb

This file was deleted.

9 changes: 4 additions & 5 deletions lib/api/entities.rb
Expand Up @@ -17,11 +17,6 @@ class Hook < Grape::Entity
expose :id, :url
end

class Commit < Grape::Entity
expose :id, :short_id, :title,
:author_name, :author_email, :created_at
end

class Project < Grape::Entity
expose :id, :code, :name, :description, :path, :default_branch
expose :owner, using: Entities::UserBasic
Expand All @@ -39,6 +34,10 @@ class RepoObject < Grape::Entity
expose :name, :commit
end

class RepoCommit < Grape::Entity
expose :id, :short_id, :title, :author_name, :author_email, :created_at
end

class ProjectSnippet < Grape::Entity
expose :id, :title, :file_name
expose :author, using: Entities::UserBasic
Expand Down
18 changes: 18 additions & 0 deletions lib/api/projects.rb
Expand Up @@ -211,6 +211,24 @@ class Projects < Grape::API
present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject
end

# Get a project repository commits
#
# Parameters:
# id (required) - The ID or code name of a project
# ref_name (optional) - The name of a repository branch or tag
# Example Request:
# GET /projects/:id/repository/commits
get ":id/repository/commits" do
authorize! :download_code, user_project

page = params[:page] || 0
per_page = params[:per_page] || 20
ref = params[:ref_name] || user_project.try(:default_branch) || 'master'

commits = user_project.commits(ref, nil, per_page, page * per_page)
present CommitDecorator.decorate(commits), with: Entities::RepoCommit
end

# Get a project snippet
#
# Parameters:
Expand Down
29 changes: 0 additions & 29 deletions spec/requests/api/commits_spec.rb

This file was deleted.

21 changes: 21 additions & 0 deletions spec/requests/api/projects_spec.rb
Expand Up @@ -199,6 +199,27 @@
end
end

describe "GET /projects/:id/repository/commits" do
context "authorized user" do
before { project.add_access(user2, :read) }

it "should return project commits" do
get api("/projects/#{project.code}/repository/commits", user)
response.status.should == 200

json_response.should be_an Array
json_response.first['id'].should == project.commit.id
end
end

context "unauthorized user" do
it "should not return project commits" do
get api("/projects/#{project.code}/repository/commits")
response.status.should == 401
end
end
end

describe "GET /projects/:id/snippets/:snippet_id" do
it "should return a project snippet" do
get api("/projects/#{project.code}/snippets/#{snippet.id}", user)
Expand Down

0 comments on commit 4a072be

Please sign in to comment.