From 4a6c786ff69d3e57d095c715d508c8bc04d28d7f Mon Sep 17 00:00:00 2001 From: Sergio Zharinov <zharinov@users.noreply.github.com> Date: Fri, 13 Mar 2020 17:11:47 +0400 Subject: [PATCH] feat(github-releases): Add support for "releaseTimestamp" (#5711) --- .../__snapshots__/index.spec.ts.snap | 4 +++ lib/datasource/github-releases/index.spec.ts | 8 ++--- lib/datasource/github-releases/index.ts | 29 ++++++++++--------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/datasource/github-releases/__snapshots__/index.spec.ts.snap b/lib/datasource/github-releases/__snapshots__/index.spec.ts.snap index 9eeabf0cc6..b4544ba763 100644 --- a/lib/datasource/github-releases/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/github-releases/__snapshots__/index.spec.ts.snap @@ -5,18 +5,22 @@ Object { "releases": Array [ Object { "gitRef": "a", + "releaseTimestamp": "2020-03-09T13:00:00Z", "version": "a", }, Object { "gitRef": "v", + "releaseTimestamp": "2020-03-09T12:00:00Z", "version": "v", }, Object { "gitRef": "1.0.0", + "releaseTimestamp": "2020-03-09T11:00:00Z", "version": "1.0.0", }, Object { "gitRef": "v1.1.0", + "releaseTimestamp": "2020-03-09T10:00:00Z", "version": "v1.1.0", }, ], diff --git a/lib/datasource/github-releases/index.spec.ts b/lib/datasource/github-releases/index.spec.ts index 4213117cfd..8e19d6e1c4 100644 --- a/lib/datasource/github-releases/index.spec.ts +++ b/lib/datasource/github-releases/index.spec.ts @@ -14,10 +14,10 @@ describe('datasource/github-releases', () => { beforeAll(() => global.renovateCache.rmAll()); it('returns releases', async () => { const body = [ - { tag_name: 'a' }, - { tag_name: 'v' }, - { tag_name: '1.0.0' }, - { tag_name: 'v1.1.0' }, + { tag_name: 'a', published_at: '2020-03-09T13:00:00Z' }, + { tag_name: 'v', published_at: '2020-03-09T12:00:00Z' }, + { tag_name: '1.0.0', published_at: '2020-03-09T11:00:00Z' }, + { tag_name: 'v1.1.0', published_at: '2020-03-09T10:00:00Z' }, ]; ghGot.mockReturnValueOnce({ headers: {}, body }); const res = await github.getPkgReleases({ diff --git a/lib/datasource/github-releases/index.ts b/lib/datasource/github-releases/index.ts index f57f0434b5..02b192b992 100644 --- a/lib/datasource/github-releases/index.ts +++ b/lib/datasource/github-releases/index.ts @@ -8,6 +8,11 @@ export const id = 'github-releases'; const cacheNamespace = 'datasource-github-releases'; +type GithubRelease = { + tag_name: string; + published_at: string; +}; + /** * github.getPkgReleases * @@ -21,7 +26,7 @@ const cacheNamespace = 'datasource-github-releases'; export async function getPkgReleases({ lookupName: repo, }: GetReleasesConfig): Promise<ReleaseResult | null> { - let versions: string[]; + let githubReleases: GithubRelease[]; const cachedResult = await renovateCache.get<ReleaseResult>( cacheNamespace, repo @@ -32,29 +37,25 @@ export async function getPkgReleases({ } try { const url = `https://api.github.com/repos/${repo}/releases?per_page=100`; - type GitHubRelease = { - tag_name: string; - }[]; - - versions = ( - await ghGot<GitHubRelease>(url, { - paginate: true, - }) - ).body.map(o => o.tag_name); + const res = await ghGot<GithubRelease[]>(url, { + paginate: true, + }); + githubReleases = res.body; } catch (err) /* istanbul ignore next */ { logger.debug({ repo, err }, 'Error retrieving from github'); } // istanbul ignore if - if (!versions) { + if (!githubReleases) { return null; } const dependency: ReleaseResult = { sourceUrl: 'https://github.com/' + repo, releases: null, }; - dependency.releases = versions.map(version => ({ - version, - gitRef: version, + dependency.releases = githubReleases.map(({ tag_name, published_at }) => ({ + version: tag_name, + gitRef: tag_name, + releaseTimestamp: published_at, })); const cacheMinutes = 10; await renovateCache.set(cacheNamespace, repo, dependency, cacheMinutes); -- GitLab