Add custom message support

This commit is contained in:
Kyle Fang
2018-10-21 11:15:31 +08:00
parent ced94cd040
commit 355213bb34
3 changed files with 19 additions and 9 deletions

View File

@@ -1 +1,2 @@
regex: ^PR-TITLE.*$
regex: ^PR-TITLE.*$
message: Please correct your PR Title

View File

@@ -20,7 +20,7 @@ default_events:
# - fork
# - gollum
# - issue_comment
- issues
# - issues
# - label
# - milestone
# - member
@@ -32,7 +32,7 @@ default_events:
# - project_card
# - project_column
# - public
# - pull_request
- pull_request
# - pull_request_review
# - pull_request_review_comment
# - push
@@ -67,7 +67,7 @@ default_permissions:
# Issues and related comments, assignees, labels, and milestones.
# https://developer.github.com/v3/apps/permissions/#permission-on-issues
issues: write
# issues: write
# Search repositories, list collaborators, and access repository metadata.
# https://developer.github.com/v3/apps/permissions/#metadata-permissions
@@ -79,7 +79,7 @@ default_permissions:
# Pull requests and related comments, assignees, labels, milestones, and merges.
# https://developer.github.com/v3/apps/permissions/#permission-on-pull-requests
# pull_requests: read
pull_requests: write
# Manage the post-receive hooks for a repository.
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-hooks

View File

@@ -3,14 +3,23 @@ import { Application } from 'probot'
import getConfig from 'probot-config'
export = (app: Application) => {
app.log('App Loaded')
app.on(['pull_request.opened', 'pull_request.edited'], async (context) => {
context.log('Event triggered')
const config = await getConfig(context, 'pr-title.yml');
if (config && typeof config.regex === 'string') {
app.log(config.regex)
app.log(context.payload.pull_request)
context.log(config.regex)
const title: string = context.payload.pull_request.title;
if ((new RegExp(config.regex)).test(title)) {
context.log('No action needed')
return;
}
const comment = context.issue({
body: config.message || "Please correct your PR title"
})
context.github.issues.createComment(comment)
} else {
app.log('config file not found')
context.log('config file not found')
}
});
}