forked from Gitlink/forgeplus
FIX 重构ci流程
This commit is contained in:
parent
89b2e263ae
commit
7c1ab2cddf
28
README.md
28
README.md
|
@ -2695,22 +2695,15 @@ curl -X GET http://localhost:3000/api/dev_ops/languages/114.json | jq
|
|||
|
||||
#### 获取构建列表
|
||||
```
|
||||
GET /api/dev_ops/builds
|
||||
GET /api/:owner/:repo/builds
|
||||
```
|
||||
|
||||
*示例*
|
||||
```
|
||||
curl -X GET \
|
||||
-d 'project_id=4844' \
|
||||
http://localhost:3000/api/dev_ops/builds | jq
|
||||
http://localhost:3000/api/Jason/forge/builds | jq
|
||||
```
|
||||
|
||||
*请求参数说明:*
|
||||
|
||||
|参数名|必选|类型|说明|
|
||||
|-|-|-|-|
|
||||
|project_id |是|int |project's id |
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
|参数名|类型|说明|
|
||||
|
@ -2745,10 +2738,11 @@ http://localhost:3000/api/dev_ops/builds | jq
|
|||
"author_email": "email.com",
|
||||
"author_avatar": "",
|
||||
"sender": "jasder",
|
||||
"started": 1595317786,
|
||||
"finished": 1595318426,
|
||||
"created": 1595317786,
|
||||
"updated": 1595317786,
|
||||
"started": "2020-08-19 06:22",
|
||||
"finished": "2020-08-19 06:22",
|
||||
"created": "2020-08-19 06:22",
|
||||
"updated": "2020-08-19 06:22",
|
||||
"duration_time": 0,
|
||||
"version": 3
|
||||
}
|
||||
]
|
||||
|
@ -2757,22 +2751,20 @@ http://localhost:3000/api/dev_ops/builds | jq
|
|||
|
||||
#### 获取某条构建详情信息
|
||||
```
|
||||
GET /api/dev_ops/builds/:number
|
||||
GET /api/:owner/:repo/builds/:build
|
||||
```
|
||||
|
||||
*示例*
|
||||
```
|
||||
curl -X GET \
|
||||
-d 'project_id=4844' \
|
||||
http://ocalhost:3000/api/dev_ops/builds/1 | jq
|
||||
http://ocalhost:3000/api/jasder/forge/builds/1 | jq
|
||||
```
|
||||
|
||||
*请求参数说明:*
|
||||
|
||||
|参数名|必选|类型|说明|
|
||||
|-|-|-|-|
|
||||
|project_id |int|project's id|
|
||||
|number |是|int |build's number |
|
||||
|build |是|int |build's number |
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
class Ci::BaseController < ApplicationController
|
||||
before_action :require_login
|
||||
|
||||
def load_repo
|
||||
namespace = params[:owner]
|
||||
id = params[:repo] || params[:id]
|
||||
|
||||
@user, @repo = Ci::Repo.find_with_namespace(namespace, id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,14 +2,18 @@ class Ci::BuildsController < Ci::BaseController
|
|||
include RepositoriesHelper
|
||||
include Devopsable
|
||||
|
||||
before_action :find_project, :find_cloud_account
|
||||
before_action :find_cloud_account, except: :get_trustie_pipeline
|
||||
before_action :ci_authorize!
|
||||
before_action :load_repo
|
||||
|
||||
def index
|
||||
result = Ci::Drone::API.new(@cloud_account.drone_token, @cloud_account.drone_url, @project.owner.login, @project.identifier).builds
|
||||
scope = @repo.builds
|
||||
|
||||
render json: result
|
||||
scope = Ci::Builds::ListQuery.call(@repo, params)
|
||||
@total_count = scope.map(&:build_id).size
|
||||
@builds = paginate scope
|
||||
end
|
||||
|
||||
def show
|
||||
@build = @repo.builds.includes(stages: [:steps]).find_by(build_number: params[:build])
|
||||
end
|
||||
|
||||
def detail
|
||||
|
@ -49,10 +53,6 @@ class Ci::BuildsController < Ci::BaseController
|
|||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find params[:project_id]
|
||||
end
|
||||
|
||||
def find_cloud_account
|
||||
@cloud_account = @project.ci_cloud_account
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
module Ci::BuildsHelper
|
||||
def format_utc_time(unix_time)
|
||||
Rails.logger.info "00000000000000 #{unix_time}"
|
||||
DateTime.strptime(unix_time.to_s,'%s').strftime("%Y-%m-%d %H:%M")
|
||||
end
|
||||
|
||||
def render_duartion_time(end_time, start_time)
|
||||
(end_time - start_time) / 10000
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Ci::LanguagesHelper
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
module DevOps::BuildsHelper
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
module DevOps::LanguagesHelper
|
||||
end
|
|
@ -40,23 +40,23 @@ class Ci::Drone::Server
|
|||
end
|
||||
|
||||
def database_username
|
||||
database_config[Rails.env]["ci"]["username"]
|
||||
database_config[Rails.env]["ci_server_db"]["username"]
|
||||
end
|
||||
|
||||
def database_password
|
||||
database_config[Rails.env]["ci"]["password"]
|
||||
database_config[Rails.env]["ci_server_db"]["password"]
|
||||
end
|
||||
|
||||
def database_host
|
||||
database_config[Rails.env]["ci"]["host"]
|
||||
database_config[Rails.env]["ci_server_db"]["host"]
|
||||
end
|
||||
|
||||
def database_port
|
||||
database_config[Rails.env]["ci"]["port"] || 3306
|
||||
database_config[Rails.env]["ci_server_db"]["port"] || 3306
|
||||
end
|
||||
|
||||
def database
|
||||
database_config[Rails.env]["ci"]["database"]
|
||||
database_config[Rails.env]["ci_server_db"]["database"]
|
||||
end
|
||||
|
||||
def database_config
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Ci
|
||||
def self.table_name_prefix
|
||||
'ci_'
|
||||
end
|
||||
# def self.table_name_prefix
|
||||
# 'ci_'
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class Ci::Build < Ci::RemoteBase
|
||||
self.primary_key = 'build_id'
|
||||
|
||||
belongs_to :repo, foreign_key: :build_repo_id
|
||||
has_many :stages, foreign_key: "stage_build_id", dependent: :destroy
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
class Ci::CloudAccount < ApplicationRecord
|
||||
class Ci::CloudAccount < Local::Base
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Ci::Language < ApplicationRecord
|
||||
class Ci::Language < Local::Base
|
||||
# before_save :encode_content
|
||||
|
||||
belongs_to :cover, class_name: "Attachment", foreign_key: :cover_id, optional: true
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class Local::Base < ApplicationRecord
|
||||
def self.table_name_prefix
|
||||
"ci_"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class Ci::RemoteBase < ApplicationRecord
|
||||
self.abstract_class = true
|
||||
|
||||
establish_connection Rails.configuration.database_configuration[Rails.env]["ci_server_db"]
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
class Ci::Repo < Ci::RemoteBase
|
||||
self.primary_key = 'repo_id'
|
||||
|
||||
belongs_to :user, foreign_key: :repo_user_id
|
||||
has_many :builds, foreign_key: "build_repo_id", dependent: :destroy
|
||||
|
||||
def self.find_with_namespace(namespace_path, identifier)
|
||||
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
|
||||
|
||||
user = Ci::User.find_by_user_login namespace_path
|
||||
return nil if user.blank?
|
||||
|
||||
repo = user.repos.find_by(repo_name: identifier)
|
||||
|
||||
return nil if repo.blank?
|
||||
[user, repo]
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class Ci::Stage < Ci::RemoteBase
|
||||
self.primary_key = 'stage_id'
|
||||
|
||||
belongs_to :build, foreign_key: :stage_build_id
|
||||
has_many :steps, foreign_key: "step_stage_id", dependent: :destroy
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class Ci::Step < Ci::RemoteBase
|
||||
self.primary_key = 'step_id'
|
||||
|
||||
belongs_to :stage, foreign_key: :step_stage_id
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class Ci::User < Ci::RemoteBase
|
||||
self.primary_key = 'user_id'
|
||||
|
||||
has_many :repos, foreign_key: "repo_user_id", dependent: :destroy
|
||||
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
class Ci::Builds::ListQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
|
||||
sort_columns :build_created, default_by: :build_created, default_direction: :desc
|
||||
|
||||
def initialize(repo, params)
|
||||
@repo = repo
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
course_lists = @repo.builds
|
||||
|
||||
custom_sort(course_lists, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
json.id build.build_id
|
||||
json.repo_id build.build_repo_id
|
||||
json.number build.build_number
|
||||
json.status build.build_status
|
||||
json.event build.build_event
|
||||
json.action build.build_action
|
||||
# json.link build.build_link
|
||||
json.message build.build_message
|
||||
json.author build.build_author
|
||||
json.started format_utc_time build.build_started
|
||||
json.finished format_utc_time build.build_finished
|
||||
json.created format_utc_time build.build_created
|
||||
json.updated format_utc_time build.build_updated
|
||||
json.version build.build_version
|
||||
json.duration_time render_duartion_time(build.build_finished, build.build_started)
|
|
@ -0,0 +1,22 @@
|
|||
json.id stage.stage_id
|
||||
json.repo_id stage.stage_repo_id
|
||||
json.build_id stage.stage_build_id
|
||||
json.name stage.stage_name
|
||||
json.kind stage.stage_kind
|
||||
json.type stage.stage_type
|
||||
json.number stage.stage_number
|
||||
json.status stage.stage_status
|
||||
json.errignore stage.stage_errignore
|
||||
json.exit_code stage.stage_exit_code
|
||||
json.os stage.stage_os
|
||||
json.arch stage.stage_arch
|
||||
json.started format_utc_time(stage.stage_started)
|
||||
json.stopped format_utc_time(stage.stage_stoped)
|
||||
json.created format_utc_time(stage.stage_created)
|
||||
json.updated format_utc_time(stage.stage_updated)
|
||||
json.version stage.stage_version
|
||||
json.on_success stage.stage_on_success
|
||||
json.on_failure stage.stage_on_failure
|
||||
json.steps build.steps do |stage|
|
||||
json.partial! "/ci/builds/step", step: step
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
json.id step.step_id
|
||||
json.number step.step_number
|
||||
json.name step.step_name
|
||||
json.status step.step_status
|
||||
json.exit_code step.step_exit_code
|
||||
json.started format_utc_time(step.step_started)
|
||||
json.stopped format_utc_time(step.step_stopped)
|
||||
json.version step.build_version
|
|
@ -0,0 +1,4 @@
|
|||
json.total_count @total_count
|
||||
json.builds @builds do |build|
|
||||
json.partial! "/ci/builds/build", build: build
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
json.partial! "/ci/builds/build", build: @build
|
||||
json.stages @build.stages do |stage|
|
||||
json.partial! "/ci/builds/stage", stage: stage
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
<h1>DevOps::Builds#index</h1>
|
||||
<p>Find me in app/views/dev_ops/builds/index.html.erb</p>
|
|
@ -1,2 +0,0 @@
|
|||
<h1>DevOps::Builds#show</h1>
|
||||
<p>Find me in app/views/dev_ops/builds/show.html.erb</p>
|
|
@ -31,15 +31,15 @@ Rails.application.routes.draw do
|
|||
get :common
|
||||
end
|
||||
end
|
||||
resources :builds, only: :index do
|
||||
collection do
|
||||
get 'get_trustie_pipeline', to: 'builds#get_trustie_pipeline', as: 'get_trustie_pipeline'
|
||||
get ':number', to: 'builds#detail', as: 'detail'
|
||||
post ':number', to: 'builds#restart', as: 'restart'
|
||||
delete ':number', to: 'builds#delete', as: 'delete'
|
||||
get ':number/logs/:stage/:step', to: 'builds#logs', as: 'logs'
|
||||
end
|
||||
end
|
||||
# resources :builds, only: :index do
|
||||
# collection do
|
||||
# get 'get_trustie_pipeline', to: 'builds#get_trustie_pipeline', as: 'get_trustie_pipeline'
|
||||
# get ':number', to: 'builds#detail', as: 'detail'
|
||||
# post ':number', to: 'builds#restart', as: 'restart'
|
||||
# delete ':number', to: 'builds#delete', as: 'delete'
|
||||
# get ':number/logs/:stage/:step', to: 'builds#logs', as: 'logs'
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
resources :sync_forge, only: [:create] do
|
||||
|
@ -338,6 +338,10 @@ Rails.application.routes.draw do
|
|||
resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index]
|
||||
resources :version_releases, :path => :releases, only: [:index,:new, :create, :edit, :update, :destroy]
|
||||
|
||||
scope module: :ci do
|
||||
resources :builds, param: :build
|
||||
end
|
||||
|
||||
scope module: :projects do
|
||||
scope do
|
||||
get(
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Ci::Build, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Ci::Repo, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Ci::Stage, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Ci::Step, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue