Skip to content

Commit 24be49e

Browse files
committed
Fix commits with only filesToDelete
1 parent da63aea commit 24be49e

File tree

2 files changed

+114
-63
lines changed

2 files changed

+114
-63
lines changed

create-or-update-files.js

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = function (octokit, opts) {
8282
if (!baseTree || forkFromBaseBranch) {
8383
if (!createBranch && !baseTree) {
8484
return reject(
85-
`The branch '${branchName}' doesn't exist and createBranch is 'false'`,
85+
`The branch '${branchName}' doesn't exist and createBranch is 'false'`
8686
);
8787
}
8888

@@ -125,7 +125,7 @@ module.exports = function (octokit, opts) {
125125

126126
if (!hasFiles && !hasFilesToDelete) {
127127
return reject(
128-
`either changes[].files or changes[].filesToDelete are required`,
128+
`either changes[].files or changes[].filesToDelete are required`
129129
);
130130
}
131131

@@ -140,14 +140,14 @@ module.exports = function (octokit, opts) {
140140
owner,
141141
repo,
142142
fileName,
143-
baseTree,
143+
baseTree
144144
);
145145

146146
// If it doesn't exist, and we're not ignoring missing files
147147
// reject the promise
148148
if (!exists && !change.ignoreDeletionFailures) {
149149
return reject(
150-
`The file ${fileName} could not be found in the repo`,
150+
`The file ${fileName} could not be found in the repo`
151151
);
152152
}
153153

@@ -160,40 +160,42 @@ module.exports = function (octokit, opts) {
160160
type: "commit",
161161
});
162162
}
163-
}),
163+
})
164164
);
165165
}
166166
}
167167

168-
for (const batch of chunk(Object.keys(change.files), batchSize)) {
169-
await Promise.all(
170-
batch.map(async (fileName) => {
171-
const properties = change.files[fileName] || "";
172-
173-
const contents = properties.contents || properties;
174-
const mode = properties.mode || "100644";
175-
const type = properties.type || "blob";
176-
177-
if (!contents) {
178-
return reject(`No file contents provided for ${fileName}`);
179-
}
180-
181-
const fileSha = await createBlob(
182-
octokit,
183-
owner,
184-
repo,
185-
contents,
186-
type,
187-
);
188-
189-
treeItems.push({
190-
path: fileName,
191-
sha: fileSha,
192-
mode: mode,
193-
type: type,
194-
});
195-
}),
196-
);
168+
if (hasFiles) {
169+
for (const batch of chunk(Object.keys(change.files), batchSize)) {
170+
await Promise.all(
171+
batch.map(async (fileName) => {
172+
const properties = change.files[fileName] || "";
173+
174+
const contents = properties.contents || properties;
175+
const mode = properties.mode || "100644";
176+
const type = properties.type || "blob";
177+
178+
if (!contents) {
179+
return reject(`No file contents provided for ${fileName}`);
180+
}
181+
182+
const fileSha = await createBlob(
183+
octokit,
184+
owner,
185+
repo,
186+
contents,
187+
type
188+
);
189+
190+
treeItems.push({
191+
path: fileName,
192+
sha: fileSha,
193+
mode: mode,
194+
type: type,
195+
});
196+
})
197+
);
198+
}
197199
}
198200

199201
// no need to issue further requests if there are no updates, creations and deletions
@@ -207,7 +209,7 @@ module.exports = function (octokit, opts) {
207209
owner,
208210
repo,
209211
treeItems,
210-
baseTree,
212+
baseTree
211213
);
212214

213215
// Create a commit that points to that tree
@@ -219,7 +221,7 @@ module.exports = function (octokit, opts) {
219221
author,
220222
message,
221223
tree,
222-
baseTree,
224+
baseTree
223225
);
224226

225227
// Update the base tree if we have another commit to make
@@ -277,7 +279,7 @@ async function createCommit(
277279
author,
278280
message,
279281
tree,
280-
baseTree,
282+
baseTree
281283
) {
282284
return (
283285
await octokit.rest.git.createCommit({

0 commit comments

Comments
 (0)