Skip to content
Snippets Groups Projects
Commit 3bf4c6d7 authored by Gord Lea's avatar Gord Lea Committed by Rhys Arkins
Browse files

fix(ghe): update github release notes to use api endpoint instead of sourceUrl (#3111)

The code to get a list of releases was not using the RENOVATE_ENDPOINT when the npm modules it was fetching releases for had it's git repository on github enterprise.

Closes #3079 
parent 201d6e02
Branches
No related tags found
No related merge requests found
......@@ -14,12 +14,10 @@ module.exports = {
addReleaseNotes,
};
async function getReleaseList(githubBaseURL, repository) {
async function getReleaseList(githubApiBaseURL, repository) {
logger.trace('getReleaseList()');
try {
let url = githubBaseURL
.replace(/\/?$/, '/')
.replace('https://github.com', 'https://api.github.com');
let url = githubApiBaseURL.replace(/\/?$/, '/');
url += `repos/${repository}/releases?per_page=100`;
const res = await ghGot(url);
return res.body.map(release => ({
......@@ -61,9 +59,14 @@ function massageBody(input, githubBaseURL) {
return body.trim();
}
async function getReleaseNotes(repository, version, githubBaseURL) {
async function getReleaseNotes(
repository,
version,
githubBaseURL,
githubApiBaseURL
) {
logger.trace(`getReleaseNotes(${repository}, ${version})`);
const releaseList = await getReleaseList(githubBaseURL, repository);
const releaseList = await getReleaseList(githubApiBaseURL, repository);
let releaseNotes;
releaseList.forEach(release => {
if (release.tag === version || release.tag === `v${version}`) {
......@@ -109,7 +112,12 @@ function sectionize(text, level) {
return result;
}
async function getReleaseNotesMd(repository, version, githubBaseURL) {
async function getReleaseNotesMd(
repository,
version,
githubBaseURL,
githubApiBaseUrl
) {
logger.trace(`getReleaseNotes(${repository}, ${version})`);
const skippedRepos = ['facebook/react-native'];
// istanbul ignore if
......@@ -119,9 +127,8 @@ async function getReleaseNotesMd(repository, version, githubBaseURL) {
let changelogFile;
let changelogMd = '';
try {
let apiPrefix = githubBaseURL
.replace(/\/?$/, '/')
.replace('https://github.com', 'https://api.github.com');
let apiPrefix = githubApiBaseUrl.replace(/\/?$/, '/');
apiPrefix += `repos/${repository}/contents/`;
const filesRes = await ghGot(apiPrefix);
const files = filesRes.body
......@@ -209,14 +216,16 @@ async function addReleaseNotes(input) {
releaseNotes = await getReleaseNotesMd(
repository,
v.version,
input.project.githubBaseURL
input.project.githubBaseURL,
input.project.githubApiBaseURL
);
if (!releaseNotes) {
logger.trace('No markdown release notes found for v' + v.version);
releaseNotes = await getReleaseNotes(
repository,
v.version,
input.project.githubBaseURL
input.project.githubBaseURL,
input.project.githubApiBaseURL
);
}
// Small hack to force display of release notes when there is a compare url
......
......@@ -60,9 +60,10 @@ async function getChangeLogJSON({
host: host === 'github.com' ? 'api.github.com' : host,
});
if (!config) {
logger.debug('Repository URL does not match any hnown hosts');
logger.debug('Repository URL does not match any known hosts');
return null;
}
const githubApiBaseURL = config.endpoint;
const repository = pathname.slice(1).replace(/\/$/, '');
if (repository.split('/').length !== 2) {
logger.info({ sourceUrl }, 'Invalid github URL found');
......@@ -144,6 +145,7 @@ async function getChangeLogJSON({
let res = {
project: {
githubApiBaseURL,
githubBaseURL,
github: repository,
repository: sourceUrl,
......
......@@ -5,6 +5,7 @@ Object {
"hasReleaseNotes": true,
"project": Object {
"github": "chalk/chalk",
"githubApiBaseURL": "https://api.github.com/",
"githubBaseURL": "https://github.com/",
"repository": "https://github.com/chalk/chalk",
},
......@@ -54,6 +55,7 @@ Object {
"hasReleaseNotes": true,
"project": Object {
"github": "chalk/chalk",
"githubApiBaseURL": "https://github-enterprise.example.com/",
"githubBaseURL": "https://github-enterprise.example.com/",
"repository": "https://github-enterprise.example.com/chalk/chalk",
},
......@@ -103,6 +105,7 @@ Object {
"hasReleaseNotes": true,
"project": Object {
"github": "chalk/chalk",
"githubApiBaseURL": "https://api.github.com/",
"githubBaseURL": "https://github.com/",
"repository": "https://github.com/chalk/chalk",
},
......@@ -152,6 +155,7 @@ Object {
"hasReleaseNotes": true,
"project": Object {
"github": "chalk/chalk",
"githubApiBaseURL": "https://api.github.com/",
"githubBaseURL": "https://github.com/",
"repository": "https://github.com/chalk/chalk",
},
......@@ -201,6 +205,7 @@ Object {
"hasReleaseNotes": true,
"project": Object {
"github": "chalk/chalk",
"githubApiBaseURL": "https://api.github.com/",
"githubBaseURL": "https://github.com/",
"repository": "https://github.com/chalk/chalk",
},
......@@ -254,6 +259,7 @@ Object {
"hasReleaseNotes": true,
"project": Object {
"github": "chalk/chalk",
"githubApiBaseURL": "https://api.github.com/",
"githubBaseURL": "https://github.com/",
"repository": "https://github.com/chalk/chalk",
},
......
......@@ -43,7 +43,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotes(
'some/repository',
'1.0.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).toMatchSnapshot();
});
......@@ -61,7 +62,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotes(
'some/other-repository',
'1.0.1',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).toMatchSnapshot();
});
......@@ -71,7 +73,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'chalk',
'2.0.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBe(null);
});
......@@ -82,7 +85,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'chalk',
'2.0.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBe(null);
});
......@@ -97,7 +101,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'some/repository1',
'1.0.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBe(null);
});
......@@ -112,7 +117,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'some/repository2',
'1.0.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBe(null);
});
......@@ -127,7 +133,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'angular/angular.js',
'1.6.9',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).not.toBe(null);
expect(res).toMatchSnapshot();
......@@ -143,7 +150,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'facebook/jest',
'22.0.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).not.toBe(null);
expect(res).toMatchSnapshot();
......@@ -159,7 +167,8 @@ describe('workers/pr/release-notes', () => {
const res = await getReleaseNotesMd(
'nodeca/js-yaml',
'3.10.0',
'https://github.com/'
'https://github.com/',
'https://api.github.com/'
);
expect(res).not.toBe(null);
expect(res).toMatchSnapshot();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment