集成代码仓
适用环境 | 私有部署 |
要求
ONES | @ones-op/node-ability |
---|---|
v3.13.9+ | v0.4.0+ |
概述
开放平台提供了 “集成代码仓” 的能力,使用该能力可以将集成的第三方代码仓的代码提交和合并请求与 ONES Project 的任务相关联。关联成功后团队成员在完成编码后,提交 Commit 时在提交消息(Commit message)输入包含本段代码涉及的研发任务的 ID,或者提交 Pull Request 时在标题(Title)输入涉及的研发任务的 ID,通过“空格”隔开,提交后可以在 ONES 实时查看代码提交和代码合并请求情况。
能力表现
-
在使用该能力后,可以在配置中心 -> 流水线管理配置 -> 代码仓配置页面,点击「关联代码仓」查看到能力添加的关联代码仓选项。
-
通过能力实现关联代码仓的逻辑后,即可跟 ONES 系统的 GitHub、GitLab、私有 GitLab、SVN、私有 Bitbucket 等内置类型一样去关联代码仓,关联成功后将和其他内置类型一样,在代码仓配置面列表展示。
-
通过能力实现新增代码提交(Commit)和新增代码合并请求(Pull Request)逻辑后,你可以在工作项详情的 “代码关联” 栏位查看代码关联结果。
-
迭代支持汇总需求已关联的代码提交数据,迭代负责人可以据此跟进开发进展。
-
迭代概览下将汇总统计当前迭代的代码提交情况,帮助迭代负责人评估开发贡献量。 目前支持统计和分析代码提交次数、代码提交次数趋势、代码提交影响行数的情况。
使用
第一步:在插件项目中添加能力和插槽配置
1. 添加能力
在 “插件根目录” 使用 OP
命令添加能力,选择 custom-code-repository
类型:
$ npx op add ability
✔ Validating the input params
✔ Validating project files exists
✔ Generating initial answers by input params
✔ Parsing plugin config content
Pre-require tasks run successfully
? Please select the ability you want to add: … custom-code-repository
custom-code-repository@1.0.0
OP 工具会询问是否使用默认值,选择是即可,OP 工具会为插件添加如下内容:
-
在插件根目录的
config/plugin.yaml
中abilities
字段新增相 关段落:service:
app_id: ...
name: ability-CustomCodeRepository
...
apis:
...
abilities:
- id: CkrqExqC
name: 自定义代码仓库
version: 1.0.0
abilityType: CustomCodeRepository
relateModule:
addRepoPage: ''
function:
removeRepoFunc: removeRepo
config:
- key: repoToolName
label: 关联代码仓工具名称
value: 自定义代码仓类型
fieldType: Input
show: true
- key: repoToolDesc
label: 关联代码仓工具描述
value: 自定义代码仓类型
fieldType: Input
show: true
- key: repoToolIcon
label: 关联代码仓工具图标
value: logo.svg
fieldType: Input
show: false其中 abilities.config 中 3 个配置的作用主要用于配置中心 -> 流水线管理配置 -> 代码仓配置页面 -> 关联代码仓页面展示自定义的代码仓关联工具配置,具体如下表所示:
配置 | 描述 |
---|---|
repoToolName | 自定义关联代码仓工具名称(必填,最大长度 128) |
repoToolDesc | 自定义关联代码仓工具描述(必填) |
repoToolIcon | 自定义关联代码仓工具图标(必填,最大长度 255) 规则:logo.svg 对应插件目录 web/public/logo.svg 文件 |
-
在插件根目录的
backend/src
目录下新增custom-code-repository.ts
文件。文件中包括一个默认
removeRepo
方法实现,当管理人员在代码仓配置页面做 “移除关联” 操作时将调用此方法。提供该方法的主要目的是让插件能够收到代码仓被移除的通知。开发者可以保持不变,也可以修改此方法做自定义的清理逻辑(方法的返回值不会影响系统移除关联代码仓)。
import { PluginRequest, PluginResponse } from '@ones-op/node-types'
export async function removeRepo(request: PluginRequest): Promise<PluginResponse> {
const body = request?.body as any
if (body && body.data) {
const repoInfo = body.data
}
return {
body: {
code: 200,
},
}
}
2. 添加插槽
在 “插件根目录” 使用 OP 命令添加插槽,选择 ones:settings:pipeline:default:repo:link 类型插槽:
$ npx op add module
✔ Validating the input params
✔ Validating project files exists
✔ Generating initial answers by input params
✔ Parsing plugin config content
Pre-require tasks run successfully
? Please select the module type you want to add: … ones:settings:pipeline:default:repo:link
ones:settings:pipeline:default:repo:link
3. 能力关联插槽
在 plugin.yaml
文件中,将能力与插槽关联,即将插槽的 id
配置到能力的配置 addRepoPage
值中,最后效果如下:
service:
app_id: ...
name: ability-CustomCodeRepository
...
apis:
...
abilities:
- id: CkrqExqC
name: 自定义代码仓库
version: 1.0.0
abilityType: CustomCodeRepository
relateModule:
addRepoPage: 'ones-settings-pipeline-default-repo-link-R5w-'
function:
removeRepoFunc: removeRepo
config:
- key: repoToolName
label: 关联代码仓工具名称
value: 自定义关联代码仓工具
fieldType: Input
show: true
- key: repoToolDesc
label: 关联代码仓工具描述
value: 自定义关联代码仓工具
fieldType: Input
show: true
- key: repoToolIcon
label: 关联代码仓工具图标
value: logo.svg
fieldType: Input
show: false
modules:
- id: ones-settings-pipeline-default-repo-link-R5w-
title: 关联代码仓页面
moduleType: ones:settings:pipeline:default:repo:link
entry: modules/ones-settings-pipeline-default-repo-link-R5w-/index.html