Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[.github] Move github-related consts and enums to shared
- Allows eng/tools to use them
  • Loading branch information
mikeharder committed Jul 30, 2025
commit abb9594ba4f40fb75a19f9a29dfbb53bd36af44a
102 changes: 102 additions & 0 deletions .github/shared/src/github.js
Original file line number Diff line number Diff line change
@@ -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",
});
102 changes: 1 addition & 101 deletions .github/workflows/src/github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import { PER_PAGE_MAX } from "../../shared/src/github.js";
import { byDate, invert } from "../../shared/src/sort.js";

/**
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/src/set-status.js
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/src/spec-gen-sdk-status.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test/set-status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down