mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
feat: changelog for pip (#1927)
This PR adds support for pip changelog, unlike npm, I couldn't find a mapping between github and pip other than github being used as the homepage of some projects, if there are other ways of mapping it would be helpful. Closes #1911
This commit is contained in:
parent
79e737ed36
commit
38a4397feb
6 changed files with 126 additions and 0 deletions
|
@ -40,6 +40,8 @@ async function getPackageUpdates(config) {
|
|||
depName,
|
||||
newVersion,
|
||||
newVersionMajor: getMajor(newVersion),
|
||||
changeLogFromVersion: currentVersion,
|
||||
changeLogToVersion: newVersion,
|
||||
},
|
||||
];
|
||||
} catch (err) {
|
||||
|
|
|
@ -4,6 +4,7 @@ const sourceCache = require('./source-cache');
|
|||
const sourceGithub = require('./source-github');
|
||||
|
||||
const managerNpm = require('./manager-npm');
|
||||
const managerPip = require('./manager-pip');
|
||||
|
||||
module.exports = {
|
||||
getChangeLogJSON,
|
||||
|
@ -25,6 +26,10 @@ async function getChangeLogJSON(args) {
|
|||
pkg = await managerNpm.getPackage(args);
|
||||
}
|
||||
|
||||
if (manager === 'pip_requirements') {
|
||||
pkg = await managerPip.getPackage(args);
|
||||
}
|
||||
|
||||
res = await sourceGithub.getChangeLogJSON({ ...args, ...pkg });
|
||||
|
||||
await sourceCache.setChangeLogJSON(args, res);
|
||||
|
|
36
lib/workers/pr/changelog/manager-pip.js
Normal file
36
lib/workers/pr/changelog/manager-pip.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const got = require('got');
|
||||
const { semverSort, isPinnedVersion } = require('../../../util/semver');
|
||||
|
||||
module.exports = {
|
||||
getPackage,
|
||||
};
|
||||
|
||||
async function getPackage({ depName }) {
|
||||
try {
|
||||
logger.debug({ depName }, 'fetching pip package versions');
|
||||
const rep = await got(`https://pypi.org/pypi/${depName}/json`, {
|
||||
json: true,
|
||||
});
|
||||
|
||||
const dep = rep && rep.body;
|
||||
if (!dep) {
|
||||
logger.debug({ depName }, 'pip package not found');
|
||||
return null;
|
||||
}
|
||||
const releases = Object.keys(dep.releases).filter(isPinnedVersion);
|
||||
releases.sort(semverSort);
|
||||
const versions = releases.map(release => ({
|
||||
version: release,
|
||||
date: (dep.releases[release][0] || {}).upload_time,
|
||||
}));
|
||||
const res = {
|
||||
repositoryUrl: dep.info.home_page,
|
||||
versions,
|
||||
};
|
||||
logger.debug({ res }, 'found pip package versions');
|
||||
return res;
|
||||
} catch (err) {
|
||||
logger.debug({ err }, 'failed to fetch pip package versions');
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
exports[`lib/manager/pip_requirements/package getPackageUpdates() returns one upgrade 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"changeLogFromVersion": "0.3.2",
|
||||
"changeLogToVersion": "1.0.2",
|
||||
"depName": "some-package",
|
||||
"newVersion": "1.0.2",
|
||||
"newVersionMajor": 1,
|
||||
|
|
|
@ -100,6 +100,46 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`workers/pr/changelog getChangeLogJSON supports pip 1`] = `
|
||||
Object {
|
||||
"hasReleaseNotes": false,
|
||||
"project": Object {
|
||||
"github": "chalk/chalk",
|
||||
"repository": "https://github.com/chalk/chalk",
|
||||
},
|
||||
"versions": Array [
|
||||
Object {
|
||||
"changes": Array [],
|
||||
"compare": Object {},
|
||||
"date": undefined,
|
||||
"releaseNotes": undefined,
|
||||
"version": "2.5.2",
|
||||
},
|
||||
Object {
|
||||
"changes": Array [],
|
||||
"compare": Object {},
|
||||
"date": "2017-12-24T03:20:46.238Z",
|
||||
"releaseNotes": undefined,
|
||||
"version": "2.4.2",
|
||||
},
|
||||
Object {
|
||||
"changes": Array [],
|
||||
"compare": Object {},
|
||||
"date": "2017-10-24T03:20:46.238Z",
|
||||
"releaseNotes": undefined,
|
||||
"version": "2.3.0",
|
||||
},
|
||||
Object {
|
||||
"changes": Array [],
|
||||
"compare": Object {},
|
||||
"date": undefined,
|
||||
"releaseNotes": undefined,
|
||||
"version": "2.2.2",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`workers/pr/changelog getChangeLogJSON uses GitHub tags 1`] = `
|
||||
Object {
|
||||
"hasReleaseNotes": true,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
jest.mock('../../../lib/platform/github/gh-got-wrapper');
|
||||
jest.mock('../../../lib/datasource/npm');
|
||||
jest.mock('got');
|
||||
|
||||
const ghGot = require('../../../lib/platform/github/gh-got-wrapper');
|
||||
const npmRegistry = require('../../../lib/datasource/npm');
|
||||
const got = require('got');
|
||||
|
||||
const { getChangeLogJSON } = require('../../../lib/workers/pr/changelog');
|
||||
const {
|
||||
|
@ -30,6 +32,22 @@ function npmResponse() {
|
|||
};
|
||||
}
|
||||
|
||||
function pipResponse() {
|
||||
return {
|
||||
info: {
|
||||
home_page: 'https://github.com/chalk/chalk',
|
||||
},
|
||||
releases: {
|
||||
'0.9.0': [],
|
||||
'1.0.0': [],
|
||||
'2.3.0': [{ upload_time: '2017-10-24T03:20:46.238Z' }],
|
||||
'2.2.2': [{}],
|
||||
'2.4.2': [{ upload_time: '2017-12-24T03:20:46.238Z' }],
|
||||
'2.5.2': [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('workers/pr/changelog', () => {
|
||||
describe('getChangeLogJSON', () => {
|
||||
beforeEach(async () => {
|
||||
|
@ -132,5 +150,28 @@ describe('workers/pr/changelog', () => {
|
|||
null
|
||||
);
|
||||
});
|
||||
it('supports pip', async () => {
|
||||
got.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
body: pipResponse(),
|
||||
})
|
||||
);
|
||||
expect(
|
||||
await getChangeLogJSON({ ...upgrade, manager: 'pip_requirements' })
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
it('works without pip', async () => {
|
||||
expect(
|
||||
await getChangeLogJSON({ ...upgrade, manager: 'pip_requirements' })
|
||||
).toBe(null);
|
||||
});
|
||||
it('handles pip errors', async () => {
|
||||
got.mockImplementation(() => {
|
||||
throw new Error('Unknown Pip Repo');
|
||||
});
|
||||
expect(
|
||||
await getChangeLogJSON({ ...upgrade, manager: 'pip_requirements' })
|
||||
).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue