Skip to content
Permalink
Browse files
tweak issue class and issue opened hook
  • Loading branch information
plainheart committed Nov 29, 2021
1 parent 22ddfd1 commit 918181dfb43ef14747011d8702b4b837aadf0d7e
Showing 2 changed files with 6 additions and 34 deletions.
@@ -11,34 +11,22 @@ module.exports = (/** @type import('probot').Probot */ app) => {

await issue.init();

// Ignore comment because it will commented when adding invalid label
const comment = !issue.response || issue.response === text.NOT_USING_TEMPLATE
? Promise.resolve()
: commentIssue(context, issue.response);

await comment;
await commentIssue(context, text.ISSUE_CREATED);

const addLabels = issue.addLabels.length
? context.octokit.issues.addLabels(
&& context.octokit.issues.addLabels(
context.issue({
labels: issue.addLabels
})
)
: Promise.resolve();
);

const removeLabel = issue.removeLabel
? getRemoveLabel(context, issue.removeLabel)
: Promise.resolve();
const removeLabel = issue.removeLabel && getRemoveLabel(context, issue.removeLabel);

// then add and remove label
// add and remove label
await Promise.all([addLabels, removeLabel]);

// translate finally
const translate = issue.response === text.ISSUE_CREATED
? translateIssue(context, issue)
: Promise.resolve();

return translate;
return translateIssue(context, issue);
});

app.on(['issues.closed'], context => {
@@ -1,4 +1,3 @@
const text = require('./text');
const label = require('./label');
const { isCommitter } = require('./coreCommitters');
const { translate } = require('./translator');
@@ -14,8 +13,6 @@ class Issue {
// false -> translated -> not in English
this.translatedTitle = null;
this.translatedBody = null;
this.issueType = null;
this.response = null;
this.addLabels = [];
this.removeLabel = null;
}
@@ -50,19 +47,6 @@ class Issue {
this.translatedBody = res.lang !== 'en' && [res.translated, res.lang];
}
}

_computeResponse() {
switch(this.context.payload.action) {
case 'opened':
case 'reopened':
this.response = text.ISSUE_CREATED;
break;
case 'edited':
this.response = text.ISSUE_UPDATED;
this.removeLabel = label.WAITING_FOR_HELP;
break;
}
}
}

module.exports = Issue;

0 comments on commit 918181d

Please sign in to comment.