Skip to content

Commit

Permalink
Apply Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Jan 24, 2025
1 parent 3b2fd36 commit a2041b7
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions tools/docs/github-query-items.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DateTime } from 'luxon';
import { z } from 'zod';
import { logger } from '../../lib/logger';
import { exec } from '../../lib/util/exec';

export type ItemsEntity = {
html_url: string;
url: string;
number: number;
title: string;
labels: LabelsEntity[];
Expand All @@ -28,22 +29,31 @@ export interface Items {
features: ItemsEntity[];
}

interface GhIssueOutput {
title: string;
number: number;
url: string;
labels: { name: string; id: string; description: string }[];
}
const GhOutputSchema = z.array(
z.object({
url: z.string(),
title: z.string(),
labels: z.array(
z.object({
name: z.string(),
}),
),
number: z.number(),
}),
);

async function getIssuesByIssueType(
issueType: 'Bug' | 'Feature',
): Promise<ItemsEntity[]> {
const command = `gh issue list --json "title,number,url,labels" --search "type:${issueType}" --limit 1000`;
const res = await exec(command);
const issues = JSON.parse(res.stdout) as GhIssueOutput[];
const execRes = await exec(command);
const res = GhOutputSchema.safeParse(JSON.parse(execRes.stdout));
if (res.error) {
throw res.error;
}

return issues.map((issue) => {
return { ...issue, html_url: issue.url, issueType };
return res.data.map((issue) => {
return { ...issue, issueType };
});
}

Expand All @@ -67,6 +77,10 @@ export async function getOpenGitHubItems(): Promise<RenovateOpenItems> {
return result;
}

if (process.env.CI) {
return result;
}

try {
const rawItems: ItemsEntity[] = (await getIssuesByIssueType('Bug')).concat(
await getIssuesByIssueType('Feature'),
Expand Down Expand Up @@ -126,7 +140,7 @@ function stringifyIssues(items: ItemsEntity[] | undefined): string {
}
let list = '';
for (const item of items) {
list += ` - ${item.title} [#${item.number}](${item.html_url})\n`;
list += ` - ${item.title} [#${item.number}](${item.url})\n`;
}
return list;
}
Expand Down

0 comments on commit a2041b7

Please sign in to comment.