Skip to content
Snippets Groups Projects
Commit 8391fa37 authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

Merge branch...

Merge branch '12818-expose-simple-cicd-status-endpoints-with-status-serializer-gitlab-ci-status-for-pipeline-job-and-merge-request' into 'master'

Expose CI/CD status API endpoints with Gitlab::Ci::Status facility on pipeline, job and merge request for favicon

See merge request !9561
parents 856d2991 b3375a49
No related branches found
No related tags found
No related merge requests found
Showing
with 120 additions and 9 deletions
Loading
Loading
@@ -74,7 +74,9 @@ class Projects::BuildsController < Projects::ApplicationController
end
 
def status
render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
render json: BuildSerializer
.new(project: @project, user: @current_user)
.represent_status(@build)
end
 
def erase
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled
before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :conflicts, :conflict_for_path, :pipelines, :merge, :merge_check,
:ci_status, :ci_environments_status, :toggle_subscription, :cancel_merge_when_pipeline_succeeds, :remove_wip, :resolve_conflicts, :assign_related_issues
:ci_status, :pipeline_status, :ci_environments_status, :toggle_subscription, :cancel_merge_when_pipeline_succeeds, :remove_wip, :resolve_conflicts, :assign_related_issues
]
before_action :validates_merge_request, only: [:show, :diffs, :commits, :pipelines]
before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :conflict_for_path, :builds, :pipelines]
Loading
Loading
@@ -473,6 +473,12 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: response
end
 
def pipeline_status
render json: PipelineSerializer
.new(project: @project, user: @current_user)
.represent_status(@merge_request.head_pipeline)
end
def ci_environments_status
environments =
begin
Loading
Loading
Loading
Loading
@@ -72,6 +72,12 @@ class Projects::PipelinesController < Projects::ApplicationController
end
end
 
def status
render json: PipelineSerializer
.new(project: @project, user: @current_user)
.represent_status(@pipeline)
end
def stage
@stage = pipeline.stage(params[:stage])
return not_found unless @stage
Loading
Loading
Loading
Loading
@@ -18,10 +18,17 @@ class BuildEntity < Grape::Entity
 
expose :created_at
expose :updated_at
expose :detailed_status, as: :status, with: StatusEntity
 
private
 
alias_method :build, :object
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build)
end
def detailed_status
build.detailed_status(request.user)
end
end
class BuildSerializer < BaseSerializer
entity BuildEntity
def represent_status(resource)
data = represent(resource, { only: [:status] })
data.fetch(:status, {})
end
end
Loading
Loading
@@ -12,12 +12,7 @@ class PipelineEntity < Grape::Entity
end
 
expose :details do
expose :status do |pipeline, options|
StatusEntity.represent(
pipeline.detailed_status(request.user),
options)
end
expose :detailed_status, as: :status, with: StatusEntity
expose :duration
expose :finished_at
expose :stages, using: StageEntity
Loading
Loading
@@ -82,4 +77,8 @@ class PipelineEntity < Grape::Entity
pipeline.cancelable? &&
can?(request.user, :update_pipeline, pipeline)
end
def detailed_status
pipeline.detailed_status(request.user)
end
end
Loading
Loading
@@ -22,4 +22,11 @@ class PipelineSerializer < BaseSerializer
super(resource, opts)
end
end
def represent_status(resource)
return {} unless resource.present?
data = represent(resource, { only: [{ details: [:status] }] })
data.dig(:details, :status) || {}
end
end
class StatusEntity < Grape::Entity
include RequestAwareEntity
 
expose :icon, :text, :label, :group
expose :icon, :favicon, :text, :label, :group
 
expose :has_details?, as: :has_details
expose :details_path
Loading
Loading
---
title: Expose CI/CD status API endpoints with Gitlab::Ci::Status facility on pipeline,
job and merge request for favicon
merge_request: 9561
author: dosuken123
Loading
Loading
@@ -102,6 +102,7 @@ constraints(ProjectUrlConstrainer.new) do
get :merge_widget_refresh
post :cancel_merge_when_pipeline_succeeds
get :ci_status
get :pipeline_status
get :ci_environments_status
post :toggle_subscription
post :remove_wip
Loading
Loading
@@ -152,6 +153,7 @@ constraints(ProjectUrlConstrainer.new) do
post :cancel
post :retry
get :builds
get :status
end
end
 
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_canceled'
end
def favicon
'favicon_status_canceled'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -18,6 +18,10 @@ module Gitlab
raise NotImplementedError
end
 
def favicon
raise NotImplementedError
end
def label
raise NotImplementedError
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_created'
end
def favicon
'favicon_status_created'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_failed'
end
def favicon
'favicon_status_failed'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_manual'
end
def favicon
'favicon_status_manual'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_pending'
end
def favicon
'favicon_status_pending'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_running'
end
def favicon
'favicon_status_running'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_skipped'
end
def favicon
'favicon_status_skipped'
end
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
def icon
'icon_status_success'
end
def favicon
'favicon_status_success'
end
end
end
end
Loading
Loading
require 'spec_helper'
describe Projects::BuildsController do
include ApiHelpers
let(:user) { create(:user) }
let(:project) { create(:empty_project, :public) }
before do
sign_in(user)
end
describe 'GET status.json' do
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:status) { build.detailed_status(double('user')) }
before do
get :status, namespace_id: project.namespace,
project_id: project,
id: build.id,
format: :json
end
it 'return a detailed build status in json' do
expect(response).to have_http_status(:ok)
expect(json_response['text']).to eq status.text
expect(json_response['label']).to eq status.label
expect(json_response['icon']).to eq status.icon
expect(json_response['favicon']).to eq status.favicon
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment