Skip to content

Commit

Permalink
fix: allow null/undefined as param (#20528)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh authored Feb 21, 2023
1 parent 76dcaa6 commit 5279064
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
17 changes: 9 additions & 8 deletions lib/workers/repository/update/pr/changelog/release-notes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,21 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
});

describe('addReleaseNotes()', () => {
it('returns null if input is null/undefined', async () => {
expect(await addReleaseNotes(null, {} as BranchUpgradeConfig)).toBeNull();
expect(
await addReleaseNotes(undefined, {} as BranchUpgradeConfig)
).toBeNull();
});

it('returns input if invalid', async () => {
const input = { a: 1 };
expect(
await addReleaseNotes(input as never, {} as BranchUpgradeConfig)
).toEqual(input);
// TODO #7154
expect(await addReleaseNotes(null, {} as BranchUpgradeConfig)).toBeNull();
expect(
await addReleaseNotes(null as never, {} as BranchUpgradeConfig)
).toBeNull();
expect(
await addReleaseNotes(
{ versions: [] } as never,
{} as BranchUpgradeConfig
)
await addReleaseNotes({ versions: [] }, {} as BranchUpgradeConfig)
).toStrictEqual({
versions: [],
});
Expand Down
7 changes: 3 additions & 4 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,13 @@ export function releaseNotesCacheMinutes(releaseDate?: string | Date): number {
return 14495; // 5 minutes shy of 10 days
}

// TODO #7154 allow `null` and `undefined`
export async function addReleaseNotes(
input: ChangeLogResult,
input: ChangeLogResult | null | undefined,
config: BranchUpgradeConfig
): Promise<ChangeLogResult> {
): Promise<ChangeLogResult | null> {
if (!input?.versions || !input.project?.type) {
logger.debug('Missing project or versions');
return input;
return input ?? null;
}
const output: ChangeLogResult = { ...input, versions: [] };
const { repository, sourceDirectory } = input.project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export async function getChangeLogJSON(
}
}

let res: ChangeLogResult = {
let res: ChangeLogResult | null = {
project: {
apiBaseUrl,
baseUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function getChangeLogJSON(
}
}

let res: ChangeLogResult = {
let res: ChangeLogResult | null = {
project: {
apiBaseUrl,
baseUrl,
Expand Down

0 comments on commit 5279064

Please sign in to comment.