Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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",
},
],
Expand Down
8 changes: 4 additions & 4 deletions lib/datasource/github-releases/index.spec.ts
Expand Up @@ -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({
Expand Down
29 changes: 15 additions & 14 deletions lib/datasource/github-releases/index.ts
Expand Up @@ -8,6 +8,11 @@ export const id = 'github-releases';

const cacheNamespace = 'datasource-github-releases';

type GithubRelease = {
tag_name: string;
published_at: string;
};

/**
* github.getPkgReleases
*
Expand All @@ -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
Expand All @@ -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);
Expand Down