Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

permissions:
contents: write
pull-requests: write

jobs:
ci-checks:
Expand Down
116 changes: 116 additions & 0 deletions src/test/integration/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ describe("node", () => {
}
};

const createPullRequestForBranch = async (branch: string, title: string) => {
const pullRequest = await octokit.rest.pulls.create({
...REPO,
title,
head: branch,
base: "main",
body: `CI-created integration test PR for \`${branch}\`.`,
});

expect(pullRequest.data.state).toEqual("open");
expect(pullRequest.data.head.ref).toEqual(branch);

return pullRequest.data.html_url;
};

let testTargetCommit: string;
/**
* For tests, important that this commit is not an ancestor of TEST_TARGET_COMMIT,
Expand Down Expand Up @@ -263,6 +278,107 @@ describe("node", () => {
});
});

it("can create a commit using the REST git API", async () => {
const branch = `${TEST_BRANCH_PREFIX}-rest-git-${Date.now()}`;
const filePath = "rest-git-api-test.txt";

const baseRef = await octokit.rest.git.getRef({
...REPO,
ref: "heads/main",
});
const baseOid = baseRef.data.object.sha;

const baseCommit = await octokit.rest.git.getCommit({
...REPO,
commit_sha: baseOid,
});

const tree = await octokit.rest.git.createTree({
...REPO,
base_tree: baseCommit.data.tree.sha,
tree: [
{
path: filePath,
mode: "100644",
type: "blob",
content: "Hello from the REST git API!\n",
},
],
});

const commit = await octokit.rest.git.createCommit({
...REPO,
message: "Test REST git commit",
tree: tree.data.sha,
parents: [baseOid],
});

await octokit.rest.git.createRef({
...REPO,
ref: `refs/heads/${branch}`,
sha: commit.data.sha,
});

await waitForGitHubToBeReady();

const branchRef = await octokit.rest.git.getRef({
...REPO,
ref: `heads/${branch}`,
});

expect(branchRef.data.object.sha).toEqual(commit.data.sha);

const pullRequestUrl = await createPullRequestForBranch(
branch,
`test: REST git API branch ${branch}`,
);

expect(pullRequestUrl).toContain(`/pull/`);
});

it("can create a commit using the GraphQL commit path", async () => {
const branch = `${TEST_BRANCH_PREFIX}-graphql-git-${Date.now()}`;
const filePath = "graphql-git-api-test.txt";

await commitFilesFromBuffers({
octokit,
...REPO,
branch,
base: {
branch: "main",
},
message: {
headline: "Test GraphQL git commit",
body: "Created through commitFilesFromBuffers",
},
fileChanges: {
additions: [
{
path: filePath,
contents: Buffer.from("Hello from the GraphQL commit path!\n"),
},
],
},
log,
});

await waitForGitHubToBeReady();

const branchRef = await octokit.rest.git.getRef({
...REPO,
ref: `heads/${branch}`,
});

expect(branchRef.data.object.sha).toBeTruthy();

const pullRequestUrl = await createPullRequestForBranch(
branch,
`test: GraphQL commit path branch ${branch}`,
);

expect(pullRequestUrl).toContain(`/pull/`);
});

describe("existing branches", () => {
it("can commit to existing branch when force is true", async () => {
const branch = `${TEST_BRANCH_PREFIX}-existing-branch-force`;
Expand Down
Loading