Skip to content

Commit

Permalink
Clean up unused code and add default empty string when label is unava…
Browse files Browse the repository at this point in the history
…ilable (#290)

* chore: Refactor event handling in Action class

* Refactor event handling in Action class
  • Loading branch information
bhavyaus authored Jul 30, 2024
1 parent 7dd78cb commit 58c13ec
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 83 deletions.
6 changes: 3 additions & 3 deletions common/Action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions english-please/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions english-please/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
11 changes: 0 additions & 11 deletions feature-request/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 1 addition & 17 deletions feature-request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 3 additions & 13 deletions test-plan-item-validator/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions test-plan-item-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
* 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';

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'),
Expand All @@ -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

0 comments on commit 58c13ec

Please sign in to comment.