backend-manager 3.2.129 → 3.2.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.2.129",
3
+ "version": "3.2.130",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -282,15 +282,34 @@ Module.prototype.uploadPost = function (content) {
282
282
  return new Promise(async function(resolve, reject) {
283
283
  // Save variables
284
284
  const filename = `${payload.data.payload.path}/${payload.data.payload.date}-${payload.data.payload.url}.md`;
285
+ const owner = payload.data.payload.githubUser;
286
+ const repo = payload.data.payload.githubRepo;
285
287
 
286
288
  // Log
287
289
  assistant.log(`uploadPost(): filename`, filename);
288
290
 
291
+ // Get existing post
292
+ const existing = await self.octokit.rest.repos.getContent({
293
+ owner: owner,
294
+ repo: repo,
295
+ path: path,
296
+ })
297
+ .catch(e => e);
298
+
299
+ // Log
300
+ assistant.log(`uploadPost(): Existing`, existing);
301
+
302
+ // Error
303
+ if (existing instanceof Error) {
304
+ return reject(existing);
305
+ }
306
+
289
307
  // Upload post
290
308
  await self.octokit.rest.repos.createOrUpdateFileContents({
291
- owner: payload.data.payload.githubUser,
292
- repo: payload.data.payload.githubRepo,
309
+ owner: owner,
310
+ repo: repo,
293
311
  path: filename,
312
+ sha: existing?.data?.sha,
294
313
  message: `📦 admin:create-post:upload-post ${filename}`,
295
314
  content: Buffer.from(content).toString('base64'),
296
315
  })