diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2016-01-11 14:09:01 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2016-01-11 14:09:01 +0100 |
commit | 13aef532194059711169ecde60d6c49810a8fd65 (patch) | |
tree | f24fde46c203cc332176a22553086065835ed715 | |
parent | 69bffa16348b28cfb796d366205217840852d483 (diff) | |
download | gitlab-ce-13aef532194059711169ecde60d6c49810a8fd65.tar.gz |
Modify commits API CI data, add CI data to merge_request API
-rw-r--r-- | app/models/commit.rb | 8 | ||||
-rw-r--r-- | doc/api/commits.md | 38 | ||||
-rw-r--r-- | doc/api/merge_requests.md | 18 | ||||
-rw-r--r-- | lib/api/entities.rb | 39 |
4 files changed, 32 insertions, 71 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 6b2771569d4..ecc396045f0 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -10,6 +10,8 @@ class Commit attr_mentionable :safe_message, pipeline: :single_line participant :author, :committer, :notes + delegate :duration, :started_at, :finished_at, :coverage, to: :ci_commit + attr_accessor :project # Safe amount of changes (files and lines) in one commit to render @@ -211,12 +213,6 @@ class Commit project.ci_commit(sha) if project end - def last_build - commit = ci_commit - return unless commit - commit.builds.order('id DESC').first - end - def status ci_commit.try(:status) || :not_found end diff --git a/doc/api/commits.md b/doc/api/commits.md index 11999dadfca..9bf3a7defbe 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -23,21 +23,7 @@ Parameters: "author_email": "dzaporozhets@sphereconsultinginc.com", "created_at": "2012-09-20T11:50:22+03:00", "message": "Replace sanitize with escape once", - "allow_failure": false, - "last_build": { - "allow_failure": false, - "coverage": null, - "created_at": "2016-01-05T15:33:25.936Z", - "deploy": false, - "description": null, - "finished_at": "2016-01-05T15:33:47.553Z", - "id": 66, - "name": "rubocop", - "stage": "test", - "started_at": null, - "status": "canceled", - "target_url": "http://gitlab.dev/root/gitlab-ce/builds/66" - } + "allow_failure": false }, { "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", @@ -47,8 +33,7 @@ Parameters: "author_email": "dmitriy.zaporozhets@gmail.com", "created_at": "2012-09-20T09:06:12+03:00", "message": "Sanitize for network graph", - "allow_failure": false, - "last_build": null + "allow_failure": false } ] ``` @@ -81,21 +66,10 @@ Parameters: "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], "status": "running", - last_build: { - "allow_failure": false, - "commands": "./scripts/prepare_build.sh\nruby -v\nwhich ruby\ngem install bundler --no-ri --no-rdoc\ncp config/gitlab.yml.example config/gitlab.yml\ntouch log/application.log\ntouch log/test.log\nbundle install --without postgres production --jobs $(nproc) \"${FLAGS[@]}\"\nbundle exec rake db:create RAILS_ENV=test\nbundle exec rubocop", - "coverage": null, - "created_at": "2016-01-05T15:33:25.936Z", - "deploy": false, - "description": null, - "finished_at": "2016-01-05T15:33:47.553Z", - "id": 66, - "name": "rubocop", - "stage": "test", - "started_at": null, - "status": "canceled", - "target_url": "http://gitlab.dev/root/gitlab-ce/builds/66" - } + "coverage": null, + "duration": 2, + "started_at": "2015-12-24T17:54:09.744Z", + "finished_at": "2016-01-11T10:14:09.526Z" } ``` diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index 8bc0a67067a..4f614026dab 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -50,7 +50,8 @@ Parameters: "created_at": "2012-04-29T08:46:00Z" }, "description":"fixed login page css paddings", - "work_in_progress": false + "work_in_progress": false, + "status": "pending" } ] ``` @@ -96,7 +97,8 @@ Parameters: "created_at": "2012-04-29T08:46:00Z" }, "description":"fixed login page css paddings", - "work_in_progress": false + "work_in_progress": false, + "status": "pending" } ``` @@ -204,7 +206,8 @@ Parameters: "renamed_file": false, "deleted_file": false } - ] + ], + "status": "pending" } ``` @@ -252,7 +255,8 @@ Parameters: "state": "active", "created_at": "2012-04-29T08:46:00Z" }, - "description":"fixed login page css paddings" + "description":"fixed login page css paddings", + "status": "pending" } ``` @@ -303,7 +307,8 @@ Parameters: "name": "Administrator", "state": "active", "created_at": "2012-04-29T08:46:00Z" - } + }, + "status": "pending" } ``` @@ -359,7 +364,8 @@ Parameters: "name": "Administrator", "state": "active", "created_at": "2012-04-29T08:46:00Z" - } + }, + "status": "pending" } ``` diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0368183bca6..680cc9765dc 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -126,35 +126,15 @@ module API end end - class RepoCommitBuild < Grape::Entity - expose :id - expose :name - expose :description - expose :stage - expose :coverage - expose :status - expose :allow_failure - expose :deploy - expose :created_at - expose :started_at - expose :finished_at - expose :target_url - end - - class RepoCommitDetailBuild < RepoCommitBuild - expose :commands - end - class RepoCommit < Grape::Entity expose :id, :short_id, :title, :author_name, :author_email, :created_at expose :safe_message, as: :message - expose :last_build, with: Entities::RepoCommitBuild end class RepoCommitDetail < RepoCommit expose :parent_ids, :committed_date, :authored_date expose :status - expose :last_build, with: Entities::RepoCommitDetailBuild + expose :started_at, :finished_at, :duration, :coverage end class ProjectSnippet < Grape::Entity @@ -185,6 +165,12 @@ module API expose :assignee, :author, using: Entities::UserBasic end + class CommitStatus < Grape::Entity + expose :id, :sha, :ref, :status, :name, :target_url, :description, + :created_at, :started_at, :finished_at, :allow_failure + expose :author, using: Entities::UserBasic + end + class MergeRequest < ProjectEntity expose :target_branch, :source_branch expose :upvotes, :downvotes @@ -195,6 +181,11 @@ module API expose :work_in_progress?, as: :work_in_progress expose :milestone, using: Entities::Milestone expose :merge_when_build_succeeds + expose :status do |repo_obj, _options| + if repo_obj.respond_to?(:ci_commit) + repo_obj.ci_commit.status if repo_obj.ci_commit + end + end end class MergeRequestChanges < MergeRequest @@ -238,12 +229,6 @@ module API expose :created_at end - class CommitStatus < Grape::Entity - expose :id, :sha, :ref, :status, :name, :target_url, :description, - :created_at, :started_at, :finished_at, :allow_failure - expose :author, using: Entities::UserBasic - end - class Event < Grape::Entity expose :title, :project_id, :action_name expose :target_id, :target_type, :author_id |