Skip to content

Commit

Permalink
Update JSDoc and types
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Mar 22, 2024
1 parent 6ccc0e4 commit e1fb887
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
12 changes: 6 additions & 6 deletions environment_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function setEnvironmentVariables(pairs: { [key: string]: string; } | Map<
}
}
/**
* **\[🅰️ ADVANCED\]** Handle the exportation of PATH in the GitHub Actions runner.
* **\[🅰️ ADVANCED\]** Handle the exportation of `PATH` in the GitHub Actions runner.
*
* > **🛡️ Require Permission**
* >
Expand All @@ -166,7 +166,7 @@ export class GitHubActionsPATHExportation {
#scopeCurrent: boolean;
#scopeSubsequent: boolean;
/**
* **\[🅰️ ADVANCED\]** Create new instance to handle the exportation of PATH in the GitHub Actions runner.
* **\[🅰️ ADVANCED\]** Create new instance to handle the exportation of `PATH` in the GitHub Actions runner.
*
* > **🛡️ Require Permission**
* >
Expand All @@ -180,7 +180,7 @@ export class GitHubActionsPATHExportation {
this.#scopeSubsequent = options.scopeSubsequent ?? true;
}
/**
* Add the PATH.
* Add the `PATH`.
* @param {...string} paths
* @returns {this}
*/
Expand Down Expand Up @@ -209,7 +209,7 @@ export class GitHubActionsPATHExportation {
return this;
}
/**
* Clear the PATH for all of the subsequent steps which set in the current step.
* Clear the `PATH` for all of the subsequent steps which set in the current step.
* @returns {this}
*/
clearSubsequent(): this {
Expand All @@ -219,7 +219,7 @@ export class GitHubActionsPATHExportation {
return this;
}
/**
* Optimize the PATH for all of the subsequent steps which set in the current step to reduce size whenever possible.
* Optimize the `PATH` for all of the subsequent steps which set in the current step to reduce size whenever possible.
* @returns {this}
*/
optimizeSubsequent(): this {
Expand All @@ -230,7 +230,7 @@ export class GitHubActionsPATHExportation {
}
}
/**
* Add the PATH.
* Add the `PATH`.
*
* > **🛡️ Require Permission**
* >
Expand Down
6 changes: 6 additions & 0 deletions log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export function exitLogGroup(): void {
export {
exitLogGroup as endLogGroup
};
/**
* GitHub Actions annotation type.
*/
export enum GitHubActionsAnnotationType {
error = "error",
Error = "error",
Expand All @@ -53,6 +56,9 @@ export enum GitHubActionsAnnotationType {
warning = "warning",
Warning = "warning"
}
/**
* GitHub Actions annotation properties.
*/
export interface GitHubActionsAnnotationProperties {
/**
* Path of the issue file of the annotation.
Expand Down
56 changes: 50 additions & 6 deletions utility.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";
import { isAbsolute as isPathAbsolute } from "node:path";
import { getEnv } from "https://raw.githubusercontent.com/hugoalh-studio/cross-env-ts/v1.0.1/mod.ts";
import { type JSONObject } from "https://raw.githubusercontent.com/hugoalh-studio/is-json-ts/v1.0.0/mod.ts";
import { type JSONValueExtend } from "https://raw.githubusercontent.com/hugoalh-studio/is-json-ts/v1.0.0/mod.ts";
/**
* Get the URL of the GitHub API.
*
Expand Down Expand Up @@ -77,7 +77,7 @@ export function getRunnerArchitecture(): GitHubActionsRunnerArchitecture {
}
export {
getRunnerArchitecture as getRunnerArch
}
};
/**
* Get the debug status of the GitHub Actions runner.
*
Expand Down Expand Up @@ -479,7 +479,51 @@ export function getWorkflowRunURL(): URL {
if (typeof repository === "undefined") {
throw new ReferenceError(`Unable to get the GitHub Actions workflow run URI, environment variable \`GITHUB_REPOSITORY\` is not defined!`);
}
return new URL(`${getGitHubServerURL().toString()}/${repository}/actions/runs/${getWorkflowRunID()}`);
const serverURLString: string = getGitHubServerURL().toString();
return new URL(`${serverURLString}${serverURLString.endsWith("/") ? "" : "/"}${repository}/actions/runs/${getWorkflowRunID()}`);
}
export interface GitHubWebhookPayloadRepository {
full_name?: string;
html_url?: string;
name: string;
owner: {
login: string;
name?: string;
[key: string]: JSONValueExtend | undefined;
};
[key: string]: JSONValueExtend | undefined;
}
/**
* GitHub Actions webhook event payload.
*/
export interface GitHubActionsWebhookEventPayload {
action?: string;
comment?: {
id: number;
[key: string]: JSONValueExtend | undefined;
};
installation?: {
id: number;
[key: string]: JSONValueExtend | undefined;
};
issue?: {
number: number;
html_url?: string;
body?: string;
[key: string]: JSONValueExtend | undefined;
};
pull_request?: {
number: number;
html_url?: string;
body?: string;
[key: string]: JSONValueExtend | undefined;
};
repository?: GitHubWebhookPayloadRepository;
sender?: {
type: string;
[key: string]: JSONValueExtend | undefined;
};
[key: string]: JSONValueExtend | undefined;
}
/**
* Get the webhook event payload of the workflow run.
Expand All @@ -488,17 +532,17 @@ export function getWorkflowRunURL(): URL {
* >
* > - Environment Variable (`allow-env`)
* > - File System - Read (`allow-read`)
* @returns {JSONObject} Webhook event payload of the workflow run.
* @returns {GitHubActionsWebhookEventPayload} Webhook event payload of the workflow run.
*/
export function getWorkflowRunWebhookEventPayload(): JSONObject {
export function getWorkflowRunWebhookEventPayload(): GitHubActionsWebhookEventPayload {
const path: string | undefined = getEnv("GITHUB_EVENT_PATH");
if (typeof path === "undefined") {
throw new ReferenceError(`Unable to get the GitHub Actions workflow run webhook event payload, environment variable \`GITHUB_EVENT_PATH\` is not defined!`);
}
if (!isPathAbsolute(path)) {
throw new ReferenceError(`Unable to get the GitHub Actions workflow run webhook event payload, \`${path}\` (environment variable \`GITHUB_EVENT_PATH\`) is not a valid absolute path!`);
}
return JSON.parse(readFileSync(path, { encoding: "utf-8" })) as JSONObject;
return JSON.parse(readFileSync(path, { encoding: "utf-8" })) as GitHubActionsWebhookEventPayload;
}
/**
* Get the SHA of the workflow.
Expand Down

0 comments on commit e1fb887

Please sign in to comment.