Browse Source

流水线关联项目

tags/v3.0.1
moshenglv 5 years ago
parent
commit
f90bc0897b
6 changed files with 21 additions and 18 deletions
  1. +6
    -6
      api_document.md
  2. +2
    -2
      app/controllers/ci/pipelines_controller.rb
  3. +0
    -8
      app/controllers/ci/projects_controller.rb
  4. +11
    -0
      app/controllers/repositories_controller.rb
  5. +1
    -1
      app/views/ci/pipelines/_list.json.jbuilder
  6. +1
    -1
      db/migrate/20210119025745_add_sync_and_project_id_to_ci_pipelines.rb

+ 6
- 6
api_document.md View File

@@ -3283,9 +3283,10 @@ http://localhost:3000/api/jasder/forge/get_trustie_pipeline.json | jq

#### 更新'.trustie-pipeline.yml'文件
```
PUT /api/:owner/:repo/update_trustie_pipeline?pipeline_id={pipeline_id}
PUT /api/:owner/:repo/update_trustie_pipeline
```
*示例*

```bash
curl -X GET \
http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json?pipeline_id=1 | jq
@@ -3305,7 +3306,6 @@ http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json?pipeline_id=
|branch |否|string |分支名称, branch和new_branch必须存在一个,且只能存在一个 |
|new_branch |否|string |新的分支名称 |
|ci_language_id |否|string |新的分支名称 |
|pipeline_id |是|int |流水线id |


*返回参数说明:*
@@ -3955,14 +3955,14 @@ https://localhost:3000/api/users/ci/cloud_account/bind.json | jq
#### 流水线查询

```
GET /api/ci/pipelines/list?project_id={project_id}
GET /api/ci/pipelines/list?identifier={identifier}
```

*示例*

```bash
curl -X GET \
http://localhost:3000/api/ci/pipelines/list.json?project_id=1 | jq
http://localhost:3000/api/ci/pipelines/list.json?identifier="xxx" | jq
```

*返回参数说明:*
@@ -4007,7 +4007,7 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines' \
--data-raw ' {
"pipeline_name": "流水线 2021-01-12",
"file_name": ".trustie.pipeline.yaml",
"project_id": 1
"identifier": "xxx"
}'
```

@@ -4017,7 +4017,7 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines' \
| ------------- | ---- | ------ | ---------------------------------------------- |
| pipeline_name | 是 | string | 流水线名称 |
| file_name | 是 | string | 文件名称(默认初始值:.trustie.pipeline.yaml) |
| project_id | 是 | int | 项目id |
| identifier | 是 | string | 项目identifier |

*返回参数说明:*



+ 2
- 2
app/controllers/ci/pipelines_controller.rb View File

@@ -5,12 +5,12 @@ class Ci::PipelinesController < Ci::BaseController

# ======流水线相关接口========== #
def list
@pipelines = Ci::Pipeline.where('login=? and project_id=?', current_user.login, params[:project_id])
@pipelines = Ci::Pipeline.where('login=? and identifier=?', current_user.login, params[:identifier])
end

def create
ActiveRecord::Base.transaction do
pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name], login: current_user.login, project_id: params[:project_id])
pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name], login: current_user.login, identifier: params[:identifier])
pipeline.save!

# 默认创建四个初始阶段


+ 0
- 8
app/controllers/ci/projects_controller.rb View File

@@ -28,20 +28,12 @@ class Ci::ProjectsController < Ci::BaseController
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier))
if interactor.success?
@file = interactor.result
update_pipeline(params[:pipeline_id])
render_result(1, "更新成功")
else
render_error(interactor.error)
end
end

def update_pipeline(pipeline_id)
pipeline = Ci::Pipeline.find(pipeline_id)
if pipeline
pipeline.update!(sync: 1)
end
end

def activate
return render_error('你还未认证') unless current_user.ci_certification?



+ 11
- 0
app/controllers/repositories_controller.rb View File

@@ -94,11 +94,22 @@ class RepositoriesController < ApplicationController
if interactor.success?
@file = interactor.result
# create_new_pr(params)
#如果是更新流水线文件
if params[:pipeline_id]
update_pipeline(params[:pipeline_id])
end
else
render_error(interactor.error)
end
end
def update_pipeline(pipeline_id)
pipeline = Ci::Pipeline.find(pipeline_id)
if pipeline
pipeline.update!(sync: 1)
end
end
def update_file
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
if interactor.success?


+ 1
- 1
app/views/ci/pipelines/_list.json.jbuilder View File

@@ -3,6 +3,6 @@ json.pipeline_name pipeline.pipeline_name
json.pipeline_status pipeline.pipeline_status
json.file_name pipeline.file_name
json.sync pipeline.sync
json.project_id pipeline.project_id
json.identifier pipeline.identifier
json.created_at pipeline.created_at.strftime("%Y-%m-%d %H:%M:%S")
json.updated_at pipeline.updated_at.strftime("%Y-%m-%d %H:%M:%S")

+ 1
- 1
db/migrate/20210119025745_add_sync_and_project_id_to_ci_pipelines.rb View File

@@ -1,6 +1,6 @@
class AddSyncAndProjectIdToCiPipelines < ActiveRecord::Migration[5.2]
def change
add_column :ci_pipelines, :sync, :integer, null: false, comment: '0 未同步到gitea,1 已同步', default: 0
add_column :ci_pipelines, :project_id, :integer
add_column :ci_pipelines, :identifier, :string
end
end

Loading…
Cancel
Save