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: add per manager known list of issues #15791

Merged
Merged
81 changes: 81 additions & 0 deletions tools/docs/github-query-items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export type GithubApiQueryResponse = {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
total_count: number;
incomplete_results: boolean;
items: ItemsEntity[];
};

export type ItemsEntity = {
Gabriel-Ladzaretti marked this conversation as resolved.
Show resolved Hide resolved
url: string;
repository_url: string;
labels_url: string;
comments_url: string;
events_url: string;
html_url: string;
id: number;
node_id: string;
number: number;
title: string;
user: User;
labels: LabelsEntity[];
state: string;
locked: boolean;
assignee: User;
assignees: User[];
milestone: string;
comments: number;
created_at: string;
updated_at: string;
closed_at: string;
author_association: string;
active_lock_reason?: string;
body: string;
reactions: Reactions;
timeline_url: string;
performed_via_github_app: boolean;
state_reason: string;
score: number;
};

export type User = {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
};

export type LabelsEntity = {
id: number;
node_id: string;
url: string;
name: string;
color: string;
default: boolean;
description: string;
};

export type Reactions = {
url: string;
total_count: number;
'+1': number;
'-1': number;
laugh: number;
hooray: number;
confused: number;
heart: number;
rocket: number;
eyes: number;
};
97 changes: 97 additions & 0 deletions tools/docs/manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import got from 'got';
import type { RenovateConfig } from '../../lib/config/types';
import { logger } from '../../lib/logger';
import { getManagers } from '../../lib/modules/manager';
import { getQueryString } from '../../lib/util/url';
import { readFile, updateFile } from '../utils';
import type { GithubApiQueryResponse, ItemsEntity } from './github-query-items';
import { getDisplayName, getNameWithUrl, replaceContent } from './utils';

const gitHubApi = 'https://api.github.com/search/issues?';

interface ManagerIssues {
bugs: ItemsEntity[];
features: ItemsEntity[];
}

function getTitle(manager: string, displayName: string): string {
if (manager === 'regex') {
return `Custom Manager Support using Regex`;
Expand All @@ -14,8 +25,78 @@ function getManagerLink(manager: string): string {
return `[\`${manager}\`](${manager}/)`;
}

function stringifyIssues(items: ItemsEntity[]): string {
if (!items) {
return '';
}
let list = '';
for (const item of items) {
list += ` - ${item.title} [#${item.number}](${item.html_url})\n`;
}
return list;
}

function extractIssues(
managerIssuesMap: Record<string, ManagerIssues>,
items: ItemsEntity[]
): void {
if (!items || !managerIssuesMap) {
return;
}
for (const item of items) {
const type = item.labels
.find((l) => l.name.startsWith('type'))
Gabriel-Ladzaretti marked this conversation as resolved.
Show resolved Hide resolved
?.name.split(':')[1];
if (!type) {
continue;
}
const manager = item.labels
.find((l) => l.name.startsWith('manager'))
Gabriel-Ladzaretti marked this conversation as resolved.
Show resolved Hide resolved
?.name.split(':')[1];
if (!manager) {
continue;
}
if (!managerIssuesMap[manager]) {
managerIssuesMap[manager] = { bugs: [], features: [] };
}
switch (type) {
case 'bug':
managerIssuesMap[manager].bugs.push(item);
break;
case 'feature':
managerIssuesMap[manager].features.push(item);
break;
default:
break;
}
}
}

export async function getManagersGitHubIssues(): Promise<
Record<string, ManagerIssues>
> {
const q = `repo:renovatebot/renovate type:issue is:open -label:priority-5-triage`;
const per_page = 100;
const managerIssuesMap: Record<string, ManagerIssues> = {};
try {
let previouslyFound = per_page;
for (let page = 1; previouslyFound === per_page; page++) {
const query = getQueryString({ q, per_page, page });
const res = await got(gitHubApi + query).json<GithubApiQueryResponse>();
Gabriel-Ladzaretti marked this conversation as resolved.
Show resolved Hide resolved
const items = res.items ?? [];
previouslyFound = items.length;
extractIssues(managerIssuesMap, items);
}
} catch (err) {
logger.error({ err }, 'Error getting query results');
throw err;
}
return managerIssuesMap;
}

export async function generateManagers(dist: string): Promise<void> {
const managers = getManagers();
const managerIssuesMap = await getManagersGitHubIssues();
const allLanguages: Record<string, string[]> = {};
for (const [manager, definition] of managers) {
const language = definition.language ?? 'other';
Expand Down Expand Up @@ -73,6 +154,22 @@ sidebar_label: ${displayName}
}
md += managerReadmeContent + '\n\n';

const bugList = stringifyIssues(managerIssuesMap[manager]?.bugs);
if (bugList) {
md += '<!-- prettier-ignore -->\n';
md += '??? note "Click me to see the list of open bug reports"\n';
md += bugList;
md += '\n';
}

const featureList = stringifyIssues(managerIssuesMap[manager]?.features);
if (featureList) {
md += '<!-- prettier-ignore -->\n';
md += '??? note "Click me to see the list of upcoming features"\n';
md += featureList;
md += '\n';
}

await updateFile(`${dist}/modules/manager/${manager}/index.md`, md);
}
const languages = Object.keys(allLanguages).filter(
Expand Down