Skip to content
Permalink
Browse files
Merge pull request #9 from apache/check-title
feat: check if the title is valid when an issue is opened.
  • Loading branch information
pissang committed Dec 9, 2021
2 parents d537ba7 + 554af5d commit 4ecd643c8398829753e7bea993769c15ac6c05a9
Showing 4 changed files with 46 additions and 7 deletions.
@@ -25,7 +25,8 @@ module.exports = (/** @type import('probot').Probot */ app) => {
// add and remove label
await Promise.all([addLabels, removeLabel]);

const invalid = issue.addLabels.includes(labelText.INVALID);
const invalid = issue.addLabels.includes(labelText.INVALID)
|| issue.addLabels.includes(labelText.MISSING_TITLE);

// translate finally if valid
return invalid || translateIssue(context, issue);
@@ -62,13 +63,22 @@ module.exports = (/** @type import('probot').Probot */ app) => {

switch (labelName) {
case labelText.INVALID:
return Promise.all([commentIssue(context, text.NOT_USING_TEMPLATE), closeIssue(context)]);
return Promise.all([
commentIssue(context, text.NOT_USING_TEMPLATE),
closeIssue(context)
]);

case labelText.HOWTO:
return Promise.all([commentIssue(context, text.LABEL_HOWTO), closeIssue(context)]);
return Promise.all([
commentIssue(context, text.LABEL_HOWTO),
closeIssue(context)
]);

case labelText.INACTIVE:
return Promise.all([commentIssue(context, text.INACTIVE_ISSUE), closeIssue(context)]);
return Promise.all([
commentIssue(context, text.INACTIVE_ISSUE),
closeIssue(context)
]);

case labelText.MISSING_DEMO:
return Promise.all([
@@ -94,6 +104,12 @@ module.exports = (/** @type import('probot').Probot */ app) => {
closeIssue(context),
getRemoveLabel(context, labelText.WAITING_FOR_COMMUNITY)
]);

case labelText.MISSING_TITLE:
return Promise.all([
commentIssue(context, text.MISSING_TITLE),
closeIssue(context)
]);
}
});

@@ -23,7 +23,12 @@ class Issue {
const isCore = isCommitter(this.issue.author_association, this.issue.user.login);

if (!isCore) {
// avoid opening an issue with no template through `Reference in new issue`
// check if the title is valid
if (this.isMissingTitle()) {
this.addLabels.push(label.MISSING_TITLE);
return;
}
// prevent from opening an issue with no template via `Reference in new issue` button
if (!this.isUsingTemplate()) {
this.addLabels.push(label.INVALID);
return;
@@ -55,9 +60,14 @@ class Issue {
}

isUsingTemplate() {
return this.body.indexOf('Steps To Reproduce') > -1
return this.body.indexOf('Steps to Reproduce') > -1
|| this.body.indexOf('What problem does this feature solve') > - 1;
}

isMissingTitle() {
const title = this.title.trim()
return !title || !title.toLowerCase().replace('[bug]', '').replace('[feature]', '');
}
}

module.exports = Issue;
@@ -15,6 +15,7 @@ const RESOLVED = 'resolved';
const HOWTO = 'howto';
const INACTIVE = 'inactive';
const MISSING_DEMO = 'missing-demo';
const MISSING_TITLE = 'missing-title';
const DUPLICATE = 'duplicate';

const PRIORITY_HIGH = 'priority: high';
@@ -41,6 +42,7 @@ module.exports = {
HOWTO,
INACTIVE,
MISSING_DEMO,
MISSING_TITLE,
DUPLICATE,
PRIORITY_HIGH,
PR_AWAITING_REVIEW,
@@ -80,13 +80,24 @@ For (1), we have decided to use the GitHub issue lists exclusively for work that
For (2), we have found that issues that do not provide proper information upfront usually results in terribly inefficient back-and-forth communication just to extract the basic information needed for actual triaging. This is exactly why we have created this app: to ensure that every issue is created with the necessary information, and to save time on both sides.`;

const ISSUE_COMMENT_TRANSLATE_TIP = 'AT_ISSUE_AUTHOR It seems you are not using English, I\'ve helped translate the content automatically. To make your issue understood by more people and get helped, we\'d like to suggest using English next time. 🤗';
const ISSUE_COMMENT_TRANSLATE_TIP =
'AT_ISSUE_AUTHOR It seems you are not using English, I\'ve helped translate the content automatically. To make your issue understood by more people and get helped, we\'d like to suggest using English next time. 🤗';

const MISSING_TITLE =
`I'm sorry to close this issue for it lacks the necessary title. Please open a new issue **with a _descriptive_ and as _concise_ as possible title to describe your problems or requests**.
Every good bug report or feature request starts with a title. Your issue title is a critical element as it's the first thing maintainers see.
A good issue title makes it easier for maintainers to understand what the issue is, easily locate it, and know what steps they'll need to take to fix it.
Moreover, it's better to include keywords, as this makes it easier to find the issue self and similar issues in searches.`;

module.exports = {
NOT_USING_TEMPLATE,
ISSUE_CREATED,
ISSUE_UPDATED,
MISSING_DEMO,
MISSING_TITLE,
INACTIVE_ISSUE,
PR_OPENED,
LABEL_HOWTO,

0 comments on commit 4ecd643

Please sign in to comment.