From 979c04e60086bfd15ba477503b8553bbfd8fabd6 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 31 Dec 2015 11:44:20 +0100 Subject: [PATCH 01/10] Add 'last_build' informations to commits list/details in API --- app/models/commit.rb | 6 ++++++ lib/api/entities.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/models/commit.rb b/app/models/commit.rb index 0ba7b584d911..d200639f890c 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -211,6 +211,12 @@ def ci_commit project.ci_commit(sha) 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/lib/api/entities.rb b/lib/api/entities.rb index 26e7c956e8f7..0368183bca6b 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -126,14 +126,35 @@ class RepoTreeObject < Grape::Entity 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 end class ProjectSnippet < Grape::Entity -- GitLab From 531d79a1b3191b34a8844f9d58383003aafbe63b Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 31 Dec 2015 12:45:10 +0100 Subject: [PATCH 02/10] Fix "undefined method `ci_commit' for nil:NilClass" in Commit model --- app/models/commit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/commit.rb b/app/models/commit.rb index d200639f890c..6b2771569d4e 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -208,7 +208,7 @@ def short_id end def ci_commit - project.ci_commit(sha) + project.ci_commit(sha) if project end def last_build -- GitLab From 69bffa16348b28cfb796d366205217840852d483 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 7 Jan 2016 10:17:49 +0100 Subject: [PATCH 03/10] Update ./doc/api --- doc/api/commits.md | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/api/commits.md b/doc/api/commits.md index 93d62b751e66..11999dadfcae 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -23,7 +23,21 @@ Parameters: "author_email": "dzaporozhets@sphereconsultinginc.com", "created_at": "2012-09-20T11:50:22+03:00", "message": "Replace sanitize with escape once", - "allow_failure": false + "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" + } }, { "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", @@ -33,7 +47,8 @@ Parameters: "author_email": "dmitriy.zaporozhets@gmail.com", "created_at": "2012-09-20T09:06:12+03:00", "message": "Sanitize for network graph", - "allow_failure": false + "allow_failure": false, + "last_build": null } ] ``` @@ -65,7 +80,22 @@ Parameters: "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], - "status": "running" + "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" + } } ``` -- GitLab From 13aef532194059711169ecde60d6c49810a8fd65 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Mon, 11 Jan 2016 14:09:01 +0100 Subject: [PATCH 04/10] Modify commits API CI data, add CI data to merge_request API --- app/models/commit.rb | 8 ++------ doc/api/commits.md | 38 ++++++-------------------------------- doc/api/merge_requests.md | 18 ++++++++++++------ 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 6b2771569d4e..ecc396045f0f 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 @@ def ci_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 11999dadfcae..9bf3a7defbe3 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 8bc0a67067a1..4f614026dab0 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 0368183bca6b..680cc9765dc7 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -126,35 +126,15 @@ class RepoTreeObject < Grape::Entity 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 @@ class Issue < ProjectEntity 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 @@ class MergeRequest < ProjectEntity 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 @@ class CommitNote < Grape::Entity 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 -- GitLab From ac5b250fab83f5daace9fe99f61fcc33f3a0ed4d Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Mon, 11 Jan 2016 14:26:03 +0100 Subject: [PATCH 05/10] Fix error in Commit to Ci::Commit delegation --- app/models/commit.rb | 2 +- spec/requests/api/commits_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/commit.rb b/app/models/commit.rb index ecc396045f0f..e96bfee19003 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -10,7 +10,7 @@ class Commit attr_mentionable :safe_message, pipeline: :single_line participant :author, :committer, :notes - delegate :duration, :started_at, :finished_at, :coverage, to: :ci_commit + delegate :duration, :started_at, :finished_at, :coverage, to: :ci_commit, allow_nil: true attr_accessor :project diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 49acc3368f43..4a523365b117 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -34,7 +34,7 @@ end end - describe "GET /projects:id/repository/commits/:sha" do + describe "GET /projects/:id/repository/commits/:sha" do context "authorized user" do it "should return a commit by sha" do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) -- GitLab From be7a784db7faf558caa022535c0a192111c4336d Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 13 Jan 2016 13:07:15 +0100 Subject: [PATCH 06/10] Add some fixes after review --- doc/api/merge_requests.md | 37 +++++++++++++++++++++++++------------ lib/api/entities.rb | 21 ++++++++++----------- lib/api/merge_requests.rb | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index 4f614026dab0..2ab34c38d6ee 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -2,7 +2,7 @@ ## List merge requests -Get all merge requests for this project. +Get all merge requests for this project. The `state` parameter can be used to get only merge requests with a given state (`opened`, `closed`, or `merged`) or all of them (`all`). The pagination parameters `page` and `per_page` can be used to restrict the list of merge requests. @@ -50,8 +50,7 @@ Parameters: "created_at": "2012-04-29T08:46:00Z" }, "description":"fixed login page css paddings", - "work_in_progress": false, - "status": "pending" + "work_in_progress": false } ] ``` @@ -98,7 +97,25 @@ Parameters: }, "description":"fixed login page css paddings", "work_in_progress": false, - "status": "pending" + "last_commit": { + "author_email": "admin@example.com", + "author_name": "Administrator", + "authored_date": "2012-04-25T13:12:15.000+01:00", + "committed_date": "2012-04-25T13:12:15.000+01:00", + "coverage": null, + "created_at": "2012-04-25T13:12:15.000+01:00", + "duration": 0, + "finished_at": null, + "id": "6c14056df0be27374e849ad67295a22cd0f7e0d0", + "message": "Add some fixes", + "parent_ids": [ + "6b053ad388c531c21907f022933e5e81598db388" + ], + "short_id": "6c14056d", + "started_at": null, + "status": "pending", + "title": "Add some fixes" + } } ``` @@ -206,8 +223,7 @@ Parameters: "renamed_file": false, "deleted_file": false } - ], - "status": "pending" + ] } ``` @@ -255,8 +271,7 @@ Parameters: "state": "active", "created_at": "2012-04-29T08:46:00Z" }, - "description":"fixed login page css paddings", - "status": "pending" + "description":"fixed login page css paddings" } ``` @@ -307,8 +322,7 @@ Parameters: "name": "Administrator", "state": "active", "created_at": "2012-04-29T08:46:00Z" - }, - "status": "pending" + } } ``` @@ -364,8 +378,7 @@ 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 680cc9765dc7..5a949b75f1a2 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -165,12 +165,6 @@ class Issue < ProjectEntity 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 @@ -181,11 +175,10 @@ class MergeRequest < ProjectEntity 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 MergeRequestDetail < MergeRequest + expose :last_commit, with: RepoCommitDetail end class MergeRequestChanges < MergeRequest @@ -229,6 +222,12 @@ class CommitNote < Grape::Entity 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 diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 3c1c6bda260d..6381a771f214 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -73,7 +73,7 @@ def handle_merge_request_errors!(errors) authorize! :read_merge_request, merge_request - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequestDetail end # Show MR commits -- GitLab From 6622105709295bf344ed1ef31218f82d768d53f1 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 13 Jan 2016 22:06:53 +0100 Subject: [PATCH 07/10] Modify commits documentation API style [ci skip] --- doc/api/commits.md | 97 ++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/doc/api/commits.md b/doc/api/commits.md index 9bf3a7defbe3..751ae49b2004 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -8,10 +8,14 @@ Get a list of repository commits in a project. GET /projects/:id/repository/commits ``` -Parameters: +| Attribute | Type | required | Description | +|-------------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `ref_name` | string | no | The name of a repository branch or tag or if not given the default branch | -- `id` (required) - The ID of a project -- `ref_name` (optional) - The name of a repository branch or tag or if not given the default branch +``` +curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/repository/commits" +``` ```json [ @@ -46,10 +50,14 @@ Get a specific commit identified by the commit hash or name of a branch or tag. GET /projects/:id/repository/commits/:sha ``` -Parameters: +| Attribute | Type | required | Description | +|-----------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `sha` | string | yes | The commit SHA | -- `id` (required) - The ID of a project -- `sha` (required) - The commit hash or name of a repository branch or tag +``` +curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6" +``` ```json { @@ -81,10 +89,14 @@ Get the diff of a commit in a project. GET /projects/:id/repository/commits/:sha/diff ``` -Parameters: +| Attribute | Type | required | Description | +|-----------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `sha` | string | yes | The commit SHA | -- `id` (required) - The ID of a project -- `sha` (required) - The name of a repository branch or tag or if not given the default branch +``` +curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff" +``` ```json [ @@ -109,10 +121,14 @@ Get the comments of a commit in a project. GET /projects/:id/repository/commits/:sha/comments ``` -Parameters: +| Attribute | Type | required | Description | +|-----------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `sha` | string | yes | The commit SHA | -- `id` (required) - The ID of a project -- `sha` (required) - The name of a repository branch or tag or if not given the default branch +``` +curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments" +``` ```json [ @@ -138,14 +154,18 @@ Adds a comment to a commit. Optionally you can post comments on a specific line POST /projects/:id/repository/commits/:sha/comments ``` -Parameters: +| Attribute | Type | required | Description | +|--------------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `sha` | string | yes | The commit SHA | +| `note` | string | yes | Text of comment | +| `path` | string | no | The file path | +| `line` | integer | no | The line number | +| `line_type` | string | no | The line type; one of: `new`, `old` | -- `id` (required) - The ID of a project -- `sha` (required) - The name of a repository branch or tag or if not given the default branch -- `note` (required) - Text of comment -- `path` (optional) - The file path -- `line` (optional) - The line number -- `line_type` (optional) - The line type (new or old) +``` +curl -X POST -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments" -F "note=text1" -F "path=example.rb" -F "line=5" -F line_type=new" +``` ```json { @@ -172,14 +192,18 @@ Get the statuses of a commit in a project. GET /projects/:id/repository/commits/:sha/statuses ``` -Parameters: +| Attribute | Type | required | Description | +|------------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `sha` | string | yes | The commit SHA | +| `ref` | string | no | Filter by ref name, it can be branch or tag | +| `stage` | string | no | Filter by stage | +| `name` | string | no | Filter by status name, eg. jenkins | +| `all` | boolean | no | The flag to return all statuses, not only latest ones | -- `id` (required) - The ID of a project -- `sha` (required) - The commit SHA -- `ref` (optional) - Filter by ref name, it can be branch or tag -- `stage` (optional) - Filter by stage -- `name` (optional) - Filer by status name, eg. jenkins -- `all` (optional) - The flag to return all statuses, not only latest ones +``` +curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/statuses?ref=test&name=ci%2Fjenkins" +``` ```json [ @@ -214,13 +238,20 @@ Adds or updates a status of a commit. POST /projects/:id/statuses/:sha ``` -- `id` (required) - The ID of a project -- `sha` (required) - The commit SHA -- `state` (required) - The state of the status. Can be: pending, running, success, failed, canceled -- `ref` (optional) - The ref (branch or tag) to which the status refers -- `name` or `context` (optional) - The label to differentiate this status from the status of other systems. Default: "default" -- `target_url` (optional) - The target URL to associate with this status -- `description` (optional) - The short description of the status +| Attribute | Type | required | Description | +|---------------|---------|----------|-------------------------| +| `id` | integer | yes | The ID of a project | +| `sha` | string | yes | The commit SHA | +| `state` | string | yes | The state of the status. Can be: `pending`, `running`, `success`, `failed`, `canceled` | +| `ref` | string | no | The ref (branch or tag) to which the status refers | +| `name` | string | no | The label to differentiate this status from the status of other systems. Default: "default". Duplicate of `context` | +| `context` | string | no | The label to differentiate this status from the status of other systems. Default: "default". Duplicate of `name` | +| `target_url` | string | no | The target URL to associate with this status | +| `description` | string | no | The short description of the status | + +``` +curl -X POST -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/statuses/b0b3a907f41409829b307a28b82fdbd552ee5a27" -F "state=success" -F "ref=test" -F "name=ci/jenkins" -F "target_url=http://jenkins/project/url" -F "description=Jenkins success" +``` ```json { -- GitLab From 648a2797c1a378a49545e63419fccd202ba3665e Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 14 Jan 2016 13:04:34 +0100 Subject: [PATCH 08/10] Move build data to 'last_build' namespace in commit details --- app/models/commit.rb | 2 -- doc/api/commits.md | 14 +++++++++----- doc/api/merge_requests.md | 16 ++++++++++------ lib/api/entities.rb | 11 +++++++++-- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/app/models/commit.rb b/app/models/commit.rb index e96bfee19003..f423c2814981 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -10,8 +10,6 @@ class Commit attr_mentionable :safe_message, pipeline: :single_line participant :author, :committer, :notes - delegate :duration, :started_at, :finished_at, :coverage, to: :ci_commit, allow_nil: true - attr_accessor :project # Safe amount of changes (files and lines) in one commit to render diff --git a/doc/api/commits.md b/doc/api/commits.md index 751ae49b2004..9eed64958fb6 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -73,14 +73,18 @@ curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3 "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], - "status": "running", - "coverage": null, - "duration": 2, - "started_at": "2015-12-24T17:54:09.744Z", - "finished_at": "2016-01-11T10:14:09.526Z" + "last_build": { + "status": "failed", + "coverage": null, + "duration": 2, + "started_at": "2015-12-24T17:54:09.744Z", + "finished_at": "2016-01-11T10:14:09.526Z" + } } ``` +`duration` in `last_build` - value exposed in **seconds** + ## Get the diff of a commit Get the diff of a commit in a project. diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index 2ab34c38d6ee..40ce618b3494 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -102,23 +102,27 @@ Parameters: "author_name": "Administrator", "authored_date": "2012-04-25T13:12:15.000+01:00", "committed_date": "2012-04-25T13:12:15.000+01:00", - "coverage": null, "created_at": "2012-04-25T13:12:15.000+01:00", - "duration": 0, - "finished_at": null, "id": "6c14056df0be27374e849ad67295a22cd0f7e0d0", "message": "Add some fixes", "parent_ids": [ "6b053ad388c531c21907f022933e5e81598db388" ], "short_id": "6c14056d", - "started_at": null, - "status": "pending", - "title": "Add some fixes" + "title": "Add some fixes", + "last_build": { + "coverage": null, + "duration": 0, + "finished_at": null, + "started_at": "2012-04-25T13:15:15.000+01:00", + "status": "running" + } } } ``` +`duration` in `last_commit` > `last_build` - value exposed in **seconds** + ## Get single MR commits Get a list of merge request commits. diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5a949b75f1a2..5ab82ebaa5fe 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -131,10 +131,17 @@ class RepoCommit < Grape::Entity expose :safe_message, as: :message end + class RepoCommitLastBuild < Grape::Entity + expose :status + expose :started_at + expose :finished_at + expose :duration + expose :coverage + end + class RepoCommitDetail < RepoCommit expose :parent_ids, :committed_date, :authored_date - expose :status - expose :started_at, :finished_at, :duration, :coverage + expose :ci_commit, as: :last_build, with: Entities::RepoCommitLastBuild end class ProjectSnippet < Grape::Entity -- GitLab From 56a45b0962b5ba61d69c2d2e8641664f37b3d686 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 14 Jan 2016 14:00:19 +0100 Subject: [PATCH 09/10] Modify notes about `duration` unit in commits and merge_requests API documentation [ci skip] --- doc/api/commits.md | 2 +- doc/api/merge_requests.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/commits.md b/doc/api/commits.md index 9eed64958fb6..4034187babe5 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -83,7 +83,7 @@ curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3 } ``` -`duration` in `last_build` - value exposed in **seconds** +**Note:** The `duration` value as exposed in `last_build`, is in seconds. ## Get the diff of a commit diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index 40ce618b3494..89a9573740b2 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -121,7 +121,7 @@ Parameters: } ``` -`duration` in `last_commit` > `last_build` - value exposed in **seconds** +**Note:** The `duration` value as exposed in `last_commit > last_build`, is in seconds. ## Get single MR commits -- GitLab From 01a407001d2b8400426f79db0762bb91e7b178f0 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 14 Jan 2016 15:11:15 +0100 Subject: [PATCH 10/10] Move `status` field back directly to commit data in API --- doc/api/commits.md | 2 +- doc/api/merge_requests.md | 4 ++-- lib/api/entities.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/commits.md b/doc/api/commits.md index 4034187babe5..74d1e03814f1 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -73,8 +73,8 @@ curl -H "PRIVATE_TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3 "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], + "status": "failed", "last_build": { - "status": "failed", "coverage": null, "duration": 2, "started_at": "2015-12-24T17:54:09.744Z", diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index 89a9573740b2..b2434b55bafd 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -110,12 +110,12 @@ Parameters: ], "short_id": "6c14056d", "title": "Add some fixes", + "status": "running", "last_build": { "coverage": null, "duration": 0, "finished_at": null, - "started_at": "2012-04-25T13:15:15.000+01:00", - "status": "running" + "started_at": "2012-04-25T13:15:15.000+01:00" } } } diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5ab82ebaa5fe..f5776900b421 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -132,7 +132,6 @@ class RepoCommit < Grape::Entity end class RepoCommitLastBuild < Grape::Entity - expose :status expose :started_at expose :finished_at expose :duration @@ -141,6 +140,7 @@ class RepoCommitLastBuild < Grape::Entity class RepoCommitDetail < RepoCommit expose :parent_ids, :committed_date, :authored_date + expose :status expose :ci_commit, as: :last_build, with: Entities::RepoCommitLastBuild end -- GitLab