forked from Gitlink/forgeplus
Update trustie pipeline api
This commit is contained in:
parent
c1e6792f29
commit
8758ec3197
33
README.md
33
README.md
|
@ -2583,6 +2583,39 @@ http://localhost:3000/api/jasder/forge/get_trustie_pipeline.json | jq
|
|||
```
|
||||
---
|
||||
|
||||
#### 更新'.trustie-pipeline.yml'文件
|
||||
```
|
||||
PUT /api/:owner/:repo/update_trustie_pipeline
|
||||
```
|
||||
*示例*
|
||||
```
|
||||
curl -X GET \
|
||||
http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json | jq
|
||||
```
|
||||
*请求参数说明:*
|
||||
|
||||
|参数名|必选|类型|说明|
|
||||
|-|-|-|-|
|
||||
|owner |是|string |用户登录名 |
|
||||
|repo |是|string |project's identifier |
|
||||
|ref |否|string |分支名称、tag名称或是提交记录id,默认为master分支 |
|
||||
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
|参数名|类型|说明|
|
||||
|-|-|-|
|
||||
|status |int|接口返回状态, 1: 请求成功, -1: 请求失败|
|
||||
|message |string|文件夹或文件相对路径|
|
||||
|
||||
```
|
||||
{
|
||||
"status": 1,
|
||||
"message": ".trustie-pipeline.yml"
|
||||
}
|
||||
```
|
||||
---
|
||||
|
||||
#### 获取语言列表
|
||||
```
|
||||
GET /api/ci/languages
|
||||
|
|
|
@ -35,19 +35,6 @@ class Ci::BuildsController < Ci::BaseController
|
|||
render json: result
|
||||
end
|
||||
|
||||
# get .trustie-pipeline.yml file
|
||||
def get_trustie_pipeline
|
||||
file_path_uri = URI.parse('.trustie-pipeline.yml')
|
||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: params[:ref] || "master")
|
||||
if interactor.success?
|
||||
file = interactor.result
|
||||
return render json: {} if file[:status]
|
||||
|
||||
json = {name: file['name'], path: file['path'], sha: file['sha'], content: render_decode64_content(file['content'])}
|
||||
render json: json
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_cloud_account
|
||||
@cloud_account = current_user.cloud_account
|
||||
|
|
|
@ -27,4 +27,15 @@ class Ci::ProjectsController < Ci::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def update_trustie_pipeline
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
Ci::Drone::API.new(current_user.cloud_account.drone_token, current_user.cloud_account.endpoint, params[:owner], @project.identifier, config_path: '.trustie-pipeline.yml').config_yml
|
||||
render_result(1, "更新成功")
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# Build List
|
||||
# GET api/repos/{owner}/{name}/builds
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier)
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier)
|
||||
def builds
|
||||
get(endpoint, "api/repos/#{owner}/#{repo}/builds", drone_token: drone_token)
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# Build Info
|
||||
# GET api/repos/{owner}/{name}/builds/{number}
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.endpoint, project.owner.login, project.identifier, number: number).build
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.endpoint, project.owner.login, project.identifier, number: number).build
|
||||
def build
|
||||
get(endpoint, "api/repos/#{owner}/#{repo}/builds/#{options[:number]}", drone_token: drone_token)
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# Update .trustie-pipeline.yml file
|
||||
# PATCH api/repos/{owner}/{name}\
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.endpoint, project.owner.login, project.identifier, config_path: config_path).config_yml
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.endpoint, project.owner.login, project.identifier, config_path: config_path).config_yml
|
||||
def config_yml
|
||||
patch(endpoint, "/api/repos/#{owner}/#{repo}", drone_token: drone_token, config_path: options[:config_path])
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# Activate user's project with Drone CI
|
||||
# POST api/repos/{owner}/{name}
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, project.owner.login, project.identifier).activate
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, project.owner.login, project.identifier).activate
|
||||
def activate
|
||||
post(endpoint, "/api/repos/#{owner}/#{repo}", drone_token: drone_token)
|
||||
end
|
||||
|
@ -48,7 +48,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# POST api/repos/{owner}/{name}/builds/{number}
|
||||
# Restart the specified build. Please note this api requires read and write access to the repository and the request parameter {build} is not the build id but the build number.
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, number: number).restart
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, number: number).restart
|
||||
def restart
|
||||
post(endpoint, "/api/repos/#{owner}/#{repo}/builds/#{options[:number]}", drone_token: drone_token)
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# DELETE api/repos/{owner}/{name}/builds/{number}
|
||||
# Stop the specified build. Please note this api requires administrative privileges and the request parameter {build} is not the build id but the build number.
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, number: number).stop
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, number: number).stop
|
||||
def stop
|
||||
delete(endpoint, "/api/repos/#{owner}/#{repo}/builds/#{options[:number]}", drone_token: drone_token)
|
||||
end
|
||||
|
@ -66,7 +66,7 @@ class Ci::Drone::API < Ci::Drone::Request
|
|||
# GET /api/repos/{owner}/{repo}/builds/{build}/logs/{stage}/{step}
|
||||
# Please note this api requires read access to the repository.
|
||||
# eq:
|
||||
# DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, build: build, stage: stage, step: step).logs
|
||||
# Ci::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, build: build, stage: stage, step: step).logs
|
||||
def logs
|
||||
get(endpoint, "/api/repos/#{owner}/#{repo}/builds/#{options[:build]}/logs/#{options[:stage]}/#{options[:step]}", drone_token: drone_token)
|
||||
end
|
||||
|
|
|
@ -344,6 +344,11 @@ Rails.application.routes.draw do
|
|||
to: 'projects#get_trustie_pipeline',
|
||||
as: :get_trustie_pipeline
|
||||
)
|
||||
put(
|
||||
'update_trustie_pipeline',
|
||||
to: 'projects#update_trustie_pipeline',
|
||||
as: :update_trustie_pipeline
|
||||
)
|
||||
end
|
||||
resources :cloud_accounts, only: [:create] do
|
||||
member do
|
||||
|
|
Loading…
Reference in New Issue