diff --git a/README.md b/README.md index 3ed28e687..e98789b26 100644 --- a/README.md +++ b/README.md @@ -2399,6 +2399,41 @@ https://localhost:3000/api/dev_ops/cloud_accounts.json | jq ``` --- +#### 获取仓库的.trustie-pipeline.yml +``` +GET /api/dev_ops/builds/get_trustie_pipeline +``` +*示例* +``` +curl -X GET \ +-d "id=4844" \ +http://localhost:3000/api/dev_ops/builds/get_trustie_pipeline.json | jq +``` +*请求参数说明:* + +|参数名|必选|类型|说明| +|-|-|-|-| +|id |是|int |repository's id | +|ref |否|string |分支名称、tag名称或是提交记录id,默认为master分支 | + + +*返回参数说明:* + +|参数名|类型|说明| +|-|-|-| +|id |int |id | +|name |string|文件夹或文件名称| +|path |string|文件夹或文件相对路径| +|content |string|文件内容,| + +``` +{ + "name": ".trustie-pipeline.yml", + "path": ".trustie-pipeline.yml", + "content": "..jsaf" +} +``` + #### 获取语言列表 ``` GET /api/dev_ops/languages diff --git a/app/controllers/dev_ops/builds_controller.rb b/app/controllers/dev_ops/builds_controller.rb index 8870ec4b3..b7829c634 100644 --- a/app/controllers/dev_ops/builds_controller.rb +++ b/app/controllers/dev_ops/builds_controller.rb @@ -1,4 +1,6 @@ class ::DevOps::BuildsController < ApplicationController + include RepositoriesHelper + before_action :require_login before_action :find_repo @@ -36,6 +38,19 @@ class ::DevOps::BuildsController < ApplicationController 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(@repo.user, @repo.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'], content: render_decode64_content(file['content'])} + render json: json + end + end + private def find_repo @repo = ::Repository.find params[:id] diff --git a/config/routes.rb b/config/routes.rb index 64ada7e8d..8064352bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,7 @@ Rails.application.routes.draw do 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'