Skip to content

Commit

Permalink
refactor(datasource/orb): log res when no response (#20134)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Jan 31, 2023
1 parent c7c5c8f commit 3a58d23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/modules/datasource/orb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from '../../../logger';
import { cache } from '../../../util/cache/package/decorator';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import type { OrbRelease } from './types';
import type { OrbResponse } from './types';

const query = `
query($packageName: String!) {
Expand Down Expand Up @@ -45,20 +45,22 @@ export class OrbDatasource extends Datasource {
query,
variables: { packageName },
};
const res: OrbRelease = (
await this.http.postJson<{ data: { orb: OrbRelease } }>(url, {
const res = (
await this.http.postJson<OrbResponse>(url, {
body,
})
).body.data.orb;
if (!res) {
logger.debug(`Failed to look up orb ${packageName}`);
).body;
if (!res?.data?.orb) {
logger.debug({ res }, `Failed to look up orb ${packageName}`);
return null;
}

const { orb } = res.data;
// Simplify response before caching and returning
const homepage = res.homeUrl?.length
? res.homeUrl
const homepage = orb.homeUrl?.length
? orb.homeUrl
: `https://circleci.com/developer/orbs/orb/${packageName}`;
const releases = res.versions.map(({ version, createdAt }) => ({
const releases = orb.versions.map(({ version, createdAt }) => ({
version,
releaseTimestamp: createdAt ?? null,
}));
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/datasource/orb/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ export interface OrbRelease {
createdAt?: string;
}[];
}

export interface OrbResponse {
data?: {
orb?: OrbRelease;
};
}

0 comments on commit 3a58d23

Please sign in to comment.