Skip to content

Commit da60c7e

Browse files
authored
[feat] [tools] add cr btn in sync-pr of ci-tools (#18)
* feat(ci-tools): add cr in sync-pr * feat(ci-tools): bump to 0.0.5 * ci: remove hard code git user
1 parent 19aff6d commit da60c7e

5 files changed

Lines changed: 71 additions & 21 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ jobs:
1616
runs-on: ubuntu-latest
1717
env:
1818
NODE_VERSION: '18'
19-
GIT_USER_NAME: 'mocayo'
20-
GIT_USER_EMAIL: 'qihai@bytedance.com'
2119
steps:
2220
- uses: actions/checkout@v3
2321
with:
2422
fetch-depth: 1
2523

26-
- name: Config Git User
27-
# should be turn to ci user
28-
run: |
29-
git config --local user.name ${{ env.GIT_USER_NAME }}
30-
git config --local user.email ${{ env.GIT_USER_EMAIL }}
31-
3224
- uses: actions/setup-node@v3
3325
with:
3426
node-version: ${{ env.NODE_VERSION }}

packages/ci-tools/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🕗 Change Log - @cozeloop/ci-tools
22

3-
## 0.0.2
3+
## 0.0.2 ~ 0.0.5
44
* [feat] add `sync-pr` to synchronize GitHub PR via lark in `lark` command
55

66
## 0.0.1

packages/ci-tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cozeloop/ci-tools",
3-
"version": "0.0.4",
4-
"description": "🔧 Tools for CI",
3+
"version": "0.0.5",
4+
"description": "🔧 Tools for Coze Loop CI",
55
"homepage": "https://github.com/coze-dev/cozeloop-js/tree/main/packages/ci-tools",
66
"bugs": {
77
"url": "https://github.com/coze-dev/cozeloop-js/issues"

packages/ci-tools/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ export function run() {
2222

2323
program.parse(process.argv);
2424
}
25+
26+
// if (require.main === module) {
27+
// run();
28+
// }

packages/ci-tools/src/lark/sync-pr.ts

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ import { Client } from '@larksuiteoapi/node-sdk';
55

66
import { larkOptionSchema, messageReceiverSchema } from './schema';
77

8+
function makeCRUrl(pr_url?: string) {
9+
const baseUrl = process.env.PR_CR_BASE_URL;
10+
11+
if (!pr_url || !baseUrl) {
12+
return;
13+
}
14+
15+
const docUrl = process.env.PR_CR_DOC_URL || '';
16+
const formData = JSON.stringify([
17+
{ name: 'pr_url', value: pr_url },
18+
{ name: 'doc_url', value: docUrl },
19+
]);
20+
21+
const cr_url = new URL(baseUrl);
22+
cr_url.searchParams.append('formData', formData);
23+
cr_url.searchParams.append('autoreg', 'true');
24+
cr_url.searchParams.append('fromapp', 'GitHub');
25+
26+
return cr_url.toString();
27+
}
28+
829
function makePrMessage() {
930
const repo_name = process.env.REPO_NAME;
1031
const pr_action = process.env.PR_ACTION;
@@ -17,11 +38,14 @@ function makePrMessage() {
1738
const pr_target_owner = process.env.PR_TARGET_OWNER;
1839
const pr_target_ref = process.env.PR_TARGET_REF;
1940
const pr_merged = process.env.PR_MERGED;
41+
const cr_url = makeCRUrl(pr_url);
2042

21-
const title =
22-
pr_action === 'closed' && pr_merged === 'true'
23-
? `🎉 PR #${pr_number} merged`
24-
: `📢 PR #${pr_number} ${pr_action}`;
43+
const isOpen = pr_action === 'opened' || pr_action === 'reopened';
44+
const isMerged = pr_action === 'closed' && pr_merged === 'true';
45+
46+
const title = isMerged
47+
? `🎉 PR #${pr_number} merged`
48+
: `📢 PR #${pr_number} ${pr_action}`;
2549

2650
return JSON.stringify({
2751
schema: '2.0',
@@ -59,13 +83,43 @@ function makePrMessage() {
5983
margin: '0px 0px 0px 0px',
6084
},
6185
{
62-
tag: 'markdown',
63-
content: `<a href="${pr_url}">👉 前往查看</a>`,
64-
text_align: 'left',
65-
text_size: 'normal_v2',
66-
margin: '0px 0px 0px 0px',
86+
tag: 'column_set',
87+
columns: [
88+
{
89+
tag: 'column',
90+
width: 'weighted',
91+
elements: [
92+
{
93+
tag: 'markdown',
94+
content: `<a href="${pr_url}">👉 前往查看</a>`,
95+
text_align: 'left',
96+
text_size: 'normal_v2',
97+
margin: '0px 0px 0px 0px',
98+
},
99+
],
100+
vertical_align: 'top',
101+
weight: 1,
102+
},
103+
isOpen && cr_url
104+
? {
105+
tag: 'column',
106+
width: 'weighted',
107+
elements: [
108+
{
109+
tag: 'markdown',
110+
content: `<a href="${cr_url}">🔍 Aime CR</a>`,
111+
text_align: 'left',
112+
text_size: 'normal_v2',
113+
margin: '0px 0px 0px 0px',
114+
},
115+
],
116+
vertical_align: 'top',
117+
weight: 1,
118+
}
119+
: undefined,
120+
],
67121
},
68-
],
122+
].filter(v => Boolean(v)),
69123
},
70124
header: {
71125
title: {

0 commit comments

Comments
 (0)