Skip to content

Commit c5fd254

Browse files
committed
Return commits rather than the branch name
1 parent 979d5f1 commit c5fd254

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

create-or-update-files.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = function(octokit, opts) {
5858
}
5959

6060
// Create blobs
61+
const commits = [];
6162
for (const change of changes) {
6263
const message = change.message;
6364
if (!message) {
@@ -163,6 +164,7 @@ module.exports = function(octokit, opts) {
163164

164165
// Update the base tree if we have another commit to make
165166
baseTree = commit.sha;
167+
commits.push(commit);
166168
}
167169

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

186188
// Return the new branch name so that we can use it later
187189
// e.g. to create a pull request
188-
return resolve(branchName);
190+
return resolve({ commits });
189191
} catch (e) {
190192
return reject(e);
191193
}

create-or-update-files.test.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ I hope it works`,
3232

3333
// Destructuring for easier access later
3434
let { owner, repo, base, branch } = validRequest;
35+
const mockCommitList = {
36+
commits: [{ sha: "ef105a72c03ce2743d90944c2977b1b5563b43c0" }]
37+
};
38+
const mockSecondCommitList = {
39+
commits: [{ sha: "45d77edc93556e3a997bf73d5ed4d9fb57068928" }]
40+
};
41+
const mockSubmoduleCommitList = {
42+
commits: [{ sha: "ef105a72c03ce2743d90944c2977b1b5563b43c0" }]
43+
};
3544

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

166-
await expect(run(body)).resolves.toEqual(branch);
175+
await expect(run(body)).resolves.toEqual(mockSubmoduleCommitList);
167176
});
168177

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

180-
await expect(run(body)).resolves.toEqual(branch);
189+
await expect(run(body)).resolves.toEqual(mockCommitList);
181190
});
182191

183192
test(`success (committer details)`, async () => {
@@ -198,7 +207,7 @@ test(`success (committer details)`, async () => {
198207
});
199208
mockUpdateRef(branch);
200209

201-
await expect(run(body)).resolves.toEqual(branch);
210+
await expect(run(body)).resolves.toEqual(mockCommitList);
202211
});
203212

204213
test(`success (author details)`, async () => {
@@ -219,7 +228,7 @@ test(`success (author details)`, async () => {
219228
});
220229
mockUpdateRef(branch);
221230

222-
await expect(run(body)).resolves.toEqual(branch);
231+
await expect(run(body)).resolves.toEqual(mockCommitList);
223232
});
224233

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

238-
await expect(run(body)).resolves.toEqual(branch);
247+
await expect(run(body)).resolves.toEqual(mockCommitList);
239248
});
240249

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

259-
await expect(run(body)).resolves.toEqual(branch);
268+
await expect(run(body)).resolves.toEqual(mockCommitList);
260269
});
261270

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

291-
await expect(run(body)).resolves.toEqual(branch);
300+
await expect(run(body)).resolves.toEqual({
301+
commits: [...mockCommitList.commits, ...mockSecondCommitList.commits]
302+
});
292303
});
293304

294305
test("success (ignore missing deleted files)", async () => {
@@ -321,7 +332,7 @@ test("success (ignore missing deleted files)", async () => {
321332
changes
322333
};
323334

324-
await expect(run(body)).resolves.toEqual(branch);
335+
await expect(run(body)).resolves.toEqual(mockSecondCommitList);
325336
});
326337

327338
test("success (fileToDelete exists)", async () => {
@@ -352,7 +363,7 @@ test("success (fileToDelete exists)", async () => {
352363
changes
353364
};
354365

355-
await expect(run(body)).resolves.toEqual(branch);
366+
await expect(run(body)).resolves.toEqual(mockSecondCommitList);
356367
});
357368

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

0 commit comments

Comments
 (0)