diff --git a/api_document.md b/api_document.md index f58f6f1f..3c6c90fd 100644 --- a/api_document.md +++ b/api_document.md @@ -4179,22 +4179,24 @@ curl --location --request GET 'http://localhost:3000/api/ci/pipelines/19/stages. #### 确认阶段流水线完整内容查询 ``` -GET /api/ci/pipelines/{id}/content +GET /api/ci/pipelines/{id}/content?owner={owner}&repo={repo} ``` *示例* ```bash curl -X GET \ -http://localhost:3000/api/ci/pipelines/1/content.json | jq +http://localhost:3000/api/ci/pipelines/1/content.json?owner=xx&repo=xx | jq ``` *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ------- | ------ | ---------- | -| content | String | 流水线内容 | -| sync | int | 同步状态 | +| 参数名 | 类型 | 说明 | +| ------- | ------ | ---------------- | +| content | String | 流水线内容 | +| sync | int | 同步状态 | +| owner | string | 用户登录名 | +| repo | string | 项目的identifier | 返回值 diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 9add4cb4..371f062b 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -2,6 +2,7 @@ class Ci::PipelinesController < Ci::BaseController before_action :require_login, only: %i[list create] skip_before_action :connect_to_ci_db + before_action :load_project, only: %i[content] # ======流水线相关接口========== # def list @@ -54,6 +55,7 @@ class Ci::PipelinesController < Ci::BaseController @yaml = "#pipeline \n" pipeline = Ci::Pipeline.find(params[:id]) @sync = pipeline.sync + @sha = '' stages = pipeline.pipeline_stages if stages && !stages.empty? init_step = stages.first.pipeline_stage_steps.first @@ -69,8 +71,19 @@ class Ci::PipelinesController < Ci::BaseController end end end + if @sync == 1 + @sha = get_pipeline_file_sha(pipeline.file_name) + end end + def get_pipeline_file_sha(file_name) + file_path_uri = URI.parse(file_name) + interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: params[:ref] || "master") + if interactor.success? + file = interactor.result + return file['sha'] + end + end # =========阶段相关接口========= # def stages pipeline_id = params[:id] diff --git a/app/views/ci/pipelines/content.json.jbuilder b/app/views/ci/pipelines/content.json.jbuilder index e532dd57..60d211b9 100644 --- a/app/views/ci/pipelines/content.json.jbuilder +++ b/app/views/ci/pipelines/content.json.jbuilder @@ -1,2 +1,3 @@ json.content @yaml -json.sync @sync \ No newline at end of file +json.sync @sync +json.sha @sha \ No newline at end of file