Skip to content

Add support for author and committer #13

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 2 commits into from
Nov 18, 2020
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
17 changes: 16 additions & 1 deletion create-or-update-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = function(octokit, opts) {
base,
branch: branchName,
createBranch,
committer,
author,
changes
} = opts;

Expand Down Expand Up @@ -152,6 +154,8 @@ module.exports = function(octokit, opts) {
octokit,
owner,
repo,
committer,
author,
message,
tree,
baseTree
Expand Down Expand Up @@ -203,12 +207,23 @@ async function fileExistsInRepo(octokit, owner, repo, path, branch) {
}
}

async function createCommit(octokit, owner, repo, message, tree, baseTree) {
async function createCommit(
octokit,
owner,
repo,
committer,
author,
message,
tree,
baseTree
) {
return (
await octokit.git.createCommit({
owner,
repo,
message,
committer,
author,
tree: tree.sha,
parents: [baseTree]
})
Expand Down
49 changes: 47 additions & 2 deletions create-or-update-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,48 @@ test(`success (branch exists)`, async () => {
await expect(run(body)).resolves.toEqual(branch);
});

test(`success (committer details)`, async () => {
const committer = {
name: "Ashley Person",
email: "[email protected]"
};
const body = {
...validRequest,
committer
};
mockGetRef(branch, `sha-${branch}`, true);
mockCreateBlobFileOne();
mockCreateBlobFileTwo();
mockCreateTree(`sha-${branch}`);
mockCommit(`sha-${branch}`, {
committer
});
mockUpdateRef(branch);

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

test(`success (author details)`, async () => {
const author = {
name: "Ashley Person",
email: "[email protected]"
};
const body = {
...validRequest,
author
};
mockGetRef(branch, `sha-${branch}`, true);
mockCreateBlobFileOne();
mockCreateBlobFileTwo();
mockCreateTree(`sha-${branch}`);
mockCommit(`sha-${branch}`, {
author
});
mockUpdateRef(branch);

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

test(`success (createBranch, base provided)`, async () => {
const body = {
...validRequest,
Expand Down Expand Up @@ -561,11 +603,14 @@ function mockCommitSubmodule(baseTree) {
m.reply(200, body);
}

function mockCommit(baseTree) {
function mockCommit(baseTree, additional) {
additional = additional || {};

const expectedBody = {
message: "Your commit message",
tree: "4112258c05f8ce2b0570f1bbb1a330c0f9595ff9",
parents: [baseTree]
parents: [baseTree],
...additional
};

const m = nock("https://api.github.com").post(
Expand Down