From 14947cd78b0bf2df5d6f081bff7d820119a53149 Mon Sep 17 00:00:00 2001
From: Oleg Krivtsov <olegkrivtsov@gmail.com>
Date: Wed, 24 Nov 2021 16:46:05 +0700
Subject: [PATCH] feat(platform/github): modify getJsonFile to use branchOrTag
 on GitHub (#12819)

---
 lib/platform/github/__snapshots__/index.spec.ts.snap | 6 +++---
 lib/platform/github/index.spec.ts                    | 4 ++--
 lib/platform/github/index.ts                         | 5 ++++-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/platform/github/__snapshots__/index.spec.ts.snap b/lib/platform/github/__snapshots__/index.spec.ts.snap
index e95821a17a..339ec34173 100644
--- a/lib/platform/github/__snapshots__/index.spec.ts.snap
+++ b/lib/platform/github/__snapshots__/index.spec.ts.snap
@@ -4945,7 +4945,7 @@ Array [
 ]
 `;
 
-exports[`platform/github/index getJsonFile() ignores branchOrTag 1`] = `
+exports[`platform/github/index getJsonFile() returns file content 1`] = `
 Array [
   Object {
     "graphql": Object {
@@ -5006,7 +5006,7 @@ Array [
 ]
 `;
 
-exports[`platform/github/index getJsonFile() returns file content 1`] = `
+exports[`platform/github/index getJsonFile() returns file content from branch or tag 1`] = `
 Array [
   Object {
     "graphql": Object {
@@ -5062,7 +5062,7 @@ Array [
       "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
     },
     "method": "GET",
-    "url": "https://api.github.com/repos/some/repo/contents/file.json",
+    "url": "https://api.github.com/repos/some/repo/contents/file.json?ref=dev",
   },
 ]
 `;
diff --git a/lib/platform/github/index.spec.ts b/lib/platform/github/index.spec.ts
index a16ab9c08e..97fd3541e2 100644
--- a/lib/platform/github/index.spec.ts
+++ b/lib/platform/github/index.spec.ts
@@ -2445,12 +2445,12 @@ describe('platform/github/index', () => {
       expect(httpMock.getTrace()).toMatchSnapshot();
     });
 
-    it('ignores branchOrTag', async () => {
+    it('returns file content from branch or tag', async () => {
       const data = { foo: 'bar' };
       const scope = httpMock.scope(githubApiHost);
       initRepoMock(scope, 'some/repo');
       await github.initRepo({ repository: 'some/repo', token: 'token' } as any);
-      scope.get('/repos/some/repo/contents/file.json').reply(200, {
+      scope.get('/repos/some/repo/contents/file.json?ref=dev').reply(200, {
         content: Buffer.from(JSON.stringify(data)).toString('base64'),
       });
       const res = await github.getJsonFile('file.json', 'some/repo', 'dev');
diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts
index 4ead5ef8fa..ecc2895006 100644
--- a/lib/platform/github/index.ts
+++ b/lib/platform/github/index.ts
@@ -177,7 +177,10 @@ export async function getRawFile(
   branchOrTag?: string
 ): Promise<string | null> {
   const repo = repoName ?? config.repository;
-  const url = `repos/${repo}/contents/${fileName}`;
+  let url = `repos/${repo}/contents/${fileName}`;
+  if (branchOrTag) {
+    url += `?ref=` + branchOrTag;
+  }
   const res = await githubApi.getJson<{ content: string }>(url);
   const buf = res.body.content;
   const str = Buffer.from(buf, 'base64').toString();
-- 
GitLab