diff --git a/.github/shared/package.json b/.github/shared/package.json index b82abb44c7aa..2dbaeadbbe76 100644 --- a/.github/shared/package.json +++ b/.github/shared/package.json @@ -9,6 +9,7 @@ "./equality": "./src/equality.js", "./error-reporting": "./src/error-reporting.js", "./exec": "./src/exec.js", + "./github": "./src/github.js", "./logger": "./src/logger.js", "./path": "./src/path.js", "./readme": "./src/readme.js", diff --git a/.github/shared/src/github.js b/.github/shared/src/github.js new file mode 100644 index 000000000000..b9e7a30ff9e6 --- /dev/null +++ b/.github/shared/src/github.js @@ -0,0 +1,102 @@ +// @ts-check + +export const PER_PAGE_MAX = 100; + +/** + * https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#check-statuses-and-conclusions + * + * @readonly + * @enum {"completed" | "expected" | "failure" | "in_progress" | "pending" | "queued" | "requested" | "startup_failure" | "waiting" } + */ +export const CheckStatus = Object.freeze({ + /** + * @description The check run completed and has a conclusion. + */ + COMPLETED: "completed", + /** + * @description The check run is waiting for a status to be reported. + */ + EXPECTED: "expected", + /** + * @description The check run failed. + */ + FAILURE: "failure", + /** + * @description The check run is in progress. + */ + IN_PROGRESS: "in_progress", + /** + * @description The check run is at the front of the queue but the group-based concurrency limit has been reached. + */ + PENDING: "pending", + /** + * @description The check run has been queued. + */ + QUEUED: "queued", + /** + * @description The check run has been created but has not been queued. + */ + REQUESTED: "requested", + /** + * @description The check suite failed during startup. This status is not applicable to check runs. + */ + STARTUP_FAILURE: "startup_failure", + /** + * @description The check run is waiting for a deployment protection rule to be satisfied. + */ + WAITING: "waiting", +}); + +/** + * https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#check-statuses-and-conclusions + * + * @readonly + * @enum {"action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" } + */ +export const CheckConclusion = Object.freeze({ + /** + * @description The check run provided required actions upon its completion. For more information, see Using the REST API to interact with checks. + */ + ACTION_REQUIRED: "action_required", + /** + * @description The check run was cancelled before it completed. + */ + CANCELLED: "cancelled", + /** + * @description The check run failed. + */ + FAILURE: "failure", + /** + * @description The check run completed with a neutral result. This is treated as a success for dependent checks in GitHub Actions. + */ + NEUTRAL: "neutral", + /** + * @description The check run was skipped. This is treated as a success for dependent checks in GitHub Actions. + */ + SKIPPED: "skipped", + /** + * @description The check run was marked stale by GitHub because it took too long. + */ + STALE: "stale", + /** + * @description The check run completed successfully. + */ + SUCCESS: "success", + /** + * @description The check run timed out. + */ + TIMED_OUT: "timed_out", +}); + +/** + * https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status--parameters + * + * @readonly + * @enum {"error" | "failure" | "pending" | "success"} + */ +export const CommitStatusState = Object.freeze({ + ERROR: "error", + FAILURE: "failure", + PENDING: "pending", + SUCCESS: "success", +}); diff --git a/.github/workflows/src/arm-auto-signoff.js b/.github/workflows/src/arm-auto-signoff.js index 05f825557223..2d20956f2557 100644 --- a/.github/workflows/src/arm-auto-signoff.js +++ b/.github/workflows/src/arm-auto-signoff.js @@ -1,8 +1,8 @@ // @ts-check import { setEquals } from "../../shared/src/equality.js"; +import { PER_PAGE_MAX } from "../../shared/src/github.js"; import { extractInputs } from "./context.js"; -import { PER_PAGE_MAX } from "./github.js"; import { LabelAction } from "./label.js"; // TODO: Add tests diff --git a/.github/workflows/src/comment.js b/.github/workflows/src/comment.js index e6f8ae63b73d..f872d56d2bf4 100644 --- a/.github/workflows/src/comment.js +++ b/.github/workflows/src/comment.js @@ -1,4 +1,4 @@ -import { PER_PAGE_MAX } from "./github.js"; +import { PER_PAGE_MAX } from "../../shared/src/github.js"; /** * @typedef {Object} IssueComment diff --git a/.github/workflows/src/context.js b/.github/workflows/src/context.js index 20ec868d9e09..530ec1113b8a 100644 --- a/.github/workflows/src/context.js +++ b/.github/workflows/src/context.js @@ -1,6 +1,6 @@ // @ts-check -import { PER_PAGE_MAX } from "./github.js"; +import { PER_PAGE_MAX } from "../../shared/src/github.js"; import { getIssueNumber } from "./issues.js"; /** diff --git a/.github/workflows/src/github.js b/.github/workflows/src/github.js index 2aa1192980db..00876082464b 100644 --- a/.github/workflows/src/github.js +++ b/.github/workflows/src/github.js @@ -1,5 +1,6 @@ // @ts-check +import { PER_PAGE_MAX } from "../../shared/src/github.js"; import { byDate, invert } from "../../shared/src/sort.js"; /** @@ -9,107 +10,6 @@ import { byDate, invert } from "../../shared/src/sort.js"; * @typedef {RestEndpointMethodTypes["repos"]["listCommitStatusesForRef"]["response"]["data"]} CommitStatuses */ -export const PER_PAGE_MAX = 100; - -/** - * https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#check-statuses-and-conclusions - * - * @readonly - * @enum {"completed" | "expected" | "failure" | "in_progress" | "pending" | "queued" | "requested" | "startup_failure" | "waiting" } - */ -export const CheckStatus = Object.freeze({ - /** - * @description The check run completed and has a conclusion. - */ - COMPLETED: "completed", - /** - * @description The check run is waiting for a status to be reported. - */ - EXPECTED: "expected", - /** - * @description The check run failed. - */ - FAILURE: "failure", - /** - * @description The check run is in progress. - */ - IN_PROGRESS: "in_progress", - /** - * @description The check run is at the front of the queue but the group-based concurrency limit has been reached. - */ - PENDING: "pending", - /** - * @description The check run has been queued. - */ - QUEUED: "queued", - /** - * @description The check run has been created but has not been queued. - */ - REQUESTED: "requested", - /** - * @description The check suite failed during startup. This status is not applicable to check runs. - */ - STARTUP_FAILURE: "startup_failure", - /** - * @description The check run is waiting for a deployment protection rule to be satisfied. - */ - WAITING: "waiting", -}); - -/** - * https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#check-statuses-and-conclusions - * - * @readonly - * @enum {"action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" } - */ -export const CheckConclusion = Object.freeze({ - /** - * @description The check run provided required actions upon its completion. For more information, see Using the REST API to interact with checks. - */ - ACTION_REQUIRED: "action_required", - /** - * @description The check run was cancelled before it completed. - */ - CANCELLED: "cancelled", - /** - * @description The check run failed. - */ - FAILURE: "failure", - /** - * @description The check run completed with a neutral result. This is treated as a success for dependent checks in GitHub Actions. - */ - NEUTRAL: "neutral", - /** - * @description The check run was skipped. This is treated as a success for dependent checks in GitHub Actions. - */ - SKIPPED: "skipped", - /** - * @description The check run was marked stale by GitHub because it took too long. - */ - STALE: "stale", - /** - * @description The check run completed successfully. - */ - SUCCESS: "success", - /** - * @description The check run timed out. - */ - TIMED_OUT: "timed_out", -}); - -/** - * https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status--parameters - * - * @readonly - * @enum {"error" | "failure" | "pending" | "success"} - */ -export const CommitStatusState = Object.freeze({ - ERROR: "error", - FAILURE: "failure", - PENDING: "pending", - SUCCESS: "success", -}); - /** * Writes content to the GitHub Actions summary * @param {string} content - Markdown content to add to the summary diff --git a/.github/workflows/src/set-status.js b/.github/workflows/src/set-status.js index 7fad49b6153f..79b565ab227c 100644 --- a/.github/workflows/src/set-status.js +++ b/.github/workflows/src/set-status.js @@ -1,7 +1,12 @@ // @ts-check +import { + CheckConclusion, + CheckStatus, + CommitStatusState, + PER_PAGE_MAX, +} from "../../shared/src/github.js"; import { extractInputs } from "./context.js"; -import { CheckConclusion, CheckStatus, CommitStatusState, PER_PAGE_MAX } from "./github.js"; // TODO: Add tests /* v8 ignore start */ diff --git a/.github/workflows/src/spec-gen-sdk-status.js b/.github/workflows/src/spec-gen-sdk-status.js index daa1f59189a7..a4c8770c3089 100644 --- a/.github/workflows/src/spec-gen-sdk-status.js +++ b/.github/workflows/src/spec-gen-sdk-status.js @@ -1,7 +1,8 @@ // @ts-check +import { CheckStatus, CommitStatusState, PER_PAGE_MAX } from "../../shared/src/github.js"; import { getAdoBuildInfoFromUrl, getAzurePipelineArtifact } from "./artifacts.js"; import { extractInputs } from "./context.js"; -import { CheckStatus, CommitStatusState, PER_PAGE_MAX, writeToActionsSummary } from "./github.js"; +import { writeToActionsSummary } from "./github.js"; /** * @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments @@ -123,10 +124,10 @@ export async function setSpecGenSdkStatusImpl({ * @param {Object} params * @param {Array} params.checkRuns * @param {typeof import("@actions/core")} params.core - * @returns {Promise<{state: import("./github.js").CommitStatusState, description: string}>} + * @returns {Promise<{state: CommitStatusState, description: string}>} */ async function processResult({ checkRuns, core }) { - /** @type {import("./github.js").CommitStatusState} */ + /** @type {CommitStatusState} */ let state = CommitStatusState.SUCCESS; let specGenSdkFailedRequiredLanguages = ""; let description = "SDK Validation CI checks succeeded"; diff --git a/.github/workflows/src/summarize-checks/summarize-checks.js b/.github/workflows/src/summarize-checks/summarize-checks.js index bda684f88c95..5fd4d0c04725 100644 --- a/.github/workflows/src/summarize-checks/summarize-checks.js +++ b/.github/workflows/src/summarize-checks/summarize-checks.js @@ -22,7 +22,7 @@ import { extractInputs } from "../context.js"; // import { commentOrUpdate } from "../comment.js"; import { execFile } from "../../../shared/src/exec.js"; -import { PER_PAGE_MAX } from "../github.js"; +import { PER_PAGE_MAX } from "../../../shared/src/github.js"; import { brChRevApproval, getViolatedRequiredLabelsRules, diff --git a/.github/workflows/src/update-labels.js b/.github/workflows/src/update-labels.js index a7664d21fb6f..087aec9f44d9 100644 --- a/.github/workflows/src/update-labels.js +++ b/.github/workflows/src/update-labels.js @@ -1,7 +1,7 @@ // @ts-check +import { PER_PAGE_MAX } from "../../shared/src/github.js"; import { extractInputs } from "../src/context.js"; -import { PER_PAGE_MAX } from "./github.js"; /** * @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments diff --git a/.github/workflows/test/context.test.js b/.github/workflows/test/context.test.js index b9f1fc36b0c9..f272b115b026 100644 --- a/.github/workflows/test/context.test.js +++ b/.github/workflows/test/context.test.js @@ -1,6 +1,6 @@ import { describe, expect, it } from "vitest"; +import { PER_PAGE_MAX } from "../../shared/src/github.js"; import { extractInputs } from "../src/context.js"; -import { PER_PAGE_MAX } from "../src/github.js"; import { createMockCore, createMockGithub } from "./mocks.js"; describe("extractInputs", () => { diff --git a/.github/workflows/test/set-status.test.js b/.github/workflows/test/set-status.test.js index b2d22575ae54..bea3648c40c4 100644 --- a/.github/workflows/test/set-status.test.js +++ b/.github/workflows/test/set-status.test.js @@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it } from "vitest"; import { setStatusImpl } from "../src/set-status.js"; -import { CheckConclusion, CheckStatus, CommitStatusState } from "../src/github.js"; +import { CheckConclusion, CheckStatus, CommitStatusState } from "../../shared/src/github.js"; import { createMockCore, createMockGithub } from "./mocks.js"; describe("setStatusImpl", () => { diff --git a/.github/workflows/test/update-labels.test.js b/.github/workflows/test/update-labels.test.js index 4c14438888ea..c1a1161ff810 100644 --- a/.github/workflows/test/update-labels.test.js +++ b/.github/workflows/test/update-labels.test.js @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { PER_PAGE_MAX } from "../src/github.js"; +import { PER_PAGE_MAX } from "../../shared/src/github.js"; import updateLabels, { updateLabelsImpl } from "../src/update-labels.js"; import { createMockCore, createMockGithub, createMockRequestError } from "./mocks.js";