Skip to content

Commit

Permalink
docs(managers): use table for categories display (#23503)
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Jul 24, 2023
1 parent e24ca0e commit 949681f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
52 changes: 28 additions & 24 deletions lib/constants/category.ts
@@ -1,24 +1,28 @@
export type Category =
| 'ansible'
| 'batect'
| 'bazel'
| 'c'
| 'cd'
| 'ci'
| 'dart'
| 'docker'
| 'dotnet'
| 'elixir'
| 'golang'
| 'helm'
| 'iac'
| 'java'
| 'js'
| 'kubernetes'
| 'node'
| 'php'
| 'python'
| 'ruby'
| 'rust'
| 'swift'
| 'terraform';
// istanbul ignore next
const Categories = [
'ansible',
'batect',
'bazel',
'c',
'cd',
'ci',
'dart',
'docker',
'dotnet',
'elixir',
'golang',
'helm',
'iac',
'java',
'js',
'kubernetes',
'node',
'php',
'python',
'ruby',
'rust',
'swift',
'terraform',
] as const;

export type Category = (typeof Categories)[number];
50 changes: 43 additions & 7 deletions tools/docs/manager.ts
@@ -1,4 +1,5 @@
import type { RenovateConfig } from '../../lib/config/types';
import type { Category } from '../../lib/constants';
import { getManagers } from '../../lib/modules/manager';
import { readFile, updateFile } from '../utils';
import { OpenItems, generateFeatureAndBugMarkdown } from './github-query-items';
Expand All @@ -9,7 +10,8 @@ import {
replaceContent,
} from './utils';

const noCategoryDisplayName = 'no-category';
const noCategoryID = 'no-category';
const noCategoryDisplayName = 'No Category';

function getTitle(manager: string, displayName: string): string {
if (manager === 'regex') {
Expand All @@ -22,6 +24,32 @@ function getManagerLink(manager: string): string {
return `[\`${manager}\`](${manager}/)`;
}

export const CategoryNames: Record<Category, string> = {
ansible: 'Ansible',
batect: 'Batect',
bazel: 'Bazel',
c: 'C and C++',
cd: 'Continuous Delivery',
ci: 'Continuous Integration',
dart: 'Dart',
docker: 'Docker',
dotnet: '.NET',
elixir: 'Elixir',
golang: 'Go',
helm: 'Helm',
iac: 'Infrastructure as Code',
java: 'Java',
js: 'JavaScript',
kubernetes: 'Kubernetes',
node: 'Node.js',
php: 'PHP',
python: 'Python',
ruby: 'Ruby',
rust: 'Rust',
swift: 'Swift',
terraform: 'Terraform',
};

export async function generateManagers(
dist: string,
managerIssuesMap: OpenItems
Expand All @@ -35,7 +63,7 @@ export async function generateManagers(
const { fileMatch } = defaultConfig as RenovateConfig;
const displayName = getDisplayName(manager, definition);

const categories = definition.categories ?? [noCategoryDisplayName];
const categories = definition.categories ?? [noCategoryID];
for (const category of categories) {
allCategories[category] ??= [];
allCategories[category].push(manager);
Expand Down Expand Up @@ -119,17 +147,25 @@ sidebar_label: ${displayName}

// add noCategoryDisplayName as last option
const categories = Object.keys(allCategories).filter(
(category) => category !== noCategoryDisplayName
(category) => category !== noCategoryID
);
categories.sort();
categories.push(noCategoryDisplayName);
categories.push(noCategoryID);
let categoryText = '\n';

categoryText += '| Group | Category ID | Managers |\n';
categoryText += '| :-- | :-- | :-- |\n';
for (const category of categories) {
categoryText += `**${category}**: `;
categoryText += allCategories[category].map(getManagerLink).join(', ');
categoryText += '\n\n';
const managerLinkList = allCategories[category]
.map(getManagerLink)
.join(', ');
const displayName =
CategoryNames[category as Category] ?? noCategoryDisplayName;
const massagedCategory =
category === noCategoryID ? 'n/a' : `\`${category}\``;
categoryText += `| ${displayName} | ${massagedCategory} | ${managerLinkList} | \n`;
}

let indexContent = await readFile(`docs/usage/modules/manager/index.md`);
indexContent = replaceContent(indexContent, categoryText);
await updateFile(`${dist}/modules/manager/index.md`, indexContent);
Expand Down

0 comments on commit 949681f

Please sign in to comment.