From e7ad43b8914cfd2686d7086826ccc4e46993b79d Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Sat, 24 Mar 2018 18:26:10 -0500 Subject: [PATCH] Add logic to automatically label issues as a question --- org/labelissue.ts | 30 ++++++++++++++++++++++++++++++ settings-peril.json | 6 +++--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 org/labelissue.ts diff --git a/org/labelissue.ts b/org/labelissue.ts new file mode 100644 index 0000000..8189c22 --- /dev/null +++ b/org/labelissue.ts @@ -0,0 +1,30 @@ +import { danger, schedule } from "danger" + +const gh = danger.github as any +const issue = gh.issue +const repo = gh.repository + +const qWords: string[] = ["how", "who", "what", "where", "when", "why", "which"] + +if (issue.title.slice(-1) == "?") { + addLabel() +} else { + const title = issue.title.toLowerCase() + for (var i = 0; i < qWords.length; i++) { + if (title.startsWith(qWords[i])) { + addLabel() + break + } + } +} + +function addLabel() { + schedule(async () => { + await danger.github.api.issues.addLabels({ + owner: repo.owner.login, + repo: repo.name, + number: issue.number, + labels: ["question"], + }) + }) +} diff --git a/settings-peril.json b/settings-peril.json index 8d1cb3f..5a07293 100644 --- a/settings-peril.json +++ b/settings-peril.json @@ -4,9 +4,9 @@ }, "rules": { "pull_request": "RxSwiftCommunity/peril@org/all-prs.ts", + "pull_request.closed": "RxSwiftCommunity/peril@org/aeryn.ts", "issue": "RxSwiftCommunity/peril@org/all-issues.ts", - "pull_request.closed": "RxSwiftCommunity/peril@org/aeryn.ts" + "issue.opened": "RxSwiftCommunity/peril@org/labelissue.ts" }, - "repos": { - } + "repos": {} }