Skip to content

Commit 0e50762

Browse files
mheapLHumblot
andauthored
Add support for author and committer
Co-authored-by: Lionel Humblot <[email protected]>
1 parent 731ea64 commit 0e50762

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

Diff for: create-or-update-files.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module.exports = function(octokit, opts) {
1919
base,
2020
branch: branchName,
2121
createBranch,
22+
committer,
23+
author,
2224
changes
2325
} = opts;
2426

@@ -152,6 +154,8 @@ module.exports = function(octokit, opts) {
152154
octokit,
153155
owner,
154156
repo,
157+
committer,
158+
author,
155159
message,
156160
tree,
157161
baseTree
@@ -203,12 +207,23 @@ async function fileExistsInRepo(octokit, owner, repo, path, branch) {
203207
}
204208
}
205209

206-
async function createCommit(octokit, owner, repo, message, tree, baseTree) {
210+
async function createCommit(
211+
octokit,
212+
owner,
213+
repo,
214+
committer,
215+
author,
216+
message,
217+
tree,
218+
baseTree
219+
) {
207220
return (
208221
await octokit.git.createCommit({
209222
owner,
210223
repo,
211224
message,
225+
committer,
226+
author,
212227
tree: tree.sha,
213228
parents: [baseTree]
214229
})

Diff for: create-or-update-files.test.js

+47-2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,48 @@ test(`success (branch exists)`, async () => {
180180
await expect(run(body)).resolves.toEqual(branch);
181181
});
182182

183+
test(`success (committer details)`, async () => {
184+
const committer = {
185+
name: "Ashley Person",
186+
187+
};
188+
const body = {
189+
...validRequest,
190+
committer
191+
};
192+
mockGetRef(branch, `sha-${branch}`, true);
193+
mockCreateBlobFileOne();
194+
mockCreateBlobFileTwo();
195+
mockCreateTree(`sha-${branch}`);
196+
mockCommit(`sha-${branch}`, {
197+
committer
198+
});
199+
mockUpdateRef(branch);
200+
201+
await expect(run(body)).resolves.toEqual(branch);
202+
});
203+
204+
test(`success (author details)`, async () => {
205+
const author = {
206+
name: "Ashley Person",
207+
208+
};
209+
const body = {
210+
...validRequest,
211+
author
212+
};
213+
mockGetRef(branch, `sha-${branch}`, true);
214+
mockCreateBlobFileOne();
215+
mockCreateBlobFileTwo();
216+
mockCreateTree(`sha-${branch}`);
217+
mockCommit(`sha-${branch}`, {
218+
author
219+
});
220+
mockUpdateRef(branch);
221+
222+
await expect(run(body)).resolves.toEqual(branch);
223+
});
224+
183225
test(`success (createBranch, base provided)`, async () => {
184226
const body = {
185227
...validRequest,
@@ -561,11 +603,14 @@ function mockCommitSubmodule(baseTree) {
561603
m.reply(200, body);
562604
}
563605

564-
function mockCommit(baseTree) {
606+
function mockCommit(baseTree, additional) {
607+
additional = additional || {};
608+
565609
const expectedBody = {
566610
message: "Your commit message",
567611
tree: "4112258c05f8ce2b0570f1bbb1a330c0f9595ff9",
568-
parents: [baseTree]
612+
parents: [baseTree],
613+
...additional
569614
};
570615

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

0 commit comments

Comments
 (0)