forked from gitlabhq/gitlabhq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dmitriy Zaporozhets
committed
Sep 21, 2012
1 parent
4cc169d
commit 10d3a30
Showing
10 changed files
with
199 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,96 @@ | ||
%h3 API | ||
%h3.page_title API | ||
.back_link | ||
= link_to help_path do | ||
← to index | ||
%hr | ||
%br | ||
|
||
%ol | ||
%ul.nav.nav-tabs.log-tabs | ||
%li.active | ||
= link_to "README", "#README", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#README"} README | ||
= link_to "Projects", "#projects", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#projects"} Projects | ||
= link_to "Snippets", "#snippets", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#snippets"} Snippets | ||
= link_to "Users", "#users", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#users"} Users | ||
= link_to "Session", "#session", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#session"} Session | ||
= link_to "Issues", "#issues", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#issues"} Issues | ||
= link_to "Milestones", "#milestones", 'data-toggle' => 'tab' | ||
%li | ||
%a{href: "#milestones"} Milestones | ||
|
||
.file_holder#README | ||
.file_title | ||
%i.icon-file | ||
README | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "README.md")) | ||
|
||
%br | ||
|
||
.file_holder#projects | ||
.file_title | ||
%i.icon-file | ||
Projects | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "projects.md")) | ||
|
||
%br | ||
|
||
.file_holder#snippets | ||
.file_title | ||
%i.icon-file | ||
Projects Snippets | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "snippets.md")) | ||
= link_to "Commits", "#commits", 'data-toggle' => 'tab' | ||
|
||
%br | ||
.tab-content | ||
.tab-pane.active#README | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
README | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "README.md")) | ||
|
||
.file_holder#users | ||
.file_title | ||
%i.icon-file | ||
Users | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "users.md")) | ||
.tab-pane#projects | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Projects | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "projects.md")) | ||
|
||
%br | ||
.tab-pane#snippets | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Projects Snippets | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "snippets.md")) | ||
|
||
.file_holder#session | ||
.file_title | ||
%i.icon-file | ||
Session | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "session.md")) | ||
.tab-pane#users | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Users | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "users.md")) | ||
|
||
%br | ||
.tab-pane#session | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Session | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "session.md")) | ||
|
||
.file_holder#issues | ||
.file_title | ||
%i.icon-file | ||
Issues | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "issues.md")) | ||
.tab-pane#issues | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Issues | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "issues.md")) | ||
|
||
%br | ||
.tab-pane#milestones | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Milestones | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "milestones.md")) | ||
|
||
.file_holder#milestones | ||
.file_title | ||
%i.icon-file | ||
Milestones | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "milestones.md")) | ||
.tab-pane#commits | ||
.file_holder | ||
.file_title | ||
%i.icon-file | ||
Commits | ||
.file_content.wiki | ||
= preserve do | ||
= markdown File.read(Rails.root.join("doc", "api", "commits.md")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## List Commits | ||
|
||
Get a list of project commits. | ||
|
||
``` | ||
GET /projects/:id/commits | ||
``` | ||
|
||
Parameters: | ||
|
||
+ `id` (required) - The ID or code name of a project | ||
+ `ref_name` (optional) - branch/tag name | ||
+ `page` (optional) | ||
+ `per_page` (optional) | ||
|
||
|
||
```json | ||
|
||
[ | ||
{ | ||
"id": "ed899a2f4b50b4370feeea94676502b42383c746", | ||
"short_id": "ed899a2f4b5", | ||
"title": "Replace sanitize with escape once", | ||
"author_name": "Dmitriy Zaporozhets", | ||
"author_email": "[email protected]", | ||
"created_at": "2012-09-20T11:50:22+03:00" | ||
}, | ||
{ | ||
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", | ||
"short_id": "6104942438c", | ||
"title": "Sanitize for network graph", | ||
"author_name": "randx", | ||
"author_email": "[email protected]", | ||
"created_at": "2012-09-20T09:06:12+03:00" | ||
} | ||
] | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ class API < Grape::API | |
mount Milestones | ||
mount Keys | ||
mount Session | ||
mount Commits | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Gitlab | ||
# Commits API | ||
class Commits < Grape::API | ||
before { authenticate! } | ||
|
||
resource :projects do | ||
# Get a list of project commits | ||
# | ||
# Parameters: | ||
# id (required) - The ID or code name of a project | ||
# ref_name (optional) - Name of branch or tag | ||
# page (optional) - default is 0 | ||
# per_page (optional) - default is 20 | ||
# Example Request: | ||
# GET /projects/:id/commits | ||
get ":id/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::Commit | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
describe Gitlab::API do | ||
include ApiHelpers | ||
|
||
let(:user) { Factory :user } | ||
let!(:project) { Factory :project, owner: user } | ||
|
||
describe "GET /projects/:id/commits" do | ||
context "authorized user" do | ||
before { project.add_access(user, :read) } | ||
|
||
it "should return project commits" do | ||
get api("/projects/#{project.code}/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 return project commits" do | ||
get api("/projects/#{project.code}/commits") | ||
response.status.should == 401 | ||
end | ||
end | ||
end | ||
end |