feat(github-releases): Add support for "releaseTimestamp" (#5711)

This commit is contained in:
Sergio Zharinov 2020-03-13 17:11:47 +04:00 committed by GitHub
parent 1130bed9a5
commit 4a6c786ff6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 18 deletions

View file

@ -5,18 +5,22 @@ Object {
"releases": Array [ "releases": Array [
Object { Object {
"gitRef": "a", "gitRef": "a",
"releaseTimestamp": "2020-03-09T13:00:00Z",
"version": "a", "version": "a",
}, },
Object { Object {
"gitRef": "v", "gitRef": "v",
"releaseTimestamp": "2020-03-09T12:00:00Z",
"version": "v", "version": "v",
}, },
Object { Object {
"gitRef": "1.0.0", "gitRef": "1.0.0",
"releaseTimestamp": "2020-03-09T11:00:00Z",
"version": "1.0.0", "version": "1.0.0",
}, },
Object { Object {
"gitRef": "v1.1.0", "gitRef": "v1.1.0",
"releaseTimestamp": "2020-03-09T10:00:00Z",
"version": "v1.1.0", "version": "v1.1.0",
}, },
], ],

View file

@ -14,10 +14,10 @@ describe('datasource/github-releases', () => {
beforeAll(() => global.renovateCache.rmAll()); beforeAll(() => global.renovateCache.rmAll());
it('returns releases', async () => { it('returns releases', async () => {
const body = [ const body = [
{ tag_name: 'a' }, { tag_name: 'a', published_at: '2020-03-09T13:00:00Z' },
{ tag_name: 'v' }, { tag_name: 'v', published_at: '2020-03-09T12:00:00Z' },
{ tag_name: '1.0.0' }, { tag_name: '1.0.0', published_at: '2020-03-09T11:00:00Z' },
{ tag_name: 'v1.1.0' }, { tag_name: 'v1.1.0', published_at: '2020-03-09T10:00:00Z' },
]; ];
ghGot.mockReturnValueOnce({ headers: {}, body }); ghGot.mockReturnValueOnce({ headers: {}, body });
const res = await github.getPkgReleases({ const res = await github.getPkgReleases({

View file

@ -8,6 +8,11 @@ export const id = 'github-releases';
const cacheNamespace = 'datasource-github-releases'; const cacheNamespace = 'datasource-github-releases';
type GithubRelease = {
tag_name: string;
published_at: string;
};
/** /**
* github.getPkgReleases * github.getPkgReleases
* *
@ -21,7 +26,7 @@ const cacheNamespace = 'datasource-github-releases';
export async function getPkgReleases({ export async function getPkgReleases({
lookupName: repo, lookupName: repo,
}: GetReleasesConfig): Promise<ReleaseResult | null> { }: GetReleasesConfig): Promise<ReleaseResult | null> {
let versions: string[]; let githubReleases: GithubRelease[];
const cachedResult = await renovateCache.get<ReleaseResult>( const cachedResult = await renovateCache.get<ReleaseResult>(
cacheNamespace, cacheNamespace,
repo repo
@ -32,29 +37,25 @@ export async function getPkgReleases({
} }
try { try {
const url = `https://api.github.com/repos/${repo}/releases?per_page=100`; const url = `https://api.github.com/repos/${repo}/releases?per_page=100`;
type GitHubRelease = { const res = await ghGot<GithubRelease[]>(url, {
tag_name: string;
}[];
versions = (
await ghGot<GitHubRelease>(url, {
paginate: true, paginate: true,
}) });
).body.map(o => o.tag_name); githubReleases = res.body;
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
logger.debug({ repo, err }, 'Error retrieving from github'); logger.debug({ repo, err }, 'Error retrieving from github');
} }
// istanbul ignore if // istanbul ignore if
if (!versions) { if (!githubReleases) {
return null; return null;
} }
const dependency: ReleaseResult = { const dependency: ReleaseResult = {
sourceUrl: 'https://github.com/' + repo, sourceUrl: 'https://github.com/' + repo,
releases: null, releases: null,
}; };
dependency.releases = versions.map(version => ({ dependency.releases = githubReleases.map(({ tag_name, published_at }) => ({
version, version: tag_name,
gitRef: version, gitRef: tag_name,
releaseTimestamp: published_at,
})); }));
const cacheMinutes = 10; const cacheMinutes = 10;
await renovateCache.set(cacheNamespace, repo, dependency, cacheMinutes); await renovateCache.set(cacheNamespace, repo, dependency, cacheMinutes);