Skip to content

Commit

Permalink
change: 通过标题判断议题是否为指定类型
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Mar 7, 2021
1 parent 7feab58 commit 93af2c5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 34 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# NoneBot2 Plugin Issue Bot
# NoneBot2 Store Issue Bot

[NoneBot2](https://github.com/nonebot/nonebot2) 插件/协议/机器人 发布机器人
[NoneBot2](https://github.com/nonebot/nonebot2) 插件/协议/机器人 商店发布机器人

## 主要功能

根据 插件/协议/机器人 发布(带 Plugin/Adapter/Bot 标签)议题,自动修改对应文件,并创建拉取请求。
根据 插件/协议/机器人 发布(带 Plugin/Adapter/Bot 标题)议题,自动修改对应文件,并创建拉取请求。

## 自动处理

- 插件发布议题创建后,自动根据议题内容创建拉取请求
- 商店发布议题创建后,自动根据议题内容创建拉取请求
- 相关议题修改时,自动修改已创建的拉取请求,如果没有创建则重新创建
- 拉取请求关闭时,自动关闭对应议题,并删除对应分支
- 已经创建的拉取请求在其他拉取请求合并后,自动解决冲突
Expand Down
51 changes: 36 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as exec from '@actions/exec'
import {
checkCommitType,
checkLabel,
checkTitle,
closeIssue,
commitandPush,
createPullRequest,
Expand Down Expand Up @@ -85,36 +86,45 @@ async function run(): Promise<void> {
['opened', 'reopened', 'edited'].includes(github.context.payload.action)
) {
// 从 GitHub Context 中获取议题的相关信息
const issueNumber = github.context.payload.issue?.number
const issue_number = github.context.payload.issue?.number
const issueBody = github.context.payload.issue?.body

if (!issueNumber || !issueBody) {
if (!issue_number || !issueBody) {
core.setFailed('无法获取议题的信息')
return
}

// 检查是否含有指定标签
const publishType = checkLabel(github.context.payload.issue?.labels)
// 检查是否为指定类型的提交
const publishType = checkTitle(github.context.payload.issue?.title)
if (!publishType) {
core.info('没有指定标签,已跳过')
core.info('不是商店发布议题,已跳过')
return
}

// 创建新分支
// 命名示例 plugin/issue123
const branchName = `plugin/issue${issueNumber}`
const branchName = `plugin/issue${issue_number}`
await exec.exec('git', ['checkout', '-b', branchName])

// 插件作者信息
const username = github.context.payload.issue?.user.login

// 更新文件并提交更改
// 提取信息
const info = extractInfo(publishType, issueBody, username)

// 自动给议题添加标签
await octokit.issues.addLabels({
...github.context.repo,
issue_number,
labels: [info.type]
})

// 更新文件并提交更改
await updateFile(info)
await commitandPush(branchName, info)

// 创建拉取请求
await createPullRequest(octokit, info, issueNumber, branchName, base)
await createPullRequest(octokit, info, issue_number, branchName, base)
} else {
core.info('事件不是议题开启,重新开启或修改,已跳过')
}
Expand Down
30 changes: 24 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import * as bot from './types/bot'
import * as plugin from './types/plugin'
import {Info, PublishType} from './info'

/**检查是否含有指定标签
/**检查标签是否含有指定类型
*
* 并返回指定的类型(Plugin Adapter Bot)
*
* 如果无返回则说明不含指定标签
* 如果无返回则说明不含指定类型
*/
export function checkLabel(
labels: IssuesGetResponseData['labels']
Expand All @@ -25,7 +25,25 @@ export function checkLabel(
}
}

/**检查是否含有指定类型
/**检查标题是否含有指定类型
*
* 并返回指定的类型(Plugin Adapter Bot)
*
* 如果无返回则说明不含指定类型
*/
export function checkTitle(title: string): PublishType | undefined {
if (title.startsWith('Adapter:')) {
return 'Adapter'
}
if (title.startsWith('Bot:')) {
return 'Bot'
}
if (title.startsWith('Plugin:')) {
return 'Plugin'
}
}

/**检查提交信息是否含有指定类型
*
* 并返回指定的类型(Plugin Adapter Bot)
*
Expand All @@ -34,13 +52,13 @@ export function checkLabel(
export function checkCommitType(
commitMessage: string
): PublishType | undefined {
if (commitMessage.includes(':beers: publish adapter')) {
if (commitMessage.startsWith(':beers: publish adapter')) {
return 'Adapter'
}
if (commitMessage.includes(':beers: publish bot')) {
if (commitMessage.startsWith(':beers: publish bot')) {
return 'Bot'
}
if (commitMessage.includes(':beers: publish plguin')) {
if (commitMessage.startsWith(':beers: publish plguin')) {
return 'Plugin'
}
}
Expand Down

0 comments on commit 93af2c5

Please sign in to comment.