diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bbb98e4..e861ea7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: - fetch-depth: 2 + fetch-depth: 20 - name: Use Node.js uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: @@ -31,7 +31,7 @@ jobs: - run: pnpm build - run: pnpm lint - run: pnpm format:check - - run: pnpm test:integration + - run: pnpm test:integration ghbug env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} HEAD_OID: ${{ github.base_ref }} diff --git a/src/test/integration/ghbug.test.ts b/src/test/integration/ghbug.test.ts new file mode 100644 index 0000000..e7e5719 --- /dev/null +++ b/src/test/integration/ghbug.test.ts @@ -0,0 +1,77 @@ +import { getOctokit } from "@actions/github"; +import { promises as fs } from "fs"; + +import { ENV, REPO, ROOT_TEST_BRANCH_PREFIX } from "./env.js"; +import { deleteBranches } from "./util.js"; +import { + createRefMutation, + getRepositoryMetadata, +} from "../../github/graphql/queries.js"; +import git from "isomorphic-git"; + +const octokit = getOctokit(ENV.GITHUB_TOKEN); + +const TEST_BRANCH_PREFIX = `${ROOT_TEST_BRANCH_PREFIX}-ghbug`; + +describe("demonstrate bug with", () => { + const branches: string[] = []; + + // Set timeout to 1 minute + jest.setTimeout(60 * 1000); + + let repositoryId: string; + let shas: string[] = []; + + beforeAll(async () => { + const response = await getRepositoryMetadata(octokit, { + owner: REPO.owner, + name: REPO.repository, + baseRef: "HEAD", + targetRef: "HEAD", + }); + if (!response?.id) { + throw new Error("Repository not found"); + } + repositoryId = response.id; + // Get most recent 10 commits + const log = await git.log({ fs, dir: process.cwd(), depth: 10 }); + shas = log.map((commit) => commit.oid); + console.log("SHAS", shas); + }); + + for (let i = 0; i < 10; i++) { + describe(`Create branches from HEAD~${i}`, () => { + it(`GraphQL: createRef mutation`, async () => { + const branch = `${TEST_BRANCH_PREFIX}-graphql-${i}`; + branches.push(branch); + // Create test directory + + await createRefMutation(octokit, { + input: { + repositoryId, + name: `refs/heads/${branch}`, + oid: shas[i], + }, + }); + }); + + it(`REST: createRef mutation`, async () => { + const branch = `${TEST_BRANCH_PREFIX}-rest-${i}`; + branches.push(branch); + // Create test directory + await octokit.rest.git.createRef({ + owner: REPO.owner, + repo: REPO.repository, + ref: `refs/heads/${branch}`, + sha: shas[i] ?? "", + }); + }); + }); + } + + afterAll(async () => { + console.info("Cleaning up test branches"); + + await deleteBranches(octokit, branches); + }); +});