summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-10-12 12:16:00 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-10-12 12:42:27 +0200
commit0aefeeb882b40d740b80f15ac6610a88a340d30b (patch)
tree5dcf22ccfd0b7222529f6d74b3e05c2dc2fb2493
parent7ef156a24292f98d89bc424cc245f00548831863 (diff)
downloadgitlab-ce-0aefeeb882b40d740b80f15ac6610a88a340d30b.tar.gz
Add Commit Status documentation
-rw-r--r--app/models/ci/commit.rb2
-rw-r--r--app/models/commit_status.rb2
-rw-r--r--doc/api/commits.md82
-rw-r--r--lib/api/commit_statuses.rb20
4 files changed, 94 insertions, 12 deletions
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index 042a68681bb..623ff619c49 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -136,7 +136,7 @@ module Ci
latest_statuses = statuses.latest.to_a
latest_statuses.reject! { |status| status.try(&:allow_failure?) }
- latest_statuses.select! { |status| status.ref == nil || status.ref == ref } if ref
+ latest_statuses.select! { |status| status.ref.nil? || status.ref == ref } if ref
if latest_statuses.none?
return 'skipped'
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index de7b29a649d..a4896a76316 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -5,7 +5,7 @@ class CommitStatus < ActiveRecord::Base
belongs_to :user
validates :commit, presence: true
- validates :status, inclusion: {in: %w(pending running failed success canceled)}
+ validates :status, inclusion: { in: %w(pending running failed success canceled) }
validates_presence_of :name
diff --git a/doc/api/commits.md b/doc/api/commits.md
index b22d040bf0d..78144dd42ef 100644
--- a/doc/api/commits.md
+++ b/doc/api/commits.md
@@ -157,3 +157,85 @@ Parameters:
"line_type": "new"
}
```
+
+## Get the status of a commit
+
+Get the statuses of a commit in a project.
+
+```
+GET /projects/:id/repository/commits/:sha/statuses
+```
+
+Parameters:
+
+- `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
+
+```json
+[
+ {
+ "id": 13,
+ "sha": "b0b3a907f41409829b307a28b82fdbd552ee5a27",
+ "ref": "test",
+ "status": "success",
+ "name": "ci/jenkins",
+ "target_url": "http://jenkins/project/url",
+ "description": "Jenkins success",
+ "created_at": "2015-10-12T09:47:16.250Z",
+ "started_at": "2015-10-12T09:47:16.250Z"",
+ "finished_at": "2015-10-12T09:47:16.262Z",
+ "author": {
+ "id": 1,
+ "username": "admin",
+ "email": "admin@local.host",
+ "name": "Administrator",
+ "blocked": false,
+ "created_at": "2012-04-29T08:46:00Z"
+ }
+ }
+]
+```
+
+## Post the status to commit
+
+Adds or updates a status of a commit.
+Optionally you can post comments on a specific line of a commit. Therefor both `path`, `line_new` and `line_old` are required.
+
+```
+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
+
+```json
+{
+ "id": 13,
+ "sha": "b0b3a907f41409829b307a28b82fdbd552ee5a27",
+ "ref": "test",
+ "status": "success",
+ "name": "ci/jenkins",
+ "target_url": "http://jenkins/project/url",
+ "description": "Jenkins success",
+ "created_at": "2015-10-12T09:47:16.250Z",
+ "started_at": "2015-10-12T09:47:16.250Z"",
+ "finished_at": "2015-10-12T09:47:16.262Z",
+ "author": {
+ "id": 1,
+ "username": "admin",
+ "email": "admin@local.host",
+ "name": "Administrator",
+ "blocked": false,
+ "created_at": "2012-04-29T08:46:00Z"
+ }
+}
+```
diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb
index c478b3dc245..ca750320e40 100644
--- a/lib/api/commit_statuses.rb
+++ b/lib/api/commit_statuses.rb
@@ -56,16 +56,16 @@ module API
status.update(attrs)
case params[:state].to_s
- when 'running'
- status.run
- when 'success'
- status.success
- when 'failed'
- status.drop
- when 'canceled'
- status.cancel
- else
- status.status = params[:state].to_s
+ when 'running'
+ status.run
+ when 'success'
+ status.success
+ when 'failed'
+ status.drop
+ when 'canceled'
+ status.cancel
+ else
+ status.status = params[:state].to_s
end
if status.save