Skip to content

Return commits rather than the branch name #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2022
Merged
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
4 changes: 3 additions & 1 deletion create-or-update-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = function(octokit, opts) {
}

// Create blobs
const commits = [];
for (const change of changes) {
const message = change.message;
if (!message) {
Expand Down Expand Up @@ -163,6 +164,7 @@ module.exports = function(octokit, opts) {

// Update the base tree if we have another commit to make
baseTree = commit.sha;
commits.push(commit);
}

// Create a ref that points to that tree
Expand All @@ -185,7 +187,7 @@ module.exports = function(octokit, opts) {

// Return the new branch name so that we can use it later
// e.g. to create a pull request
return resolve(branchName);
return resolve({ commits });
} catch (e) {
return reject(e);
}
Expand Down
29 changes: 20 additions & 9 deletions create-or-update-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ I hope it works`,

// Destructuring for easier access later
let { owner, repo, base, branch } = validRequest;
const mockCommitList = {
commits: [{ sha: "ef105a72c03ce2743d90944c2977b1b5563b43c0" }]
};
const mockSecondCommitList = {
commits: [{ sha: "45d77edc93556e3a997bf73d5ed4d9fb57068928" }]
};
const mockSubmoduleCommitList = {
commits: [{ sha: "ef105a72c03ce2743d90944c2977b1b5563b43c0" }]
};

for (let req of ["owner", "repo", "branch"]) {
const body = { ...validRequest };
Expand Down Expand Up @@ -163,7 +172,7 @@ test(`success (submodule, branch exists)`, async () => {
mockCommitSubmodule(`sha-${branch}`);
mockUpdateRef(branch);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockSubmoduleCommitList);
});

test(`success (branch exists)`, async () => {
Expand All @@ -177,7 +186,7 @@ test(`success (branch exists)`, async () => {
mockCommit(`sha-${branch}`);
mockUpdateRef(branch);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockCommitList);
});

test(`success (committer details)`, async () => {
Expand All @@ -198,7 +207,7 @@ test(`success (committer details)`, async () => {
});
mockUpdateRef(branch);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockCommitList);
});

test(`success (author details)`, async () => {
Expand All @@ -219,7 +228,7 @@ test(`success (author details)`, async () => {
});
mockUpdateRef(branch);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockCommitList);
});

test(`success (createBranch, base provided)`, async () => {
Expand All @@ -235,7 +244,7 @@ test(`success (createBranch, base provided)`, async () => {
mockCommit(`sha-${base}`);
mockCreateRef(branch);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockCommitList);
});

test(`success (createBranch, use default base branch)`, async () => {
Expand All @@ -256,7 +265,7 @@ test(`success (createBranch, use default base branch)`, async () => {
mockCommit(`sha-${repoDefaultBranch}`);
mockCreateRef(branch);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockCommitList);
});

test(`success (createBranch, use default base branch, multiple commits)`, async () => {
Expand Down Expand Up @@ -288,7 +297,9 @@ test(`success (createBranch, use default base branch, multiple commits)`, async
mockCommitSecond(`ef105a72c03ce2743d90944c2977b1b5563b43c0`);
mockCreateRef(branch, `45d77edc93556e3a997bf73d5ed4d9fb57068928`);

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual({
commits: [...mockCommitList.commits, ...mockSecondCommitList.commits]
});
});

test("success (ignore missing deleted files)", async () => {
Expand Down Expand Up @@ -321,7 +332,7 @@ test("success (ignore missing deleted files)", async () => {
changes
};

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockSecondCommitList);
});

test("success (fileToDelete exists)", async () => {
Expand Down Expand Up @@ -352,7 +363,7 @@ test("success (fileToDelete exists)", async () => {
changes
};

await expect(run(body)).resolves.toEqual(branch);
await expect(run(body)).resolves.toEqual(mockSecondCommitList);
});

test("failure (fileToDelete is missing)", async () => {
Expand Down