# 前言

这里介绍如何使用 SCM 模板创建插件

# 接入效果

# 接入流程

# 创建 TAPD 托管应用

在开发平台中选择 SCM NodeJs Vue 模板插件来创建应用 创建应用

# 下载代码及授权验证

在应用概览中选择代码仓库并下载 下载代码

安装并使用 tplugin-cli 进行 Oauth 授权,参考【快速入门】实现 授权验证

# TAPD 服务集成

使用tplugin-cli serve命令启动模板插件应用,在【公司管理-开放集成-服务集成】中对插件进行管理 服务集成

# 配置 SCM 服务

在 SCM 服务中配置地址和私人令牌 私人令牌

以工蜂为例,在账户中查看私人令牌 工蜂令牌

# 关联代码仓库

在【项目协作-项目设置-DevOps配置-代码】中即可关联代码仓库 关联仓库

# 扩展能力

# 挂载点

app:
  modules:
    scm:
      adapter:
        _hooks_handler:
          adapter: hook.adapter
        commit:
          get: commit.get
        commit_diff:
          get: commit.diff
        commits:
          get: commit.list
        hook:
          delete: hook.delete
          put: hook.put
        hooks:
          get: hook.get
          post: hook.post
        project:
          get: projects.get
        projects:
          get: projects.list
        query_commits:
          get: commit.query
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 能力实现

SCM 插件应用主要根据用户的 host 和 private key 来调用代码仓库的相关接口,以commit.query为例,它可以查询指定仓库的提价记录 查询提交

data参数的结构如下

{
    "workspace_id": "66229999",
    "current_user": {
        "id": "810118533",
        "nick": "nick",
        "name_pinyin": "",
        "enabled": "1",
        "status_name": "",
        "current_company_id": "58082844",
        "group_id": "0",
        "group_name": "",
        "group_names": "",
        "post_name": ""
    },
    "tapd_request_id": "55dbd5265385f7d981cdda243a413710",
    "data": {
        "app_code": "tapd-app-ec1bde",
        "handler": "commit.query",
        "access_token": "",
        "host": "",
        "api_uri": "",
        "query": {
            "author": "author",
            "project_id": "1307508",
            "per_page": "8",
            "begin_date": "2024-02-11T00:00:00+0800",
            "end_date": "2024-08-09T23:59:59+0800",
            "message": "",
            "page": "0",
            "apply_ignore_rules": false
        }
    },
    "files": [

    ],
    "company_id": "58082844"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

返回的结构如下

[
    {
        "commit": "47f6a16d",
        "username": "mooretwang",
        "message": "超 200+ 应用接入,强大的应用开放生态\n",
        "time": 1723174630000
    },
    {
        "commit": "886eed17",
        "username": "mooretwang",
        "message": "add README\n",
        "time": 1723113868000
    }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 使用示例

在任意工作项中使用 SCM 插件应用进行关联

# 插件工程目录示例

├── handler
│   └── config.js
├── index.js
├── Makefile
├── modules
│   ├── autotasks
│   │   └── condition.js
│   └── scm
│       ├── commit.js
│       ├── hook.js
│       ├── projects.js
│       ├── sdk.js
│       └── storage
│           ├── config.js
│           └── storage.js
├── package.json
├── plugin.yaml
├── resources
│   └── pages
│       ├── app_for_global_config
│       │   ├── app_for_global_config.vue
│       │   └── index.css
│       ├── app_for_global_config.js
│       └── index.html
├── utils.js
└── webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# plugin.yaml 示例

app:
  code: tapd-app-ec1bde
  desc: scm demo
  modules:
    autotasks:
      - code: scm
        conditions:
          - code: scm::conditon-demo
            data:
              handler: condition.data
            desc: scm condition demo
            icon: business
            name: scm-condition
            option:
              handler: condition.option
            related:
              - story
              - bug
              - task
        icon: business
        name: scm-demo
    scm:
      adapter:
        _hooks_handler:
          adapter: hook.adapter
        commit:
          get: commit.get
        commit_diff:
          get: commit.diff
        commits:
          get: commit.list
        hook:
          delete: hook.delete
          put: hook.put
        hooks:
          get: hook.get
          post: hook.post
        project:
          get: projects.get
        projects:
          get: projects.list
        query_commits:
          get: commit.query
      code: scm
      desc: scm demo
      name: scm-demo
      support:
        branch: false
  name: SCM
  resources:
    - key: app_for_global_config
      name: Demo应用
      path: pages/app_for_global_config
  scopes:
    - source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
上次更新: 2024-08-12 16:45:15