Skip to content

Commit

Permalink
fix(github): support dots in repo names, fix #183
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 25, 2021
1 parent 0d9a4f6 commit a090814
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/plugin-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export function apply(ctx: Context, config: Config = {}) {
return '请点击下面的链接继续操作:\n' + url
})

const repoRegExp = /^[\w.-]+\/[\w.-]+$/

ctx.command('github.repos [name]', 'GitHub 仓库')
.userFields(['ghAccessToken', 'ghRefreshToken'])
.option('add', '-a 监听一个新的仓库')
Expand All @@ -84,7 +86,7 @@ export function apply(ctx: Context, config: Config = {}) {
.action(async ({ session, options }, name) => {
if (options.add || options.delete) {
if (!name) return '请输入仓库名。'
if (!/^[\w-]+\/[\w-]+$/.test(name)) return '请输入正确的仓库名。'
if (!repoRegExp.test(name)) return '请输入正确的仓库名。'
if (!session.user.ghAccessToken) {
return ctx.app.github.authorize(session, '要使用此功能,请对机器人进行授权。输入你的 GitHub 用户名。')
}
Expand Down Expand Up @@ -168,7 +170,7 @@ export function apply(ctx: Context, config: Config = {}) {
if (options.add || options.delete) {
if (!session.channel) return '当前不是群聊上下文。'
if (!name) return '请输入仓库名。'
if (!/^[\w-]+\/[\w-]+$/.test(name)) return '请输入正确的仓库名。'
if (!repoRegExp.test(name)) return '请输入正确的仓库名。'

name = name.toLowerCase()
const webhooks = session.channel.githubWebhooks
Expand Down

0 comments on commit a090814

Please sign in to comment.