From 4a072be2d775d5ce59573cfb447ddab940854d54 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 21 Sep 2012 04:34:07 -0700 Subject: API: commits belong to project repository --- doc/api/commits.md | 38 -------------------------------------- doc/api/projects.md | 34 ++++++++++++++++++++++++++++++++++ lib/api.rb | 1 - lib/api/commits.rb | 29 ----------------------------- lib/api/entities.rb | 9 ++++----- lib/api/projects.rb | 18 ++++++++++++++++++ spec/requests/api/commits_spec.rb | 29 ----------------------------- spec/requests/api/projects_spec.rb | 21 +++++++++++++++++++++ 8 files changed, 77 insertions(+), 102 deletions(-) delete mode 100644 doc/api/commits.md delete mode 100644 lib/api/commits.rb delete mode 100644 spec/requests/api/commits_spec.rb diff --git a/doc/api/commits.md b/doc/api/commits.md deleted file mode 100644 index fccb35c3300..00000000000 --- a/doc/api/commits.md +++ /dev/null @@ -1,38 +0,0 @@ -## 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": "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" - } -] - -``` diff --git a/doc/api/projects.md b/doc/api/projects.md index 1e23df3ac89..2d67bfa9674 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -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. diff --git a/lib/api.rb b/lib/api.rb index f4e9e5fcc13..3b62f31bf32 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -19,6 +19,5 @@ module Gitlab mount Milestones mount Keys mount Session - mount Commits end end diff --git a/lib/api/commits.rb b/lib/api/commits.rb deleted file mode 100644 index 47d96fc4906..00000000000 --- a/lib/api/commits.rb +++ /dev/null @@ -1,29 +0,0 @@ -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 diff --git a/lib/api/entities.rb b/lib/api/entities.rb index fd19fa0e87f..ee6f15f1218 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -17,11 +17,6 @@ module Gitlab 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 @@ -39,6 +34,10 @@ module Gitlab 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 diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 0554d97c86b..c3dc3da6fac 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -211,6 +211,24 @@ module Gitlab 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: diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb deleted file mode 100644 index 3af5ec21c43..00000000000 --- a/spec/requests/api/commits_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -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 diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 40a9147d726..498bbad6179 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -199,6 +199,27 @@ describe Gitlab::API do 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) -- cgit v1.2.3 From b62445813dffec92e85540ed081e4d6e12d58dc0 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 21 Sep 2012 04:49:28 -0700 Subject: API: SSH keys belong to user entity --- doc/api/keys.md | 79 -------------------------------------- doc/api/users.md | 78 +++++++++++++++++++++++++++++++++++++ lib/api.rb | 1 - lib/api/entities.rb | 4 +- lib/api/keys.rb | 50 ------------------------ lib/api/users.rb | 59 +++++++++++++++++++++++++--- spec/requests/api/ssh_keys_spec.rb | 73 ----------------------------------- spec/requests/api/users_spec.rb | 63 +++++++++++++++++++++++++++++- 8 files changed, 195 insertions(+), 212 deletions(-) delete mode 100644 doc/api/keys.md delete mode 100644 lib/api/keys.rb delete mode 100644 spec/requests/api/ssh_keys_spec.rb diff --git a/doc/api/keys.md b/doc/api/keys.md deleted file mode 100644 index d22b22e20b8..00000000000 --- a/doc/api/keys.md +++ /dev/null @@ -1,79 +0,0 @@ -## List keys - -Get a list of currently authenticated user's keys. - -``` -GET /keys -``` - -```json -[ - { - "id": 1, - "title" : "Public key" - "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 - 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 - soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", - }, - { - "id": 3, - "title" : "Another Public key" - "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 - 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 - soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" - } -] -``` - -## Single key - -Get a single key. - -``` -GET /keys/:id -``` - -Parameters: - -+ `id` (required) - The ID of a key - -```json -{ - "id": 1, - "title" : "Public key" - "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 - 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 - soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" -} -``` -## Add key - -Create new key owned by currently authenticated user - -``` -POST /keys -``` - -Parameters: - -+ `title` (required) - new SSH Key's title -+ `key` (required) - new SSH key - -Will return created key with status `201 Created` on success, or `404 Not -found` on fail. - -## Delete key - -Delete key owned by currently authenticated user - -``` -DELETE /keys/:id -``` - -Parameters: - -+ `id` (required) - key ID - -Will return `200 OK` on success, or `404 Not Found` on fail. - - diff --git a/doc/api/users.md b/doc/api/users.md index b9b04dc5399..4f806b145d1 100644 --- a/doc/api/users.md +++ b/doc/api/users.md @@ -88,3 +88,81 @@ GET /user "theme_id": 1 } ``` + +## List SSH keys + +Get a list of currently authenticated user's SSH keys. + +``` +GET /user/keys +``` + +```json +[ + { + "id": 1, + "title" : "Public key" + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", + }, + { + "id": 3, + "title" : "Another Public key" + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" + } +] +``` + +## Single SSH key + +Get a single key. + +``` +GET /user/keys/:id +``` + +Parameters: + ++ `id` (required) - The ID of an SSH key + +```json +{ + "id": 1, + "title" : "Public key" + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" +} +``` +## Add SSH key + +Create new key owned by currently authenticated user + +``` +POST /user/keys +``` + +Parameters: + ++ `title` (required) - new SSH Key's title ++ `key` (required) - new SSH key + +Will return created key with status `201 Created` on success, or `404 Not +found` on fail. + +## Delete SSH key + +Delete key owned by currently authenticated user + +``` +DELETE /user/keys/:id +``` + +Parameters: + ++ `id` (required) - SSH key ID + +Will return `200 OK` on success, or `404 Not Found` on fail. diff --git a/lib/api.rb b/lib/api.rb index 3b62f31bf32..2890a8cc9e8 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -17,7 +17,6 @@ module Gitlab mount Projects mount Issues mount Milestones - mount Keys mount Session end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index ee6f15f1218..ee693de699e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -60,8 +60,8 @@ module Gitlab expose :closed, :updated_at, :created_at end - class Key < Grape::Entity - expose :id, :title, :key + class SSHKey < Grape::Entity + expose :id, :title, :key end end end diff --git a/lib/api/keys.rb b/lib/api/keys.rb deleted file mode 100644 index 4c302727c4f..00000000000 --- a/lib/api/keys.rb +++ /dev/null @@ -1,50 +0,0 @@ -module Gitlab - # Keys API - class Keys < Grape::API - before { authenticate! } - resource :keys do - # Get currently authenticated user's keys - # - # Example Request: - # GET /keys - get do - present current_user.keys, with: Entities::Key - end - # Get single key owned by currently authenticated user - # - # Example Request: - # GET /keys/:id - get "/:id" do - key = current_user.keys.find params[:id] - present key, with: Entities::Key - end - # Add new ssh key to currently authenticated user - # - # Parameters: - # key (required) - New SSH Key - # title (required) - New SSH Key's title - # Example Request: - # POST /keys - post do - attrs = attributes_for_keys [:title, :key] - key = current_user.keys.new attrs - if key.save - present key, with: Entities::Key - else - not_found! - end - end - # Delete existed ssh key of currently authenticated user - # - # Parameters: - # id (required) - SSH Key ID - # Example Request: - # DELETE /keys/:id - delete "/:id" do - key = current_user.keys.find params[:id] - key.delete - end - end - end -end - diff --git a/lib/api/users.rb b/lib/api/users.rb index 98ced6f8e5b..0ca8fb2a1ae 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -25,12 +25,59 @@ module Gitlab end end - # Get currently authenticated user - # - # Example Request: - # GET /user - get "/user" do - present @current_user, with: Entities::User + resource :user do + # Get currently authenticated user + # + # Example Request: + # GET /user + get do + present @current_user, with: Entities::User + end + + # Get currently authenticated user's keys + # + # Example Request: + # GET /user/keys + get "keys" do + present current_user.keys, with: Entities::SSHKey + end + + # Get single key owned by currently authenticated user + # + # Example Request: + # GET /user/keys/:id + get "keys/:id" do + key = current_user.keys.find params[:id] + present key, with: Entities::SSHKey + end + + # Add new ssh key to currently authenticated user + # + # Parameters: + # key (required) - New SSH Key + # title (required) - New SSH Key's title + # Example Request: + # POST /user/keys + post "keys" do + attrs = attributes_for_keys [:title, :key] + key = current_user.keys.new attrs + if key.save + present key, with: Entities::SSHKey + else + not_found! + end + end + + # Delete existed ssh key of currently authenticated user + # + # Parameters: + # id (required) - SSH Key ID + # Example Request: + # DELETE /user/keys/:id + delete "keys/:id" do + key = current_user.keys.find params[:id] + key.delete + end end end end diff --git a/spec/requests/api/ssh_keys_spec.rb b/spec/requests/api/ssh_keys_spec.rb deleted file mode 100644 index 7fb8c920fb1..00000000000 --- a/spec/requests/api/ssh_keys_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Keys do - include ApiHelpers - let(:user) { - user = Factory.create :user - user.reset_authentication_token! - user - } - let(:key) { Factory.create :key, { user: user}} - - describe "GET /keys" do - context "when unauthenticated" do - it "should return authentication error" do - get api("/keys") - response.status.should == 401 - end - end - context "when authenticated" do - it "should return array of ssh keys" do - user.keys << key - user.save - get api("/keys", user) - response.status.should == 200 - json_response.should be_an Array - json_response.first["title"].should == key.title - end - end - end - - describe "GET /keys/:id" do - it "should returm single key" do - user.keys << key - user.save - get api("/keys/#{key.id}", user) - response.status.should == 200 - json_response["title"].should == key.title - end - it "should return 404 Not Found within invalid ID" do - get api("/keys/42", user) - response.status.should == 404 - end - end - - describe "POST /keys" do - it "should not create invalid ssh key" do - post api("/keys", user), { title: "invalid key" } - response.status.should == 404 - end - it "should create ssh key" do - key_attrs = Factory.attributes :key - expect { - post api("/keys", user), key_attrs - }.to change{ user.keys.count }.by(1) - end - end - - describe "DELETE /keys/:id" do - it "should delete existed key" do - user.keys << key - user.save - expect { - delete api("/keys/#{key.id}", user) - }.to change{user.keys.count}.by(-1) - end - it "should return 404 Not Found within invalid ID" do - delete api("/keys/42", user) - response.status.should == 404 - end - end - -end - diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index e25fe1341d5..5d7ef99c481 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' describe Gitlab::API do include ApiHelpers - let(:user) { Factory :user } + let(:user) { Factory :user } + let(:key) { Factory :key, user: user } describe "GET /users" do context "when unauthenticated" do @@ -38,4 +39,64 @@ describe Gitlab::API do json_response['email'].should == user.email end end + + describe "GET /user/keys" do + context "when unauthenticated" do + it "should return authentication error" do + get api("/user/keys") + response.status.should == 401 + end + end + context "when authenticated" do + it "should return array of ssh keys" do + user.keys << key + user.save + get api("/user/keys", user) + response.status.should == 200 + json_response.should be_an Array + json_response.first["title"].should == key.title + end + end + end + + describe "GET /user/keys/:id" do + it "should returm single key" do + user.keys << key + user.save + get api("/user/keys/#{key.id}", user) + response.status.should == 200 + json_response["title"].should == key.title + end + it "should return 404 Not Found within invalid ID" do + get api("/user/keys/42", user) + response.status.should == 404 + end + end + + describe "POST /user/keys" do + it "should not create invalid ssh key" do + post api("/user/keys", user), { title: "invalid key" } + response.status.should == 404 + end + it "should create ssh key" do + key_attrs = Factory.attributes :key + expect { + post api("/user/keys", user), key_attrs + }.to change{ user.keys.count }.by(1) + end + end + + describe "DELETE /user/keys/:id" do + it "should delete existed key" do + user.keys << key + user.save + expect { + delete api("/user/keys/#{key.id}", user) + }.to change{user.keys.count}.by(-1) + end + it "should return 404 Not Found within invalid ID" do + delete api("/user/keys/42", user) + response.status.should == 404 + end + end end -- cgit v1.2.3 From 1bae64d7f608e3d68d52fd59755216db6c70f7f4 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 21 Sep 2012 04:53:13 -0700 Subject: whitespace --- spec/requests/api/users_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 5d7ef99c481..243f70f5230 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -47,6 +47,7 @@ describe Gitlab::API do response.status.should == 401 end end + context "when authenticated" do it "should return array of ssh keys" do user.keys << key @@ -67,6 +68,7 @@ describe Gitlab::API do response.status.should == 200 json_response["title"].should == key.title end + it "should return 404 Not Found within invalid ID" do get api("/user/keys/42", user) response.status.should == 404 @@ -78,6 +80,7 @@ describe Gitlab::API do post api("/user/keys", user), { title: "invalid key" } response.status.should == 404 end + it "should create ssh key" do key_attrs = Factory.attributes :key expect { @@ -94,6 +97,7 @@ describe Gitlab::API do delete api("/user/keys/#{key.id}", user) }.to change{user.keys.count}.by(-1) end + it "should return 404 Not Found within invalid ID" do delete api("/user/keys/42", user) response.status.should == 404 -- cgit v1.2.3 From 130433158981bd4f95121060d75d8fb56c14f80d Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 21 Sep 2012 05:00:20 -0700 Subject: remove commits API section from help --- app/views/help/api.html.haml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/views/help/api.html.haml b/app/views/help/api.html.haml index 1f0ce879381..d317bfa7bfe 100644 --- a/app/views/help/api.html.haml +++ b/app/views/help/api.html.haml @@ -19,8 +19,6 @@ = link_to "Issues", "#issues", 'data-toggle' => 'tab' %li = link_to "Milestones", "#milestones", 'data-toggle' => 'tab' - %li - = link_to "Commits", "#commits", 'data-toggle' => 'tab' .tab-content .tab-pane.active#README @@ -85,12 +83,3 @@ .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")) -- cgit v1.2.3 From 4162566e11d9239d82b532e34c503ad1cbfe4d78 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 21 Sep 2012 05:03:50 -0700 Subject: separate project repositories API docs --- app/views/help/api.html.haml | 11 +++ doc/api/projects.md | 166 ------------------------------------------- doc/api/repositories.md | 166 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 166 deletions(-) create mode 100644 doc/api/repositories.md diff --git a/app/views/help/api.html.haml b/app/views/help/api.html.haml index d317bfa7bfe..00085166bcf 100644 --- a/app/views/help/api.html.haml +++ b/app/views/help/api.html.haml @@ -11,6 +11,8 @@ = link_to "Projects", "#projects", 'data-toggle' => 'tab' %li = link_to "Snippets", "#snippets", 'data-toggle' => 'tab' + %li + = link_to "Repositories", "#repositories", 'data-toggle' => 'tab' %li = link_to "Users", "#users", 'data-toggle' => 'tab' %li @@ -48,6 +50,15 @@ = preserve do = markdown File.read(Rails.root.join("doc", "api", "snippets.md")) + .tab-pane#repositories + .file_holder + .file_title + %i.icon-file + Projects + .file_content.wiki + = preserve do + = markdown File.read(Rails.root.join("doc", "api", "repositories.md")) + .tab-pane#users .file_holder .file_title diff --git a/doc/api/projects.md b/doc/api/projects.md index 2d67bfa9674..d06a41c2d74 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -239,169 +239,3 @@ Parameters: + `hook_id` (required) - The ID of hook to delete Will return status `200 OK` on success, or `404 Not found` on fail. - -## Project repository branches - -Get a list of repository branches from a project, sorted by name alphabetically. - -``` -GET /projects/:id/repository/branches -``` - -Parameters: - -+ `id` (required) - The ID or code name of a project - -```json -[ - { - "name": "master", - "commit": { - "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", - "parents": [ - { - "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" - } - ], - "tree": "46e82de44b1061621357f24c05515327f2795a95", - "message": "add projects API", - "author": { - "name": "John Smith", - "email": "john@example.com" - }, - "committer": { - "name": "John Smith", - "email": "john@example.com" - }, - "authored_date": "2012-06-27T05:51:39-07:00", - "committed_date": "2012-06-28T03:44:20-07:00" - } - } -] -``` - -Get a single project repository branch. - -``` -GET /projects/:id/repository/branches/:branch -``` - -Parameters: - -+ `id` (required) - The ID or code name of a project -+ `branch` (required) - The name of the branch - -```json -{ - "name": "master", - "commit": { - "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", - "parents": [ - { - "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" - } - ], - "tree": "46e82de44b1061621357f24c05515327f2795a95", - "message": "add projects API", - "author": { - "name": "John Smith", - "email": "john@example.com" - }, - "committer": { - "name": "John Smith", - "email": "john@example.com" - }, - "authored_date": "2012-06-27T05:51:39-07:00", - "committed_date": "2012-06-28T03:44:20-07:00" - } -} -``` - -## Project repository tags - -Get a list of repository tags from a project, sorted by name in reverse alphabetical order. - -``` -GET /projects/:id/repository/tags -``` - -Parameters: - -+ `id` (required) - The ID or code name of a project - -```json -[ - { - "name": "v1.0.0", - "commit": { - "id": "2695effb5807a22ff3d138d593fd856244e155e7", - "parents": [ - - ], - "tree": "38017f2f189336fe4497e9d230c5bb1bf873f08d", - "message": "Initial commit", - "author": { - "name": "John Smith", - "email": "john@example.com" - }, - "committer": { - "name": "Jack Smith", - "email": "jack@example.com" - }, - "authored_date": "2012-05-28T04:42:42-07:00", - "committed_date": "2012-05-28T04:42:42-07:00" - } - } -] -``` - -## 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. - -``` -GET /projects/:id/repository/commits/:sha/blob -``` - -Parameters: - -+ `id` (required) - The ID or code name of a project -+ `sha` (required) - The commit or branch name -+ `filepath` (required) - The path the file - -Will return the raw file contents. - diff --git a/doc/api/repositories.md b/doc/api/repositories.md new file mode 100644 index 00000000000..487ad9b2718 --- /dev/null +++ b/doc/api/repositories.md @@ -0,0 +1,166 @@ +## Project repository branches + +Get a list of repository branches from a project, sorted by name alphabetically. + +``` +GET /projects/:id/repository/branches +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project + +```json +[ + { + "name": "master", + "commit": { + "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", + "parents": [ + { + "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" + } + ], + "tree": "46e82de44b1061621357f24c05515327f2795a95", + "message": "add projects API", + "author": { + "name": "John Smith", + "email": "john@example.com" + }, + "committer": { + "name": "John Smith", + "email": "john@example.com" + }, + "authored_date": "2012-06-27T05:51:39-07:00", + "committed_date": "2012-06-28T03:44:20-07:00" + } + } +] +``` + +## Project repository branch + +Get a single project repository branch. + +``` +GET /projects/:id/repository/branches/:branch +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `branch` (required) - The name of the branch + +```json +{ + "name": "master", + "commit": { + "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", + "parents": [ + { + "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" + } + ], + "tree": "46e82de44b1061621357f24c05515327f2795a95", + "message": "add projects API", + "author": { + "name": "John Smith", + "email": "john@example.com" + }, + "committer": { + "name": "John Smith", + "email": "john@example.com" + }, + "authored_date": "2012-06-27T05:51:39-07:00", + "committed_date": "2012-06-28T03:44:20-07:00" + } +} +``` + +## Project repository tags + +Get a list of repository tags from a project, sorted by name in reverse alphabetical order. + +``` +GET /projects/:id/repository/tags +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project + +```json +[ + { + "name": "v1.0.0", + "commit": { + "id": "2695effb5807a22ff3d138d593fd856244e155e7", + "parents": [ + + ], + "tree": "38017f2f189336fe4497e9d230c5bb1bf873f08d", + "message": "Initial commit", + "author": { + "name": "John Smith", + "email": "john@example.com" + }, + "committer": { + "name": "Jack Smith", + "email": "jack@example.com" + }, + "authored_date": "2012-05-28T04:42:42-07:00", + "committed_date": "2012-05-28T04:42:42-07:00" + } + } +] +``` + +## 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. + +``` +GET /projects/:id/repository/commits/:sha/blob +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `sha` (required) - The commit or branch name ++ `filepath` (required) - The path the file + +Will return the raw file contents. -- cgit v1.2.3 From bbdb2c3fef5a71802131c08226d7f4dfa18ddd89 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 21 Sep 2012 05:06:36 -0700 Subject: fix links in API README --- doc/api/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/README.md b/doc/api/README.md index 443ec7bf1ca..36a36f8f6a4 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -33,6 +33,6 @@ When listing resources you can pass the following parameters: + [Session](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/session.md) + [Projects](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md) + [Snippets](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md) ++ [Repositories](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repositories.md) + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md) + [Milestones](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md) -+ [SSH Keys](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/keys.md) -- cgit v1.2.3