Skip to content

Commit

Permalink
Refactor getAssignee method in Action class (#291)
Browse files Browse the repository at this point in the history
* Refactor getAssignee method in Action class

* Update action.yml files with optional event and action inputs
  • Loading branch information
bhavyaus authored Jul 30, 2024
1 parent 58c13ec commit 58b7b93
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
28 changes: 27 additions & 1 deletion classifier-deep/monitor/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@ description: Alerts when assignees added by the bot are unassigned
inputs:
token:
description: GitHub token with issue, comment, and label read/write permissions
default: ${{ github.token }}
app_id:
description: GitHub App ID
required: false
app_installation_id:
description: GitHub App Installation ID
required: false
app_private_key:
description: GitHub App Private Key
required: false
owner:
description: Repository owner
required: false
repo:
description: Repository name
required: false
issue_number:
description: Issue number
required: false
event:
description: Event name for a triggered action. Otherwise, this is obtained from the github context.
required: false
action:
description: Action name for a triggered action. Otherwise, this is obtained from the github context.
required: false
payload:
description: Payload object for the github action
required: true
botName:
description: The login of the bot
required: true
Expand Down
15 changes: 13 additions & 2 deletions common/Action.js

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

15 changes: 13 additions & 2 deletions common/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ export abstract class Action {
);
}

getAssignee(): string {
const payload = getInput('payload');
let assignee = '';
if (payload) {
assignee = JSON.parse(payload).assignee;
} else {
assignee = context.payload.assignee.login;
}
return assignee;
}

public async run() {
if (errorLoggingIssue) {
const errorIssue = errorLoggingIssue(this.repoName, this.repoOwner);
Expand Down Expand Up @@ -94,10 +105,10 @@ export abstract class Action {
await this.onLabeled(octokit, context.payload?.label?.name ?? '');
break;
case 'assigned':
await this.onAssigned(octokit, context.payload.assignee.login);
await this.onAssigned(octokit, this.getAssignee());
break;
case 'unassigned':
await this.onUnassigned(octokit, context.payload.assignee.login);
await this.onUnassigned(octokit, this.getAssignee());
break;
case 'edited':
await this.onEdited(octokit);
Expand Down

0 comments on commit 58b7b93

Please sign in to comment.