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

docs: use issueType field for docs generation #33718

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
69 changes: 34 additions & 35 deletions tools/docs/github-query-items.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import { DateTime } from 'luxon';
import { logger } from '../../lib/logger';
import * as hostRules from '../../lib/util/host-rules';
import { GithubHttp } from '../../lib/util/http/github';
import { getQueryString } from '../../lib/util/url';

const gitHubApiUrl = 'https://api.github.com/search/issues?';
const githubApi = new GithubHttp();

if (process.env.GITHUB_TOKEN) {
logger.info('Using GITHUB_TOKEN from env');
hostRules.add({
matchHost: 'api.github.com',
token: process.env.GITHUB_TOKEN,
});
}

type GithubApiQueryResponse = {
total_count: number;
incomplete_results: boolean;
items: ItemsEntity[];
};
import { exec } from '../../lib/util/exec';

export type ItemsEntity = {
html_url: string;
number: number;
title: string;
labels: LabelsEntity[];
issueType: 'Bug' | 'Feature';
};

export type LabelsEntity = {
Expand All @@ -46,6 +28,25 @@ export interface Items {
features: ItemsEntity[];
}

interface GhIssueOutput {
title: string;
number: number;
url: string;
labels: { name: string; id: string; description: string }[];
}

async function getIssuesByIssueType(
issueType: 'Bug' | 'Feature',
): Promise<ItemsEntity[]> {
const command = `gh issue list --json "title,number,url,labels" --search "type:${issueType}" --limit 1000`;
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
viceice marked this conversation as resolved.
Show resolved Hide resolved
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
const res = await exec(command);
const issues = JSON.parse(res.stdout) as GhIssueOutput[];
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

return issues.map((issue) => {
return { ...issue, html_url: issue.url, issueType };
});
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
}

export async function getOpenGitHubItems(): Promise<RenovateOpenItems> {
const result: RenovateOpenItems = {
managers: {},
Expand All @@ -59,18 +60,17 @@ export async function getOpenGitHubItems(): Promise<RenovateOpenItems> {
return result;
}

const q = `repo:renovatebot/renovate type:issue is:open`;
const per_page = 100;
if (!process.env.GITHUB_TOKEN) {
logger.warn(
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
'No GITHUB_TOKEN found in env, cannot fetch Github issues. Skipping...',
);
return result;
}
viceice marked this conversation as resolved.
Show resolved Hide resolved

try {
const query = getQueryString({ q, per_page });
const res = await githubApi.getJsonUnchecked<GithubApiQueryResponse>(
gitHubApiUrl + query,
{
paginationField: 'items',
paginate: true,
},
const rawItems: ItemsEntity[] = (await getIssuesByIssueType('Bug')).concat(
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
await getIssuesByIssueType('Feature'),
);
const rawItems = res.body?.items ?? [];

result.managers = extractIssues(rawItems, 'manager:');
result.platforms = extractIssues(rawItems, 'platform:');
Expand All @@ -91,9 +91,8 @@ function extractIssues(items: ItemsEntity[], labelPrefix: string): OpenItems {
const issuesMap: OpenItems = {};

for (const item of items) {
const type = item.labels
.find((l) => l.name.startsWith('type:'))
?.name.split(':')[1];
const type = item.issueType;

if (!type) {
continue;
}
Expand All @@ -107,10 +106,10 @@ function extractIssues(items: ItemsEntity[], labelPrefix: string): OpenItems {
issuesMap[label] = { bugs: [], features: [] };
}
switch (type) {
case 'bug':
case 'Bug':
issuesMap[label]?.bugs.push(item);
break;
case 'feature':
case 'Feature':
issuesMap[label]?.features.push(item);
break;
default:
Expand Down
Loading