chore(datasource/metadata): Move massageGithub|GitLabUrl() functions out of addMetaData() (#7264)

This commit is contained in:
Tobias Bieniek 2020-09-12 14:15:40 +02:00 committed by GitHub
parent 171b65eed0
commit 9c4203c890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,6 +76,25 @@ const manualSourceUrls = {
},
};
function massageGithubUrl(url: string): string {
return url
.replace('http:', 'https:')
.replace(/^git:\/?\/?/, 'https://')
.replace('www.github.com', 'github.com')
.split('/')
.slice(0, 5)
.join('/');
}
function massageGitlabUrl(url: string): string {
return url
.replace('http:', 'https:')
.replace(/^git:\/?\/?/, 'https://')
.replace(/\/tree\/.*$/i, '')
.replace(/\/$/i, '')
.replace('.git', '');
}
/* eslint-disable no-param-reassign */
export function addMetaData(
dep?: ReleaseResult,
@ -93,30 +112,6 @@ export function addMetaData(
dep.sourceUrl = manualSourceUrls[datasource][lookupNameLowercase];
}
/**
* @param {string} url
*/
const massageGithubUrl = (url: string): string => {
return url
.replace('http:', 'https:')
.replace(/^git:\/?\/?/, 'https://')
.replace('www.github.com', 'github.com')
.split('/')
.slice(0, 5)
.join('/');
};
/**
* @param {string} url
*/
const massageGitlabUrl = (url: string): string => {
return url
.replace('http:', 'https:')
.replace(/^git:\/?\/?/, 'https://')
.replace(/\/tree\/.*$/i, '')
.replace(/\/$/i, '')
.replace('.git', '');
};
if (
dep.changelogUrl?.includes('github.com') && // lgtm [js/incomplete-url-substring-sanitization]
!dep.sourceUrl