|
| 1 | +import { getOctokit } from "@actions/github"; |
| 2 | +import { promises as fs } from "fs"; |
| 3 | + |
| 4 | +import { ENV, REPO, ROOT_TEST_BRANCH_PREFIX } from "./env.js"; |
| 5 | +import { deleteBranches } from "./util.js"; |
| 6 | +import { |
| 7 | + createRefMutation, |
| 8 | + getRepositoryMetadata, |
| 9 | +} from "../../github/graphql/queries.js"; |
| 10 | +import git from "isomorphic-git"; |
| 11 | + |
| 12 | +const octokit = getOctokit(ENV.GITHUB_TOKEN); |
| 13 | + |
| 14 | +const TEST_BRANCH_PREFIX = `${ROOT_TEST_BRANCH_PREFIX}-ghbug`; |
| 15 | + |
| 16 | +describe("demonstrate bug with", () => { |
| 17 | + const branches: string[] = []; |
| 18 | + |
| 19 | + // Set timeout to 1 minute |
| 20 | + jest.setTimeout(60 * 1000); |
| 21 | + |
| 22 | + let repositoryId: string; |
| 23 | + let shas: string[] = []; |
| 24 | + |
| 25 | + beforeAll(async () => { |
| 26 | + const response = await getRepositoryMetadata(octokit, { |
| 27 | + owner: REPO.owner, |
| 28 | + name: REPO.repository, |
| 29 | + baseRef: "HEAD", |
| 30 | + targetRef: "HEAD", |
| 31 | + }); |
| 32 | + if (!response?.id) { |
| 33 | + throw new Error("Repository not found"); |
| 34 | + } |
| 35 | + repositoryId = response.id; |
| 36 | + // Get most recent 10 commits |
| 37 | + const log = await git.log({ fs, dir: process.cwd(), depth: 10 }); |
| 38 | + shas = log.map((commit) => commit.oid); |
| 39 | + }); |
| 40 | + |
| 41 | + for (let i = 0; i < 10; i++) { |
| 42 | + const oid = shas[i] ?? ""; |
| 43 | + describe(`Create branches from HEAD~${i} (${oid})`, () => { |
| 44 | + it(`GraphQL: createRef mutation`, async () => { |
| 45 | + const branch = `${TEST_BRANCH_PREFIX}-graphql-${i}`; |
| 46 | + branches.push(branch); |
| 47 | + // Create test directory |
| 48 | + |
| 49 | + await createRefMutation(octokit, { |
| 50 | + input: { |
| 51 | + repositoryId, |
| 52 | + name: `refs/heads/${branch}`, |
| 53 | + oid, |
| 54 | + }, |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it(`REST: createRef mutation`, async () => { |
| 59 | + const branch = `${TEST_BRANCH_PREFIX}-rest-${i}`; |
| 60 | + branches.push(branch); |
| 61 | + // Create test directory |
| 62 | + await octokit.rest.git.createRef({ |
| 63 | + owner: REPO.owner, |
| 64 | + repo: REPO.repository, |
| 65 | + ref: `refs/heads/${branch}`, |
| 66 | + sha: oid, |
| 67 | + }); |
| 68 | + }); |
| 69 | + }); |
| 70 | + } |
| 71 | + |
| 72 | + afterAll(async () => { |
| 73 | + console.info("Cleaning up test branches"); |
| 74 | + |
| 75 | + await deleteBranches(octokit, branches); |
| 76 | + }); |
| 77 | +}); |
0 commit comments