summaryrefslogtreecommitdiff
path: root/lib/api/repositories.rb
diff options
context:
space:
mode:
authorAlex Van't Hof <alexvh@cs.columbia.edu>2013-08-27 21:22:42 -0400
committerAlex Van't Hof <alexvh@cs.columbia.edu>2013-08-27 21:22:42 -0400
commit59f428dca20228984e9f50c33b12f54eb15638e5 (patch)
tree8ba21e90e3e2709ab831f1afe266620abe1d57d5 /lib/api/repositories.rb
parent79f0858a18081d37669883f1b5a32d033197561d (diff)
downloadgitlab-ce-59f428dca20228984e9f50c33b12f54eb15638e5.tar.gz
Standardize commit diff api url, change blob api url, add get single commit
Use "/commits/:sha/diff" as opposed to "/commit/:sha", keeping in line with existing api urls (e.g. "/projects/:id", etc.) Fix 500 error resulting from a diff api call with an invalid commit hash Move "/commits/:sha/blob" to "/blobs/:sha", leaving the old path for backwards compatibility. Add ability to get a single commit via "/commits/:sha"
Diffstat (limited to 'lib/api/repositories.rb')
-rw-r--r--lib/api/repositories.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 7e806546d02..fef32d3a2fe 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -106,13 +106,29 @@ module API
#
# Parameters:
# id (required) - The ID of a project
+ # sha (required) - The commit hash or name of a repository branch or tag
+ # Example Request:
+ # GET /projects/:id/repository/commits/:sha
+ get ":id/repository/commits/:sha" do
+ authorize! :download_code, user_project
+ sha = params[:sha]
+ commit = user_project.repository.commit(sha)
+ not_found! "Commit" unless commit
+ present commit, with: Entities::RepoCommit
+ end
+
+ # Get the diff for a specific commit of a project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
# sha (required) - The commit or branch name
# Example Request:
- # GET /projects/:id/repository/commit/:sha
- get ":id/repository/commit/:sha" do
+ # GET /projects/:id/repository/commits/:sha/diff
+ get ":id/repository/commits/:sha/diff" do
authorize! :download_code, user_project
sha = params[:sha]
result = CommitLoadContext.new(user_project, current_user, {id: sha}).execute
+ not_found! "Commit" unless result[:commit]
result[:commit].diffs
end
@@ -148,8 +164,8 @@ module API
# sha (required) - The commit or branch name
# filepath (required) - The path to the file to display
# Example Request:
- # GET /projects/:id/repository/commits/:sha/blob
- get ":id/repository/commits/:sha/blob" do
+ # GET /projects/:id/repository/blobs/:sha
+ get [ ":id/repository/blobs/:sha", ":id/repository/commits/:sha/blob" ] do
authorize! :download_code, user_project
required_attributes! [:filepath]