Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('CheckAutoDemotionAction', () => {
}
])
issueParser.parseIssue.mockReturnValueOnce({
duration: '1'
Duration: '1'
})

const check = new CheckAutoDemotionAction()
Expand Down
41 changes: 23 additions & 18 deletions admin-support-cli/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33771,7 +33771,7 @@ class CheckAutoDemotionAction {
});
for (const issue of listOfIssues) {
const parsedIssue = parseIssue(issue.body);
const issueDuration = parseInt(parsedIssue.duration);
const issueDuration = parseInt(parsedIssue.Duration);
const promotedTime = Date.parse(issue.created_at);
const passedTime = Date.now() - promotedTime;
if (passedTime > issueDuration * HOUR_IN_MILLIS) {
Expand Down Expand Up @@ -33923,9 +33923,6 @@ class CommandDoesNotExistError extends Error {
}

async function run() {
/* istanbul ignore next */
if (!githubExports.context.payload.issue)
return coreExports.setFailed('No issue found!');
const inputs = getInputs();
try {
coreExports.info('Running Action with input:');
Expand All @@ -33936,9 +33933,15 @@ async function run() {
commandInstance = new CheckAutoDemotionAction();
break;
case Action.DEMOTION_REPORT:
/* istanbul ignore next */
if (!githubExports.context.payload.issue)
return coreExports.setFailed('No issue found!');
commandInstance = new DemotionReportAction();
break;
case Action.PROMOTE_DEMOTE:
/* istanbul ignore next */
if (!githubExports.context.payload.issue)
return coreExports.setFailed('No issue found!');
commandInstance = new PromoteDemoteAction();
break;
default:
Expand All @@ -33953,20 +33956,22 @@ async function run() {
catch (error) {
coreExports.error(error);
// Report the error in a comment
const octokit = githubExports.getOctokit(inputs.adminToken);
await octokit.rest.issues.createComment({
owner: githubExports.context.repo.owner,
repo: githubExports.context.repo.repo,
issue_number: githubExports.context.payload.issue.number,
body: dedent `### :exclamation: An Error Occurred :exclamation:

${error.message}

<sub>
Details: <a href="https://github.com/${githubExports.context.repo.owner}/${githubExports.context.repo.repo}/actions/runs/${coreExports.getInput('run_id')}">here</a>.
</sub>
`
});
if (githubExports.context.payload.issue) {
const octokit = githubExports.getOctokit(inputs.adminToken);
await octokit.rest.issues.createComment({
owner: githubExports.context.repo.owner,
repo: githubExports.context.repo.repo,
issue_number: githubExports.context.payload.issue.number,
body: dedent `### :exclamation: An Error Occurred :exclamation:

${error.message}

<sub>
Details: <a href="https://github.com/${githubExports.context.repo.owner}/${githubExports.context.repo.repo}/actions/runs/${coreExports.getInput('run_id')}">here</a>.
</sub>
`
});
}
coreExports.debug(`Exit Code: ${process.exitCode}`);
return coreExports.setFailed('An error occurred running the command!');
}
Expand Down
2 changes: 1 addition & 1 deletion admin-support-cli/dist/index.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { GitHub } from '@actions/github/lib/utils.js';
import type { Inputs, Result } from '../../types.js';
import { Command } from '../command.js';
export declare class CheckAutoDemotionAction implements Command {
api: InstanceType<typeof GitHub>;
params: Inputs;
constructor();
validate(): Promise<void>;
execute(): Promise<Result>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { GitHub } from '@actions/github/lib/utils.js';
import type { Inputs, Result } from '../../types.js';
import { Command } from '../command.js';
export declare class DemotionReportAction implements Command {
api: InstanceType<typeof GitHub>;
params: Inputs;
constructor();
validate(): Promise<void>;
execute(): Promise<Result>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { GitHub } from '@actions/github/lib/utils.js';
import type { Inputs, Result } from '../../types.js';
import { Command } from '../command.js';
export declare class PromoteDemoteAction implements Command {
api: InstanceType<typeof GitHub>;
params: Inputs;
constructor();
validate(): Promise<void>;
execute(): Promise<Result>;
}
7 changes: 7 additions & 0 deletions admin-support-cli/dist/src/commands/command.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Inputs, Result } from '../types.js';
export interface Command {
api: any;
params: Inputs;
validate(): Promise<void>;
execute(): Promise<Result>;
}
15 changes: 15 additions & 0 deletions admin-support-cli/dist/src/enums.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export declare enum Action {
/** Check Auto Demotion */
CHECK_AUTO_DEMOTION = "check_auto_demotion",
/** Demotion Report */
DEMOTION_REPORT = "demotion_report",
/** Promote or Demote */
PROMOTE_DEMOTE = "promote_demote"
}
/** Role */
export declare enum Role {
/** Admin */
ADMIN = "admin",
/** Member */
MEMBER = "member"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class CommandDoesNotExistError extends Error {
constructor(message: string);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class ParameterRequiredError extends Error {
constructor(message: string);
}
1 change: 1 addition & 0 deletions admin-support-cli/dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
2 changes: 2 additions & 0 deletions admin-support-cli/dist/src/inputs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Inputs } from './types.js';
export declare function getInputs(): Inputs;
1 change: 1 addition & 0 deletions admin-support-cli/dist/src/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function run(): Promise<void>;
53 changes: 53 additions & 0 deletions admin-support-cli/dist/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Role } from './enums.js';
/** Action Inputs */
export type Inputs = {
/** Required Inputs */
/** Action to Perform */
action: string;
/** Allowed Organizations */
allowedOrgs: string[];
/** Admin Token */
adminToken: string;
/** Optional Inputs */
/** Demotion Date */
demotionDate: Date | undefined;
/** Issue Number */
issueNumber: number | undefined;
/** Parsed Issue */
parsedIssue: {
/** Description */
description: string | undefined;
/** Duration */
duration: number;
/** Ticket */
ticket: string | undefined;
/** Target Organization */
organization: string;
} | undefined;
/** Promotion Date */
promotionDate: Date | undefined;
/** Report Path */
reportPath: string | undefined;
/** Role */
role: Role | undefined;
/** Username */
username: string | undefined;
};
/** Audit Log API Response Item */
export type AuditLogEntry = {
_document_id: string;
action: string;
actor: string;
event: string;
name: string;
org: string;
repo: string;
user: string;
};
/** Command Result */
export type Result = {
/** Result Status */
status: 'success' | 'error' | undefined;
/** Output */
output: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class CheckAutoDemotionAction implements Command {
for (const issue of listOfIssues) {
const parsedIssue = parseIssue(issue.body!)

const issueDuration = parseInt(parsedIssue.duration as string)
const issueDuration = parseInt(parsedIssue.Duration as string)
const promotedTime = Date.parse(issue.created_at)
const passedTime = Date.now() - promotedTime

Expand Down
35 changes: 20 additions & 15 deletions admin-support-cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { CommandDoesNotExistError } from './exceptions/CommandDoesNotExistError.
import { getInputs } from './inputs.js'

export async function run() {
/* istanbul ignore next */
if (!github.context.payload.issue) return core.setFailed('No issue found!')

const inputs = getInputs()

try {
Expand All @@ -25,9 +22,15 @@ export async function run() {
commandInstance = new CheckAutoDemotionAction()
break
case Action.DEMOTION_REPORT:
/* istanbul ignore next */
if (!github.context.payload.issue)
return core.setFailed('No issue found!')
commandInstance = new DemotionReportAction()
break
case Action.PROMOTE_DEMOTE:
/* istanbul ignore next */
if (!github.context.payload.issue)
return core.setFailed('No issue found!')
Comment thread
Vestergaard32 marked this conversation as resolved.
commandInstance = new PromoteDemoteAction()
break
default:
Expand All @@ -45,20 +48,22 @@ export async function run() {
core.error(error)

// Report the error in a comment
const octokit = github.getOctokit(inputs.adminToken)
await octokit.rest.issues.createComment({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: github.context.payload.issue.number,
body: dedent`### :exclamation: An Error Occurred :exclamation:
if (github.context.payload.issue) {
const octokit = github.getOctokit(inputs.adminToken)
await octokit.rest.issues.createComment({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: github.context.payload.issue.number,
body: dedent`### :exclamation: An Error Occurred :exclamation:

${error.message}
${error.message}

<sub>
Details: <a href="https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${core.getInput('run_id')}">here</a>.
</sub>
`
})
<sub>
Details: <a href="https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${core.getInput('run_id')}">here</a>.
</sub>
`
})
}

core.debug(`Exit Code: ${process.exitCode}`)
return core.setFailed('An error occurred running the command!')
Expand Down