renovate/lib/datasource/metadata.ts

118 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-07-17 08:14:56 +00:00
import is from '@sindresorhus/is';
import parse from 'github-url-from-git';
import { ReleaseResult } from './common';
2018-12-25 05:57:11 +00:00
// Use this object to define changelog URLs for packages
// Only necessary when the changelog data cannot be found in the package's source repository
const manualChangelogUrls = {
npm: {
'babel-preset-react-app':
'https://github.com/facebook/create-react-app/releases',
2018-12-25 05:57:11 +00:00
firebase: 'https://firebase.google.com/support/release-notes/js',
'flow-bin': 'https://github.com/facebook/flow/blob/master/Changelog.md',
'react-native':
'https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md',
},
pypi: {
'pytest-django':
'https://pytest-django.readthedocs.io/en/latest/changelog.html#changelog',
django: 'https://github.com/django/django/tree/master/docs/releases',
djangorestframework:
'https://www.django-rest-framework.org/community/release-notes/',
flake8: 'http://flake8.pycqa.org/en/latest/release-notes/index.html',
'django-storages':
'https://github.com/jschneier/django-storages/blob/master/CHANGELOG.rst',
phonenumbers:
'https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/HISTORY.md',
'psycopg2-binary': 'http://initd.org/psycopg/articles/tag/release/',
'django-debug-toolbar':
'https://django-debug-toolbar.readthedocs.io/en/latest/changes.html',
'firebase-admin':
'https://firebase.google.com/support/release-notes/admin/python',
requests:
'http://docs.python-requests.org/en/master/community/updates/#release-and-version-history',
wagtail: 'https://github.com/wagtail/wagtail/tree/master/docs/releases',
2018-12-25 05:57:11 +00:00
},
};
// Use this object to define manual source URLs for packages
// Only necessary if the datasource is unable to locate the source URL itself
const manualSourceUrls = {
orb: {
'cypress-io/cypress': 'https://github.com/cypress-io/circleci-orb',
'hutson/library-release-workflows':
'https://github.com/hyper-expanse/library-release-workflows',
},
docker: {
node: 'https://github.com/nodejs/node',
},
kubernetes: {
node: 'https://github.com/nodejs/node',
},
npm: {
node: 'https://github.com/nodejs/node',
},
nvm: {
node: 'https://github.com/nodejs/node',
},
pypi: {
coverage: 'https://github.com/nedbat/coveragepy/', // bitbucket entry on pypi is wrong
mkdocs: 'https://github.com/mkdocs/mkdocs',
pillow: 'https://github.com/python-pillow/Pillow',
},
};
/* eslint-disable no-param-reassign */
export function addMetaData(
dep?: ReleaseResult,
datasource?: string,
lookupName?: string
) {
2018-12-25 05:57:11 +00:00
if (!dep) {
return;
}
const depName = lookupName ? lookupName.toLowerCase() : null;
2018-12-25 05:57:11 +00:00
if (
manualChangelogUrls[datasource] &&
manualChangelogUrls[datasource][depName]
2018-12-25 05:57:11 +00:00
) {
dep.changelogUrl = manualChangelogUrls[datasource][depName];
2018-12-25 05:57:11 +00:00
}
if (manualSourceUrls[datasource] && manualSourceUrls[datasource][depName]) {
dep.sourceUrl = manualSourceUrls[datasource][depName];
2018-12-25 05:57:11 +00:00
}
/**
* @param {string} url
*/
const massageGithubUrl = url => {
return url
.replace('http:', 'https:')
.replace('www.github.com', 'github.com')
.split('/')
.slice(0, 5)
.join('/');
};
if (dep.sourceUrl && dep.sourceUrl.includes('github.com')) {
dep.sourceUrl = parse(massageGithubUrl(dep.sourceUrl));
}
2018-12-25 05:57:11 +00:00
if (
!dep.sourceUrl &&
dep.changelogUrl &&
dep.changelogUrl.match(/^https?:\/\/(www\.)?github\.com/)
2018-12-25 05:57:11 +00:00
) {
dep.sourceUrl = massageGithubUrl(dep.changelogUrl);
2018-12-25 05:57:11 +00:00
}
2018-12-25 06:02:10 +00:00
// Clean up any empty urls
const urls = ['homepage', 'sourceUrl', 'changelogUrl'];
for (const url of urls) {
if (is.nonEmptyString(dep[url])) {
dep[url] = dep[url].trim();
} else {
2018-12-25 06:02:10 +00:00
delete dep[url];
}
}
2018-12-25 05:57:11 +00:00
}