forked from Trustie/forgeplus
ADD paginate for builds api
This commit is contained in:
parent
4932eae285
commit
1ea9e420be
18
README.md
18
README.md
|
@ -2599,6 +2599,14 @@ http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json | jq
|
|||
|owner |是|string |用户登录名 |
|
||||
|repo |是|string |project's identifier |
|
||||
|ref |否|string |分支名称、tag名称或是提交记录id,默认为master分支 |
|
||||
|filepath |是|string |文件相对于仓库的路径(或修改后的文件路径) |
|
||||
|from_path |是|string |原文件相对于仓库的路径, 只有当需要修改原文件名称时,才需要该参数 |
|
||||
|sha |是|string |文件的sha标识值 |
|
||||
|content |是|string |内容 |
|
||||
|message |否|string |提交说明 |
|
||||
|branch |否|string |分支名称, branch和new_branch必须存在一个,且只能存在一个 |
|
||||
|new_branch |否|string |新的分支名称 |
|
||||
|ci_language_id |否|string |新的分支名称 |
|
||||
|
||||
|
||||
*返回参数说明:*
|
||||
|
@ -2729,6 +2737,16 @@ curl -X GET \
|
|||
http://localhost:3000/api/Jason/forge/builds | jq
|
||||
```
|
||||
|
||||
*请求参数说明:*
|
||||
|
||||
|参数名|必选|类型|说明|
|
||||
|-|-|-|-|
|
||||
|owner |是|string |项目拥有者 |
|
||||
|repo |是|string |项目identifier |
|
||||
|page |否|string |页数,第几页 |
|
||||
|limit |否|string |每页多少条数据,默认20条 |
|
||||
|search |是|string |构建状态条件过滤; 值说明:pending: 准备中,failure: 构建失败,running: 运行中,error:构建失败(.trustie-pipeline.yml文件错误),success: 构建成功 |
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
|参数名|类型|说明|
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
module Ci::BuildsHelper
|
||||
def format_utc_time(unix_time)
|
||||
Rails.logger.info "00000000000000 #{unix_time}"
|
||||
return nil if unix_time.blank?
|
||||
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
|
||||
return nil if end_time == 0
|
||||
game_spend_time(end_time - start_time)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,4 +3,11 @@ class Ci::Build < Ci::RemoteBase
|
|||
|
||||
belongs_to :repo, foreign_key: :build_repo_id
|
||||
has_many :stages, foreign_key: "stage_build_id", dependent: :destroy
|
||||
|
||||
scope :successed, ->{ by_status('success') }
|
||||
scope :failed, -> { by_status('failure') }
|
||||
scope :running, -> { by_status('running') }
|
||||
scope :errored, -> { by_status('error') }
|
||||
scope :pending, -> { by_status('pending') }
|
||||
scope :by_status, ->(status) { where(build_status: status) }
|
||||
end
|
||||
|
|
|
@ -16,4 +16,11 @@ class Ci::Repo < Ci::RemoteBase
|
|||
[user, repo]
|
||||
end
|
||||
|
||||
def enable
|
||||
update_column(:repo_config, '.trustie-pipeline.yml')
|
||||
end
|
||||
|
||||
def activate
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,8 +11,23 @@ class Ci::Builds::ListQuery < ApplicationQuery
|
|||
end
|
||||
|
||||
def call
|
||||
course_lists = @repo.builds
|
||||
scope = @repo.builds
|
||||
|
||||
custom_sort(course_lists, params[:sort_by], params[:sort_direction])
|
||||
scope =
|
||||
case params[:search]
|
||||
when 'success'
|
||||
scope.successed
|
||||
when 'pending'
|
||||
scope.pending
|
||||
when 'error'
|
||||
scope.errored
|
||||
when 'running'
|
||||
scope.running
|
||||
when 'failure'
|
||||
scope.failed
|
||||
else
|
||||
scope
|
||||
end
|
||||
custom_sort(scope, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
json.id user.id
|
||||
json.name user.real_name
|
||||
json.login user.login
|
||||
json.image_url url_to_avatar(user)
|
|
@ -6,7 +6,9 @@ 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.author do
|
||||
json.partial! 'author', user: current_user
|
||||
end
|
||||
json.started format_utc_time build.build_started
|
||||
json.finished format_utc_time build.build_finished
|
||||
json.created format_utc_time build.build_created
|
||||
|
|
|
@ -11,7 +11,7 @@ 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.stopped format_utc_time(stage.stage_stopped)
|
||||
json.created format_utc_time(stage.stage_created)
|
||||
json.updated format_utc_time(stage.stage_updated)
|
||||
json.version stage.stage_version
|
||||
|
|
Loading…
Reference in New Issue