Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Jan 9, 2025
1 parent 6c9d3fc commit 4a6d29a
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 218 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
"@actions/github": "^6.0.0"
},
"devDependencies": {
"@antfu/eslint-config": "^3.12.1",
"@octokit/plugin-rest-endpoint-methods": "^13.2.6",
"@antfu/eslint-config": "^3.12.2",
"@octokit/plugin-rest-endpoint-methods": "^13.3.0",
"@types/node": "^22.10.5",
"@vercel/ncc": "^0.38.3",
"eslint": "^9.17.0",
"eslint-plugin-format": "^0.1.3",
"lint-staged": "^15.3.0",
"rimraf": "^6.0.1",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
},
"simple-git-hooks": {
Expand Down
354 changes: 177 additions & 177 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

37 changes: 10 additions & 27 deletions src/tdesign/icons.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
import type { TriggerContext } from './trigger'
import { info } from '@actions/core'
import { addContributor, getPrData } from '../utils'

const vuePackageUrl = 'https://raw.githubusercontent.com/Tencent/tdesign-icons/refs/heads/develop/packages/vue/package.json'
const vueNextPackageUrl = 'https://raw.githubusercontent.com/Tencent/tdesign-icons/refs/heads/develop/packages/vue-next/package.json'
const reactPackageUrl = 'https://raw.githubusercontent.com/Tencent/tdesign-icons/refs/heads/develop/packages/react/package.json'
const viewPackageUrl = 'https://raw.githubusercontent.com/Tencent/tdesign-icons/refs/heads/develop/packages/view/package.json'
import { addContributor, cloneRepo, getPkgLatestVersion, getPrData, updateIcons } from '../utils'
import { iconsMap, ownerMap, repoMap, type TriggerContext } from './trigger'

export default async function start(context: TriggerContext) {
const pr_data = await getPrData(context.owner, context.repo, context.pr_number, context.token)
const body = addContributor(pr_data.body || '', 'tdesign-helper')

const prData = await getPrData(context.owner, context.repo, context.pr_number, context.token)
const body = addContributor(prData.body || '', prData.user.login)
info(`body:${body}`)
const packageName = iconsMap[context.comment]
cloneRepo(ownerMap[context.comment], repoMap[context.comment], context.token)
updateIcons(packageName)
const latestVersion = await getPkgLatestVersion(packageName)
const title = `chore(Icon): update to ${latestVersion}`
info(title)
};

function _vue() {
info(viewPackageUrl)
info(vuePackageUrl)
}
function _vueNext() {
info(vueNextPackageUrl)
}
function _react() {
info(reactPackageUrl)
}
function _mobileVue() {
info(vueNextPackageUrl)
}
function _mobileReact() {
info(reactPackageUrl)
}
16 changes: 16 additions & 0 deletions src/tdesign/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import iconStart from './icons'

export const iconsMap = {
'/pr-vue': 'tdesign-icons-vue',
'/pr-vue-next': 'tdesign-icons-vue-next',
'/pr-react': 'tdesign-icons-react',
}
export const repoMap = {
'/pr-vue': 'tdesign-vue',
'/pr-vue-next': 'tdesign-vue-next',
'/pr-react': 'tdesign-react',
}
export const ownerMap = {
'/pr-vue': 'Tencent',
'/pr-vue-next': 'Tencent',
'/pr-react': 'Tencent',
}

export interface TriggerContext {
owner: string
repo: string
Expand Down
13 changes: 11 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { info } from '@actions/core'
import { exec } from '@actions/exec'
import { exec, getExecOutput } from '@actions/exec'
import { getOctokit } from '@actions/github'

export const SKIP_CHANGELOG_REG = /\[x\] PR Changelog/i
Expand Down Expand Up @@ -68,6 +68,15 @@ export async function createPR(owner: string, repo: string, pr_number: number, t
title: 'chore: update common',
head: `chore/update-common/pr${pr_number}`,
base: 'develop',
body: pr_data?.body || '',
body: '',
})
}
export async function getPkgLatestVersion(packageName: string) {
const { stdout } = await getExecOutput('npm', ['view', packageName, 'version'])
return stdout.trim()
}

export async function updateIcons(repo: string) {
await exec('npx', ['npm-check-updates', 'tdesign-icons-*', '-u'], { cwd: `../${repo}` })
await exec('git', ['status'], { cwd: `../${repo}` })
}
10 changes: 10 additions & 0 deletions test/fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "fixture",
"private": true,
"devDependencies": {
"tdesign-icons-react": "^3.0.0",
"tdesign-icons-view": "^4.0.0",
"tdesign-icons-vue": "^1.0.0",
"tdesign-icons-vue-next": "^2.0.0"
}
}
385 changes: 385 additions & 0 deletions test/fixtures/tdesign-icons-pr-data.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions test/tdesign/icons.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it, vi } from 'vitest'
import start from '../../src/tdesign/icons'
import pr_data from '../fixtures/tdesign-icons-pr-data.json' with { type: 'json' }

vi.mock('../../src/utils.ts', async () => {
return {
...(await vi.importActual<typeof import('../../src/utils.ts')>('../../src/utils.ts')),
getPrData: () => pr_data,
getPkgLatestVersion: () => 'x.x.x',
cloneRepo: () => vi.fn(),
}
})

describe('tdesign/icons', () => {
describe('comment', () => {
it('/pr-vue', async () => {
const context = {
owner: 'Tencent',
repo: 'tdesign-icons',
pr_number: 1,
comment: '/pr-vue',
token: 'token',
}
start(context)
})
})
})
8 changes: 0 additions & 8 deletions test/tdesign/icons.ts

This file was deleted.

2 changes: 1 addition & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['test/**/*.ts'],
include: ['test/**/*.test.ts'],
},
})

0 comments on commit 4a6d29a

Please sign in to comment.