mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
feat(github-releases): Add support for "releaseTimestamp" (#5711)
This commit is contained in:
parent
1130bed9a5
commit
4a6c786ff6
3 changed files with 23 additions and 18 deletions
|
@ -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",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue