From d1229b228c403d68bebab5f56bba84a0e427c635 Mon Sep 17 00:00:00 2001
From: Oleg Krivtsov <olegkrivtsov@gmail.com>
Date: Sat, 27 Nov 2021 12:42:10 +0700
Subject: [PATCH] feat(platform/azure): modify getJsonFile to use branchOrTag 
 (#12826)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 .../azure/__snapshots__/index.spec.ts.snap     |  7 +++++++
 .../azure/__snapshots__/index.spec.ts.snap     |  7 +++++++
 lib/platform/azure/index.spec.ts               |  2 +-
 lib/platform/azure/index.ts                    | 18 +++++++++++++++++-
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/lib/config/presets/azure/__snapshots__/index.spec.ts.snap b/lib/config/presets/azure/__snapshots__/index.spec.ts.snap
index c9758c77a5..862395350f 100644
--- a/lib/config/presets/azure/__snapshots__/index.spec.ts.snap
+++ b/lib/config/presets/azure/__snapshots__/index.spec.ts.snap
@@ -5,6 +5,13 @@ Array [
   Array [
     "123456",
     "some-filename.json",
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
   ],
 ]
 `;
diff --git a/lib/platform/azure/__snapshots__/index.spec.ts.snap b/lib/platform/azure/__snapshots__/index.spec.ts.snap
index 1a4ccf8fe1..e40a8dc126 100644
--- a/lib/platform/azure/__snapshots__/index.spec.ts.snap
+++ b/lib/platform/azure/__snapshots__/index.spec.ts.snap
@@ -206,6 +206,13 @@ Array [
   Array [
     "123456",
     "file.json",
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
   ],
 ]
 `;
diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts
index f9946440b6..29b8a88a8a 100644
--- a/lib/platform/azure/index.spec.ts
+++ b/lib/platform/azure/index.spec.ts
@@ -1265,7 +1265,7 @@ describe('platform/azure/index', () => {
       expect(res).toEqual({ foo: 'bar' });
     });
 
-    it('ignores branchOrTag', async () => {
+    it('returns file content from branch or tag', async () => {
       const data = { foo: 'bar' };
       azureApi.gitApi.mockImplementationOnce(
         () =>
diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts
index 1b340395f2..231cc0558d 100644
--- a/lib/platform/azure/index.ts
+++ b/lib/platform/azure/index.ts
@@ -5,6 +5,7 @@ import {
   GitPullRequestMergeStrategy,
   GitStatus,
   GitStatusState,
+  GitVersionDescriptor,
   PullRequestStatus,
 } from 'azure-devops-node-api/interfaces/GitInterfaces';
 import delay from 'delay';
@@ -127,7 +128,22 @@ export async function getRawFile(
     repoId = config.repoId;
   }
 
-  const buf = await azureApiGit.getItemContent(repoId, fileName);
+  const versionDescriptor: GitVersionDescriptor = {
+    version: branchOrTag,
+  } as GitVersionDescriptor;
+
+  const buf = await azureApiGit.getItemContent(
+    repoId,
+    fileName,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    undefined,
+    branchOrTag ? versionDescriptor : undefined
+  );
+
   const str = await streamToString(buf);
   return str;
 }
-- 
GitLab