Commit ffb0ad9399310795867c977e4a5bfb1884c8b9c6
Exists in
master
and in
4 other branches
Merge branch 'master' of github.com:gitlabhq/gitlabhq
Showing
5 changed files
with
100 additions
and
23 deletions
Show diff stats
app/views/profiles/keys/_form.html.haml
| @@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
| 13 | = f.label :key | 13 | = f.label :key |
| 14 | .controls | 14 | .controls |
| 15 | %p.light | 15 | %p.light |
| 16 | - Paste your public key here. Read more about how generate it #{link_to "here", help_ssh_path} | 16 | + Paste your public key here. Read more about how to generate a key on #{link_to "the SSH help page", help_ssh_path}. |
| 17 | = f.text_area :key, class: "input-xxlarge thin_area" | 17 | = f.text_area :key, class: "input-xxlarge thin_area" |
| 18 | 18 | ||
| 19 | 19 |
doc/api/repositories.md
| @@ -239,12 +239,37 @@ Parameters: | @@ -239,12 +239,37 @@ Parameters: | ||
| 239 | ] | 239 | ] |
| 240 | ``` | 240 | ``` |
| 241 | 241 | ||
| 242 | +## Get a single commit | ||
| 243 | + | ||
| 244 | +Get a specific commit identified by the commit hash or name of a branch or tag. | ||
| 245 | + | ||
| 246 | +``` | ||
| 247 | +GET /projects/:id/repository/commits/:sha | ||
| 248 | +``` | ||
| 249 | + | ||
| 250 | +Parameters: | ||
| 251 | + | ||
| 252 | ++ `id` (required) - The ID of a project | ||
| 253 | ++ `sha` (required) - The commit hash or name of a repository branch or tag | ||
| 254 | + | ||
| 255 | +```json | ||
| 256 | +{ | ||
| 257 | + "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", | ||
| 258 | + "short_id": "6104942438c", | ||
| 259 | + "title": "Sanitize for network graph", | ||
| 260 | + "author_name": "randx", | ||
| 261 | + "author_email": "dmitriy.zaporozhets@gmail.com", | ||
| 262 | + "created_at": "2012-09-20T09:06:12+03:00" | ||
| 263 | +} | ||
| 264 | +``` | ||
| 265 | + | ||
| 266 | + | ||
| 242 | ## Get the diff of a commit | 267 | ## Get the diff of a commit |
| 243 | 268 | ||
| 244 | Get the diff of a commit in a project. | 269 | Get the diff of a commit in a project. |
| 245 | 270 | ||
| 246 | ``` | 271 | ``` |
| 247 | -GET /projects/:id/repository/commit/:sha | 272 | +GET /projects/:id/repository/commits/:sha/diff |
| 248 | ``` | 273 | ``` |
| 249 | 274 | ||
| 250 | Parameters: | 275 | Parameters: |
| @@ -323,7 +348,7 @@ Parameters: | @@ -323,7 +348,7 @@ Parameters: | ||
| 323 | Get the raw file contents for a file. | 348 | Get the raw file contents for a file. |
| 324 | 349 | ||
| 325 | ``` | 350 | ``` |
| 326 | -GET /projects/:id/repository/commits/:sha/blob | 351 | +GET /projects/:id/repository/blobs/:sha |
| 327 | ``` | 352 | ``` |
| 328 | 353 | ||
| 329 | Parameters: | 354 | Parameters: |
lib/api/repositories.rb
| @@ -106,13 +106,29 @@ module API | @@ -106,13 +106,29 @@ module API | ||
| 106 | # | 106 | # |
| 107 | # Parameters: | 107 | # Parameters: |
| 108 | # id (required) - The ID of a project | 108 | # id (required) - The ID of a project |
| 109 | + # sha (required) - The commit hash or name of a repository branch or tag | ||
| 110 | + # Example Request: | ||
| 111 | + # GET /projects/:id/repository/commits/:sha | ||
| 112 | + get ":id/repository/commits/:sha" do | ||
| 113 | + authorize! :download_code, user_project | ||
| 114 | + sha = params[:sha] | ||
| 115 | + commit = user_project.repository.commit(sha) | ||
| 116 | + not_found! "Commit" unless commit | ||
| 117 | + present commit, with: Entities::RepoCommit | ||
| 118 | + end | ||
| 119 | + | ||
| 120 | + # Get the diff for a specific commit of a project | ||
| 121 | + # | ||
| 122 | + # Parameters: | ||
| 123 | + # id (required) - The ID of a project | ||
| 109 | # sha (required) - The commit or branch name | 124 | # sha (required) - The commit or branch name |
| 110 | # Example Request: | 125 | # Example Request: |
| 111 | - # GET /projects/:id/repository/commit/:sha | ||
| 112 | - get ":id/repository/commit/:sha" do | 126 | + # GET /projects/:id/repository/commits/:sha/diff |
| 127 | + get ":id/repository/commits/:sha/diff" do | ||
| 113 | authorize! :download_code, user_project | 128 | authorize! :download_code, user_project |
| 114 | sha = params[:sha] | 129 | sha = params[:sha] |
| 115 | result = CommitLoadContext.new(user_project, current_user, {id: sha}).execute | 130 | result = CommitLoadContext.new(user_project, current_user, {id: sha}).execute |
| 131 | + not_found! "Commit" unless result[:commit] | ||
| 116 | result[:commit].diffs | 132 | result[:commit].diffs |
| 117 | end | 133 | end |
| 118 | 134 | ||
| @@ -148,8 +164,8 @@ module API | @@ -148,8 +164,8 @@ module API | ||
| 148 | # sha (required) - The commit or branch name | 164 | # sha (required) - The commit or branch name |
| 149 | # filepath (required) - The path to the file to display | 165 | # filepath (required) - The path to the file to display |
| 150 | # Example Request: | 166 | # Example Request: |
| 151 | - # GET /projects/:id/repository/commits/:sha/blob | ||
| 152 | - get ":id/repository/commits/:sha/blob" do | 167 | + # GET /projects/:id/repository/blobs/:sha |
| 168 | + get [ ":id/repository/blobs/:sha", ":id/repository/commits/:sha/blob" ] do | ||
| 153 | authorize! :download_code, user_project | 169 | authorize! :download_code, user_project |
| 154 | required_attributes! [:filepath] | 170 | required_attributes! [:filepath] |
| 155 | 171 |
lib/tasks/gitlab/check.rake
| @@ -374,8 +374,8 @@ namespace :gitlab do | @@ -374,8 +374,8 @@ namespace :gitlab do | ||
| 374 | check_repo_base_is_not_symlink | 374 | check_repo_base_is_not_symlink |
| 375 | check_repo_base_user_and_group | 375 | check_repo_base_user_and_group |
| 376 | check_repo_base_permissions | 376 | check_repo_base_permissions |
| 377 | - check_post_receive_hook_is_up_to_date | ||
| 378 | - check_repos_post_receive_hooks_is_link | 377 | + check_update_hook_is_up_to_date |
| 378 | + check_repos_update_hooks_is_link | ||
| 379 | 379 | ||
| 380 | finished_checking "GitLab Shell" | 380 | finished_checking "GitLab Shell" |
| 381 | end | 381 | end |
| @@ -385,10 +385,10 @@ namespace :gitlab do | @@ -385,10 +385,10 @@ namespace :gitlab do | ||
| 385 | ######################## | 385 | ######################## |
| 386 | 386 | ||
| 387 | 387 | ||
| 388 | - def check_post_receive_hook_is_up_to_date | ||
| 389 | - print "post-receive hook up-to-date? ... " | 388 | + def check_update_hook_is_up_to_date |
| 389 | + print "update hook up-to-date? ... " | ||
| 390 | 390 | ||
| 391 | - hook_file = "post-receive" | 391 | + hook_file = "update" |
| 392 | gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path | 392 | gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path |
| 393 | gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) | 393 | gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) |
| 394 | gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user | 394 | gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user |
| @@ -494,10 +494,10 @@ namespace :gitlab do | @@ -494,10 +494,10 @@ namespace :gitlab do | ||
| 494 | end | 494 | end |
| 495 | end | 495 | end |
| 496 | 496 | ||
| 497 | - def check_repos_post_receive_hooks_is_link | ||
| 498 | - print "post-receive hooks in repos are links: ... " | 497 | + def check_repos_update_hooks_is_link |
| 498 | + print "update hooks in repos are links: ... " | ||
| 499 | 499 | ||
| 500 | - hook_file = "post-receive" | 500 | + hook_file = "update" |
| 501 | gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path | 501 | gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path |
| 502 | gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) | 502 | gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) |
| 503 | gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user | 503 | gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user |
spec/requests/api/repositories_spec.rb
| @@ -112,23 +112,51 @@ describe API::API do | @@ -112,23 +112,51 @@ describe API::API do | ||
| 112 | end | 112 | end |
| 113 | end | 113 | end |
| 114 | 114 | ||
| 115 | - describe "GET /projects:id/repository/commit/:sha" do | 115 | + describe "GET /projects:id/repository/commits/:sha" do |
| 116 | + context "authorized user" do | ||
| 117 | + it "should return a commit by sha" do | ||
| 118 | + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) | ||
| 119 | + response.status.should == 200 | ||
| 120 | + json_response['id'].should == project.repository.commit.id | ||
| 121 | + json_response['title'].should == project.repository.commit.title | ||
| 122 | + end | ||
| 123 | + | ||
| 124 | + it "should return a 404 error if not found" do | ||
| 125 | + get api("/projects/#{project.id}/repository/commits/invalid_sha", user) | ||
| 126 | + response.status.should == 404 | ||
| 127 | + end | ||
| 128 | + end | ||
| 129 | + | ||
| 130 | + context "unauthorized user" do | ||
| 131 | + it "should not return the selected commit" do | ||
| 132 | + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}") | ||
| 133 | + response.status.should == 401 | ||
| 134 | + end | ||
| 135 | + end | ||
| 136 | + end | ||
| 137 | + | ||
| 138 | + describe "GET /projects:id/repository/commits/:sha/diff" do | ||
| 116 | context "authorized user" do | 139 | context "authorized user" do |
| 117 | before { project.team << [user2, :reporter] } | 140 | before { project.team << [user2, :reporter] } |
| 118 | 141 | ||
| 119 | it "should return the diff of the selected commit" do | 142 | it "should return the diff of the selected commit" do |
| 120 | - get api("/projects/#{project.id}/repository/commit/#{project.repository.commit.id}", user) | 143 | + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user) |
| 121 | response.status.should == 200 | 144 | response.status.should == 200 |
| 122 | 145 | ||
| 123 | json_response.should be_an Array | 146 | json_response.should be_an Array |
| 124 | json_response.length.should >= 1 | 147 | json_response.length.should >= 1 |
| 125 | json_response.first.keys.should include "diff" | 148 | json_response.first.keys.should include "diff" |
| 126 | end | 149 | end |
| 150 | + | ||
| 151 | + it "should return a 404 error if invalid commit" do | ||
| 152 | + get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user) | ||
| 153 | + response.status.should == 404 | ||
| 154 | + end | ||
| 127 | end | 155 | end |
| 128 | 156 | ||
| 129 | context "unauthorized user" do | 157 | context "unauthorized user" do |
| 130 | it "should not return the diff of the selected commit" do | 158 | it "should not return the diff of the selected commit" do |
| 131 | - get api("/projects/#{project.id}/repository/commit/#{project.repository.commit.id}") | 159 | + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff") |
| 132 | response.status.should == 401 | 160 | response.status.should == 401 |
| 133 | end | 161 | end |
| 134 | end | 162 | end |
| @@ -157,25 +185,33 @@ describe API::API do | @@ -157,25 +185,33 @@ describe API::API do | ||
| 157 | end | 185 | end |
| 158 | end | 186 | end |
| 159 | 187 | ||
| 160 | - describe "GET /projects/:id/repository/commits/:sha/blob" do | 188 | + describe "GET /projects/:id/repository/blobs/:sha" do |
| 161 | it "should get the raw file contents" do | 189 | it "should get the raw file contents" do |
| 162 | - get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) | 190 | + get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user) |
| 163 | response.status.should == 200 | 191 | response.status.should == 200 |
| 164 | end | 192 | end |
| 165 | 193 | ||
| 166 | it "should return 404 for invalid branch_name" do | 194 | it "should return 404 for invalid branch_name" do |
| 167 | - get api("/projects/#{project.id}/repository/commits/invalid_branch_name/blob?filepath=README.md", user) | 195 | + get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user) |
| 168 | response.status.should == 404 | 196 | response.status.should == 404 |
| 169 | end | 197 | end |
| 170 | 198 | ||
| 171 | it "should return 404 for invalid file" do | 199 | it "should return 404 for invalid file" do |
| 172 | - get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.invalid", user) | 200 | + get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user) |
| 173 | response.status.should == 404 | 201 | response.status.should == 404 |
| 174 | end | 202 | end |
| 175 | 203 | ||
| 176 | it "should return a 400 error if filepath is missing" do | 204 | it "should return a 400 error if filepath is missing" do |
| 177 | - get api("/projects/#{project.id}/repository/commits/master/blob", user) | 205 | + get api("/projects/#{project.id}/repository/blobs/master", user) |
| 178 | response.status.should == 400 | 206 | response.status.should == 400 |
| 179 | end | 207 | end |
| 180 | end | 208 | end |
| 209 | + | ||
| 210 | + describe "GET /projects/:id/repository/commits/:sha/blob" do | ||
| 211 | + it "should get the raw file contents" do | ||
| 212 | + get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) | ||
| 213 | + response.status.should == 200 | ||
| 214 | + end | ||
| 215 | + end | ||
| 216 | + | ||
| 181 | end | 217 | end |