Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pypi): changelog lookup in project_urls #6421

Merged
merged 9 commits into from Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/datasource/pypi/__snapshots__/index.spec.ts.snap
@@ -1,5 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`datasource/pypi getReleases find url from project_urls 1`] = `
Object {
"changelogUrl": "https://github.com/Flexget/wiki/blob/master/ChangeLog.md",
"homepage": "https://flexget.com",
"releases": Array [],
"sourceUrl": "https://github.com/Flexget/Flexget",
}
`;

exports[`datasource/pypi getReleases process data from +simple endpoint 1`] = `
Object {
"releases": Array [
Expand Down Expand Up @@ -206,14 +215,6 @@ Object {
}
`;

exports[`datasource/pypi getReleases return sourceUrl in project_urls 1`] = `
Object {
"homepage": "https://flexget.com",
"releases": Array [],
"sourceUrl": "https://github.com/Flexget/Flexget",
}
`;

exports[`datasource/pypi getReleases returns non-github home_page 1`] = `
Object {
"homepage": "https://microsoft.com",
Expand Down
27 changes: 15 additions & 12 deletions lib/datasource/pypi/index.spec.ts
Expand Up @@ -122,25 +122,28 @@ describe('datasource/pypi', () => {
})
).toMatchSnapshot();
});
it('return sourceUrl in project_urls', async () => {
it('find url from project_urls', async () => {
const info = {
name: 'flexget',
home_page: 'https://flexget.com',
project_urls: {
Forum: 'https://discuss.flexget.com',
Homepage: 'https://flexget.com',
changelog: 'https://github.com/Flexget/wiki/blob/master/ChangeLog.md',
'Issue Tracker': 'https://github.com/Flexget/Flexget/issues',
Repository: 'https://github.com/Flexget/Flexget',
},
};
got.mockReturnValueOnce({
body: {
info: {
name: 'flexget',
home_page: 'https://flexget.com',
project_urls: {
Forum: 'https://discuss.flexget.com',
Homepage: 'https://flexget.com',
'Issue Tracker': 'https://github.com/Flexget/Flexget/issues',
Repository: 'https://github.com/Flexget/Flexget',
},
},
info,
},
});
const result = await pypi.getReleases({
lookupName: 'flexget',
});
expect(result.sourceUrl).toBe('https://github.com/Flexget/Flexget');
expect(result.sourceUrl).toBe(info.project_urls.Repository);
expect(result.changelogUrl).toBe(info.project_urls.changelog);
expect(result).toMatchSnapshot();
});
it('returns null if mismatched name', async () => {
Expand Down
30 changes: 24 additions & 6 deletions lib/datasource/pypi/index.ts
@@ -1,5 +1,6 @@
import url from 'url';
import is from '@sindresorhus/is';
import changelogFilenameRegex from 'changelog-filename-regex';
import { parse } from 'node-html-parser';
import { logger } from '../../logger';
import { Http } from '../../util/http';
Expand Down Expand Up @@ -83,17 +84,34 @@ async function getDependency(
}
}

if (dep.info?.project_urls && !dependency.sourceUrl) {
if (dep.info?.project_urls) {
for (const [name, projectUrl] of Object.entries(dep.info.project_urls)) {
const lower = name.toLowerCase();

if (
lower.startsWith('repo') ||
lower === 'code' ||
lower === 'source' ||
github_repo_pattern.exec(projectUrl)
!dependency.sourceUrl &&
(lower.startsWith('repo') ||
lower === 'code' ||
lower === 'source' ||
github_repo_pattern.exec(projectUrl))
) {
dependency.sourceUrl = projectUrl;
break;
}

if (
!dependency.changelogUrl &&
([
'changelog',
'change log',
'changes',
'release notes',
'news',
"what's new",
].includes(lower) ||
changelogFilenameRegex.exec(lower))
) {
// from https://github.com/pypa/warehouse/blob/418c7511dc367fb410c71be139545d0134ccb0df/warehouse/templates/packaging/detail.html#L24
dependency.changelogUrl = projectUrl;
}
}
}
Expand Down