diff --git a/lib/api/gh-got-retry.js b/lib/api/gh-got-retry.js index f2c8997fccd9c16328cfc1c8f506e9e2e0e02fd5..6534ba74d80c9f5df7b6e9b6130af3295a018dab 100644 --- a/lib/api/gh-got-retry.js +++ b/lib/api/gh-got-retry.js @@ -9,6 +9,18 @@ function sleep(ms) { async function ghGotRetry(path, opts, retries = 5) { try { + if (appMode) { + // eslint-disable-next-line no-param-reassign + opts = opts || {}; + // eslint-disable-next-line no-param-reassign + opts.headers = Object.assign( + { + accept: 'application/vnd.github.machine-man-preview+json', + 'user-agent': 'https://github.com/singapore/renovate', + }, + opts.headers + ); + } const res = await ghGot(path, opts); return res; } catch (err) { @@ -78,4 +90,9 @@ for (const x of helpers) { }; } +let appMode = false; +ghGotRetry.setAppMode = function setAppMode(val) { + appMode = val; +}; + module.exports = ghGotRetry; diff --git a/test/api/__snapshots__/github.spec.js.snap b/test/api/__snapshots__/github.spec.js.snap index d291793c825491dbad2a36c9bc56e22290e28a85..0cc62aac05d7ecceb4ec875a02262a1481bed5b2 100644 --- a/test/api/__snapshots__/github.spec.js.snap +++ b/test/api/__snapshots__/github.spec.js.snap @@ -1063,6 +1063,7 @@ Array [ "headers": Object { "accept": "application/vnd.github.machine-man-preview+json", "authorization": "Bearer sometoken", + "user-agent": "https://github.com/singapore/renovate", }, }, ], diff --git a/test/api/github.spec.js b/test/api/github.spec.js index 8bbd55995edbee8d578d201586efba54f6dcc90e..bc110a81a5036e05e95a6cc34f95b1dc5f3d163d 100644 --- a/test/api/github.spec.js +++ b/test/api/github.spec.js @@ -3,6 +3,7 @@ const logger = require('../_fixtures/logger'); describe('api/github', () => { let github; let ghGot; + let ghGotRetry; beforeEach(() => { // clean up env delete process.env.GITHUB_TOKEN; @@ -11,6 +12,7 @@ describe('api/github', () => { // reset module jest.resetModules(); jest.mock('gh-got'); + ghGotRetry = require('../../lib/api/gh-got-retry'); github = require('../../lib/api/github'); ghGot = require('gh-got'); }); @@ -20,6 +22,7 @@ describe('api/github', () => { ghGot.mockImplementationOnce(() => ({ body: ['a', 'b'], })); + ghGotRetry.setAppMode(true); const installations = await github.getInstallations('sometoken'); expect(ghGot.mock.calls).toMatchSnapshot(); expect(installations).toMatchSnapshot();