Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@ jobs:
runs-on: ubuntu-latest
env:
NODE_VERSION: '18'
GIT_USER_NAME: 'mocayo'
GIT_USER_EMAIL: '[email protected]'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Config Git User
# should be turn to ci user
run: |
git config --local user.name ${{ env.GIT_USER_NAME }}
git config --local user.email ${{ env.GIT_USER_EMAIL }}

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down
2 changes: 1 addition & 1 deletion packages/ci-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🕗 Change Log - @cozeloop/ci-tools

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

## 0.0.1
Expand Down
4 changes: 2 additions & 2 deletions packages/ci-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cozeloop/ci-tools",
"version": "0.0.4",
"description": "🔧 Tools for CI",
"version": "0.0.5",
"description": "🔧 Tools for Coze Loop CI",
"homepage": "https://github.com/coze-dev/cozeloop-js/tree/main/packages/ci-tools",
"bugs": {
"url": "https://github.com/coze-dev/cozeloop-js/issues"
Expand Down
4 changes: 4 additions & 0 deletions packages/ci-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ export function run() {

program.parse(process.argv);
}

// if (require.main === module) {
// run();
// }
74 changes: 64 additions & 10 deletions packages/ci-tools/src/lark/sync-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ import { Client } from '@larksuiteoapi/node-sdk';

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

function makeCRUrl(pr_url?: string) {
const baseUrl = process.env.PR_CR_BASE_URL;

if (!pr_url || !baseUrl) {
return;
}

const docUrl = process.env.PR_CR_DOC_URL || '';
const formData = JSON.stringify([
{ name: 'pr_url', value: pr_url },
{ name: 'doc_url', value: docUrl },
]);

const cr_url = new URL(baseUrl);
cr_url.searchParams.append('formData', formData);
cr_url.searchParams.append('autoreg', 'true');
cr_url.searchParams.append('fromapp', 'GitHub');

return cr_url.toString();
}

function makePrMessage() {
const repo_name = process.env.REPO_NAME;
const pr_action = process.env.PR_ACTION;
Expand All @@ -17,11 +38,14 @@ function makePrMessage() {
const pr_target_owner = process.env.PR_TARGET_OWNER;
const pr_target_ref = process.env.PR_TARGET_REF;
const pr_merged = process.env.PR_MERGED;
const cr_url = makeCRUrl(pr_url);

const title =
pr_action === 'closed' && pr_merged === 'true'
? `🎉 PR #${pr_number} merged`
: `📢 PR #${pr_number} ${pr_action}`;
const isOpen = pr_action === 'opened' || pr_action === 'reopened';
const isMerged = pr_action === 'closed' && pr_merged === 'true';

const title = isMerged
? `🎉 PR #${pr_number} merged`
: `📢 PR #${pr_number} ${pr_action}`;

return JSON.stringify({
schema: '2.0',
Expand Down Expand Up @@ -59,13 +83,43 @@ function makePrMessage() {
margin: '0px 0px 0px 0px',
},
{
tag: 'markdown',
content: `<a href="${pr_url}">👉 前往查看</a>`,
text_align: 'left',
text_size: 'normal_v2',
margin: '0px 0px 0px 0px',
tag: 'column_set',
columns: [
{
tag: 'column',
width: 'weighted',
elements: [
{
tag: 'markdown',
content: `<a href="${pr_url}">👉 前往查看</a>`,
text_align: 'left',
text_size: 'normal_v2',
margin: '0px 0px 0px 0px',
},
],
vertical_align: 'top',
weight: 1,
},
isOpen && cr_url
? {
tag: 'column',
width: 'weighted',
elements: [
{
tag: 'markdown',
content: `<a href="${cr_url}">🔍 Aime CR</a>`,
text_align: 'left',
text_size: 'normal_v2',
margin: '0px 0px 0px 0px',
},
],
vertical_align: 'top',
weight: 1,
}
: undefined,
],
},
],
].filter(v => Boolean(v)),
},
header: {
title: {
Expand Down
Loading