From dcde3aa369aa7afeeb4df97f7f641b079e8bf16f Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 24 Jun 2013 20:54:22 +0600 Subject: [PATCH] [#105] add files action --- .../api/v1/pull_requests_controller.rb | 4 ++++ .../api/v1/pull_requests/files.json.jbuilder | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 app/views/api/v1/pull_requests/files.json.jbuilder diff --git a/app/controllers/api/v1/pull_requests_controller.rb b/app/controllers/api/v1/pull_requests_controller.rb index 1be40786c..39505d28f 100644 --- a/app/controllers/api/v1/pull_requests_controller.rb +++ b/app/controllers/api/v1/pull_requests_controller.rb @@ -97,6 +97,10 @@ class Api::V1::PullRequestsController < Api::V1::BaseController @commits.paginate(paginate_params) end + def files + @stats = @pull.diff_stats.zip(@pull.diff) + end + private def render_pulls_list diff --git a/app/views/api/v1/pull_requests/files.json.jbuilder b/app/views/api/v1/pull_requests/files.json.jbuilder new file mode 100644 index 000000000..8070b0271 --- /dev/null +++ b/app/views/api/v1/pull_requests/files.json.jbuilder @@ -0,0 +1,24 @@ +json.files @stats do |json_stat, stat| + fstat, diff = stat + commit_id = diff.deleted_file ? @pull.to_commit.id : @pull.from_commit.id + json_stat.sha commit_id + json_stat.filename diff.b_path + status = case + when diff.new_file + 'added' + when diff.deleted_file + 'deleted' + when diff.renamed_file + 'renamed' + else + 'modified' + end + json_stat.status status + json_stat.additions fstat.additions + json_stat.deletions fstat.deletions + json_stat.changes fstat.additions + fstat.deletions + json_stat.blob_https_url blob_path(@project, commit_id, diff.b_path) + json_stat.raw_https_url raw_path(@project, commit_id, diff.b_path) +end + +json.url files_api_v1_project_pull_request_path(:format => :json)