Clean up unused code and add default empty string when label is unavailable (#290)
* chore: Refactor event handling in Action class * Refactor event handling in Action class
This commit is contained in:
Родитель
7dd78cbf63
Коммит
58c13ec184
|
@ -39,7 +39,7 @@ class Action {
|
|||
return ((_d = (_b = (issueNumber > 0 ? issueNumber : undefined)) !== null && _b !== void 0 ? _b : (_c = github_1.context.issue) === null || _c === void 0 ? void 0 : _c.number) !== null && _d !== void 0 ? _d : (_e = github_1.context.payload.issue) === null || _e === void 0 ? void 0 : _e.number);
|
||||
}
|
||||
async run() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||
if (utils_2.errorLoggingIssue) {
|
||||
const errorIssue = (0, utils_2.errorLoggingIssue)(this.repoName, this.repoOwner);
|
||||
if (this.repoName === (errorIssue === null || errorIssue === void 0 ? void 0 : errorIssue.repo) &&
|
||||
|
@ -73,7 +73,7 @@ class Action {
|
|||
await this.onClosed(octokit, github_1.context.payload);
|
||||
break;
|
||||
case 'labeled':
|
||||
await this.onLabeled(octokit, github_1.context.payload.label.name);
|
||||
await this.onLabeled(octokit, (_f = (_e = (_d = github_1.context.payload) === null || _d === void 0 ? void 0 : _d.label) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '');
|
||||
break;
|
||||
case 'assigned':
|
||||
await this.onAssigned(octokit, github_1.context.payload.assignee.login);
|
||||
|
@ -96,7 +96,7 @@ class Action {
|
|||
}
|
||||
}
|
||||
else if (event === 'create') {
|
||||
await this.onCreated(new octokit_1.OctoKit(token, { repo: this.repoName, owner: this.repoOwner }, { readonly }), (_d = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.payload) === null || _d === void 0 ? void 0 : _d.ref, (_f = (_e = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.payload) === null || _e === void 0 ? void 0 : _e.sender) === null || _f === void 0 ? void 0 : _f.login);
|
||||
await this.onCreated(new octokit_1.OctoKit(token, { repo: this.repoName, owner: this.repoOwner }, { readonly }), (_g = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.payload) === null || _g === void 0 ? void 0 : _g.ref, (_j = (_h = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.payload) === null || _h === void 0 ? void 0 : _h.sender) === null || _j === void 0 ? void 0 : _j.login);
|
||||
}
|
||||
else {
|
||||
await this.onTriggered(new octokit_1.OctoKit(token, { repo: this.repoName, owner: this.repoOwner }, { readonly }));
|
||||
|
|
|
@ -91,7 +91,7 @@ export abstract class Action {
|
|||
await this.onClosed(octokit, context.payload);
|
||||
break;
|
||||
case 'labeled':
|
||||
await this.onLabeled(octokit, context.payload.label.name);
|
||||
await this.onLabeled(octokit, context.payload?.label?.name ?? '');
|
||||
break;
|
||||
case 'assigned':
|
||||
await this.onAssigned(octokit, context.payload.assignee.login);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = require("../api/octokit");
|
||||
const Action_1 = require("../common/Action");
|
||||
const utils_1 = require("../common/utils");
|
||||
const EnglishPlease_1 = require("./EnglishPlease");
|
||||
|
@ -27,16 +26,6 @@ class EnglishPlease extends Action_1.Action {
|
|||
if (label == nonEnglishLabel)
|
||||
await this.doLanguageSpecific(issue);
|
||||
}
|
||||
async onTriggered(_octokit) {
|
||||
// This function is only called during a manual workspace dispatch event
|
||||
// caused by a webhook, so we know to expect some inputs.
|
||||
const auth = await this.getToken();
|
||||
const repo = (0, utils_1.getRequiredInput)('repo');
|
||||
const owner = (0, utils_1.getRequiredInput)('owner');
|
||||
const issueNumber = +(0, utils_1.getRequiredInput)('issue_number');
|
||||
const octokitIssue = new octokit_1.OctoKitIssue(auth, { owner, repo }, { number: issueNumber });
|
||||
await this.doLanguageSpecific(octokitIssue);
|
||||
}
|
||||
}
|
||||
new EnglishPlease().run(); // eslint-disable-line
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1,4 +1,4 @@
|
|||
import { OctoKit, OctoKitIssue } from '../api/octokit';
|
||||
import { OctoKitIssue } from '../api/octokit';
|
||||
import { Action } from '../common/Action';
|
||||
import { getRequiredInput } from '../common/utils';
|
||||
import { EnglishPleaseLabler, LanguageSpecificLabeler } from './EnglishPlease';
|
||||
|
@ -33,17 +33,6 @@ class EnglishPlease extends Action {
|
|||
async onLabeled(issue: OctoKitIssue, label: string) {
|
||||
if (label == nonEnglishLabel) await this.doLanguageSpecific(issue);
|
||||
}
|
||||
|
||||
async onTriggered(_octokit: OctoKit): Promise<void> {
|
||||
// This function is only called during a manual workspace dispatch event
|
||||
// caused by a webhook, so we know to expect some inputs.
|
||||
const auth = await this.getToken();
|
||||
const repo = getRequiredInput('repo');
|
||||
const owner = getRequiredInput('owner');
|
||||
const issueNumber = +getRequiredInput('issue_number');
|
||||
const octokitIssue = new OctoKitIssue(auth, { owner, repo }, { number: issueNumber });
|
||||
await this.doLanguageSpecific(octokitIssue);
|
||||
}
|
||||
}
|
||||
|
||||
new EnglishPlease().run() // eslint-disable-line
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = require("../api/octokit");
|
||||
const Action_1 = require("../common/Action");
|
||||
const utils_1 = require("../common/utils");
|
||||
const FeatureRequest_1 = require("./FeatureRequest");
|
||||
|
@ -35,16 +34,6 @@ class FeatureRequest extends Action_1.Action {
|
|||
super(...arguments);
|
||||
this.id = 'FeatureRequest';
|
||||
}
|
||||
async onTriggered(_github) {
|
||||
// This function is only called during a manual workspace dispatch event
|
||||
// caused by a webhook, so we know to expect some inputs.
|
||||
const auth = await this.getToken();
|
||||
const repo = (0, utils_1.getRequiredInput)('repo');
|
||||
const owner = (0, utils_1.getRequiredInput)('owner');
|
||||
const issue = JSON.parse((0, utils_1.getRequiredInput)('issue_number'));
|
||||
const octokitIssue = new octokit_1.OctoKitIssue(auth, { owner, repo }, { number: issue.number });
|
||||
await new FeatureRequest_1.FeatureRequestOnMilestone(octokitIssue, config.comments.init, config.milestones.candidateID).run();
|
||||
}
|
||||
async onLabeled(github, label) {
|
||||
if (label === config.featureRequestLabel) {
|
||||
await new FeatureRequest_1.FeatureRequestOnLabel(github, +(0, utils_1.getRequiredInput)('milestoneDelaySeconds'), config.milestones.candidateID, config.featureRequestLabel).run();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { OctoKit, OctoKitIssue } from '../api/octokit';
|
||||
import { OctoKitIssue } from '../api/octokit';
|
||||
import { Action } from '../common/Action';
|
||||
import { getInput, getRequiredInput } from '../common/utils';
|
||||
import { FeatureRequestConfig, FeatureRequestOnLabel, FeatureRequestOnMilestone } from './FeatureRequest';
|
||||
|
@ -34,22 +34,6 @@ const config: FeatureRequestConfig = {
|
|||
class FeatureRequest extends Action {
|
||||
id = 'FeatureRequest';
|
||||
|
||||
async onTriggered(_github: OctoKit) {
|
||||
// This function is only called during a manual workspace dispatch event
|
||||
// caused by a webhook, so we know to expect some inputs.
|
||||
const auth = await this.getToken();
|
||||
const repo = getRequiredInput('repo');
|
||||
const owner = getRequiredInput('owner');
|
||||
const issue = JSON.parse(getRequiredInput('issue_number'));
|
||||
|
||||
const octokitIssue = new OctoKitIssue(auth, { owner, repo }, { number: issue.number });
|
||||
await new FeatureRequestOnMilestone(
|
||||
octokitIssue,
|
||||
config.comments.init!,
|
||||
config.milestones.candidateID,
|
||||
).run();
|
||||
}
|
||||
|
||||
async onLabeled(github: OctoKitIssue, label: string) {
|
||||
if (label === config.featureRequestLabel) {
|
||||
await new FeatureRequestOnLabel(
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = require("../api/octokit");
|
||||
const Action_1 = require("../common/Action");
|
||||
const utils_1 = require("../common/utils");
|
||||
const TestPlanitemValidator_1 = require("./TestPlanitemValidator");
|
||||
|
@ -13,8 +12,9 @@ class TestPlanItemValidatorAction extends Action_1.Action {
|
|||
super(...arguments);
|
||||
this.id = 'TestPlanItemValidator';
|
||||
}
|
||||
async runValidation(issue, token) {
|
||||
await new TestPlanitemValidator_1.TestPlanItemValidator(issue, token !== null && token !== void 0 ? token : (0, utils_1.getRequiredInput)('token'), (0, utils_1.getRequiredInput)('refLabel'), (0, utils_1.getRequiredInput)('label'), (0, utils_1.getRequiredInput)('invalidLabel'), (0, utils_1.getRequiredInput)('comment')).run();
|
||||
async runValidation(issue) {
|
||||
const auth = await this.getToken();
|
||||
await new TestPlanitemValidator_1.TestPlanItemValidator(issue, auth !== null && auth !== void 0 ? auth : (0, utils_1.getRequiredInput)('token'), (0, utils_1.getRequiredInput)('refLabel'), (0, utils_1.getRequiredInput)('label'), (0, utils_1.getRequiredInput)('invalidLabel'), (0, utils_1.getRequiredInput)('comment')).run();
|
||||
}
|
||||
async onOpened(issue) {
|
||||
await this.runValidation(issue);
|
||||
|
@ -25,16 +25,6 @@ class TestPlanItemValidatorAction extends Action_1.Action {
|
|||
async onEdited(issue) {
|
||||
await this.runValidation(issue);
|
||||
}
|
||||
async onTriggered(_octokit) {
|
||||
// This function is only called during a manual workspace dispatch event
|
||||
// caused by a webhook, so we know to expect some inputs.
|
||||
const auth = await this.getToken();
|
||||
const repo = (0, utils_1.getRequiredInput)('repo');
|
||||
const owner = (0, utils_1.getRequiredInput)('owner');
|
||||
const issueNumber = +(0, utils_1.getRequiredInput)('issue_number');
|
||||
const octokitIssue = new octokit_1.OctoKitIssue(auth, { owner, repo }, { number: issueNumber });
|
||||
await this.runValidation(octokitIssue, auth);
|
||||
}
|
||||
}
|
||||
new TestPlanItemValidatorAction().run(); // eslint-disable-line
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { OctoKit, OctoKitIssue } from '../api/octokit';
|
||||
import { OctoKitIssue } from '../api/octokit';
|
||||
import { Action } from '../common/Action';
|
||||
import { getRequiredInput } from '../common/utils';
|
||||
import { TestPlanItemValidator } from './TestPlanitemValidator';
|
||||
|
@ -11,10 +11,11 @@ import { TestPlanItemValidator } from './TestPlanitemValidator';
|
|||
class TestPlanItemValidatorAction extends Action {
|
||||
id = 'TestPlanItemValidator';
|
||||
|
||||
async runValidation(issue: OctoKitIssue, token?: string) {
|
||||
async runValidation(issue: OctoKitIssue) {
|
||||
const auth = await this.getToken();
|
||||
await new TestPlanItemValidator(
|
||||
issue,
|
||||
token ?? getRequiredInput('token'),
|
||||
auth ?? getRequiredInput('token'),
|
||||
getRequiredInput('refLabel'),
|
||||
getRequiredInput('label'),
|
||||
getRequiredInput('invalidLabel'),
|
||||
|
@ -33,18 +34,6 @@ class TestPlanItemValidatorAction extends Action {
|
|||
protected override async onEdited(issue: OctoKitIssue) {
|
||||
await this.runValidation(issue);
|
||||
}
|
||||
|
||||
protected override async onTriggered(_octokit: OctoKit): Promise<void> {
|
||||
// This function is only called during a manual workspace dispatch event
|
||||
// caused by a webhook, so we know to expect some inputs.
|
||||
const auth = await this.getToken();
|
||||
const repo = getRequiredInput('repo');
|
||||
const owner = getRequiredInput('owner');
|
||||
const issueNumber = +getRequiredInput('issue_number');
|
||||
|
||||
const octokitIssue = new OctoKitIssue(auth, { owner, repo }, { number: issueNumber });
|
||||
await this.runValidation(octokitIssue, auth);
|
||||
}
|
||||
}
|
||||
|
||||
new TestPlanItemValidatorAction().run() // eslint-disable-line
|
||||
|
|
Загрузка…
Ссылка в новой задаче