From 71ceea0b47b9f75262d21364a18e1ee2457070b2 Mon Sep 17 00:00:00 2001
From: Pierrick V <pvgnd@users.noreply.github.com>
Date: Thu, 29 Oct 2020 12:31:14 +0100
Subject: [PATCH] feat: Trigger updateArtifacts for update-lockfile
 rangeStrategy with no packageFile content updated (#5859)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 .../__snapshots__/get-updated.spec.ts.snap    | 19 +++++++++++++++++++
 lib/workers/branch/get-updated.spec.ts        | 18 ++++++++++++++++++
 lib/workers/branch/get-updated.ts             |  8 +++++++-
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap
index e751ab26d1..1917689508 100644
--- a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap
+++ b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap
@@ -139,3 +139,22 @@ Object {
   "updatedPackageFiles": Array [],
 }
 `;
+
+exports[`workers/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = `
+Object {
+  "artifactErrors": Array [],
+  "reuseExistingBranch": undefined,
+  "updatedArtifacts": Array [
+    Object {
+      "contents": "some contents",
+      "name": "composer.lock",
+    },
+  ],
+  "updatedPackageFiles": Array [
+    Object {
+      "contents": "existing content",
+      "name": "undefined",
+    },
+  ],
+}
+`;
diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts
index 70e12e2a88..2fcf25c41a 100644
--- a/lib/workers/branch/get-updated.spec.ts
+++ b/lib/workers/branch/get-updated.spec.ts
@@ -151,5 +151,23 @@ describe('workers/branch/get-updated', () => {
       const res = await getUpdatedPackageFiles(config);
       expect(res).toMatchSnapshot();
     });
+    it('update artifacts on update-lockfile strategy', async () => {
+      config.upgrades.push({
+        manager: 'composer',
+        branchName: undefined,
+        rangeStrategy: 'update-lockfile',
+      });
+      autoReplace.doAutoReplace.mockResolvedValueOnce('existing content');
+      composer.updateArtifacts.mockResolvedValueOnce([
+        {
+          file: {
+            name: 'composer.lock',
+            contents: 'some contents',
+          },
+        },
+      ]);
+      const res = await getUpdatedPackageFiles(config);
+      expect(res).toMatchSnapshot();
+    });
   });
 });
diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts
index d922990984..233d3585b2 100644
--- a/lib/workers/branch/get-updated.ts
+++ b/lib/workers/branch/get-updated.ts
@@ -65,6 +65,10 @@ export async function getUpdatedPackageFiles(
         if (res) {
           if (res === existingContent) {
             logger.debug({ packageFile, depName }, 'No content changed');
+            if (upgrade.rangeStrategy === 'update-lockfile') {
+              logger.debug({ packageFile, depName }, 'update-lockfile add');
+              updatedFileContents[packageFile] = res;
+            }
           } else {
             logger.debug({ packageFile, depName }, 'Contents updated');
             updatedFileContents[packageFile] = res;
@@ -117,7 +121,9 @@ export async function getUpdatedPackageFiles(
       }
       if (
         newContent === existingContent &&
-        upgrade.datasource === datasourceGitSubmodules.id
+        (upgrade.datasource ===
+          datasourceGitSubmodules.id /* istanbul ignore next: no manager to test this exists */ ||
+          upgrade.rangeStrategy === 'update-lockfile')
       ) {
         updatedFileContents[packageFile] = newContent;
       }
-- 
GitLab