Skip to content

Commit

Permalink
docs: automate docs for releaseTimestamp and sourceUrl support (#…
Browse files Browse the repository at this point in the history
…29225)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
  • Loading branch information
3 people committed May 29, 2024
1 parent 3162e6e commit 6dd189e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
12 changes: 4 additions & 8 deletions lib/modules/datasource/nuget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ export class NugetDatasource extends Datasource {
override readonly registryStrategy = 'merge';

override readonly releaseTimestampSupport = true;
override readonly releaseTimestampNote = `
For the v2 API, the release timestamp is determined from the \`Publised\` tag and,
for the v3 API, the release timestamp is determined from the \`published\` field in the results.
`;
override readonly releaseTimestampNote =
'For the v2 API, the release timestamp is determined from the `Published` tag. And, for the v3 API, the release timestamp is determined from the `published` field in the results.';
override readonly sourceUrlSupport = 'package';
override readonly sourceUrlNote = `
For the v2 API, the source URL is determined from the \`ProjectUrl\` tag and,
for the v3 API, the source URL is determined from the \`metadata.repository@url\` field in the results.
`;
override readonly sourceUrlNote =
'For the v2 API, the source URL is determined from the `ProjectUrl` tag. And, for the v3 API, the source URL is determined from the `metadata.repository@url` field in the results.';

readonly v2Api = new NugetV2Api();

Expand Down
30 changes: 20 additions & 10 deletions tools/docs/datasources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export async function generateDatasources(
defaultConfig,
customRegistrySupport,
defaultVersioning,
releaseTimestampSupport,
releaseTimestampNote,
sourceUrlSupport,
sourceUrlNote,
} = definition;
const displayName = getDisplayName(datasource, definition);
datasourceContent += `* ${getModuleLink(
Expand All @@ -39,24 +43,30 @@ export async function generateDatasources(
# ${displayName} Datasource
`;
md += '\n\n';
md += `**Identifier**: \`${id}\`\n\n`;

let tableContent = '## Table of values\n\n';

tableContent += '| Name | Vaue | Notes |\n';
tableContent += '| :-- | :-- | :-- |\n';

tableContent += `| Identifier | \`${id}\` | \n`;
if (defaultVersioning) {
md += `**Default versioning**: \`${defaultVersioning}\`\n\n`;
tableContent += `| Default versioning | \`${defaultVersioning}\` | \n`;
} else {
md += `**Default versioning**: no default versioning\n\n`;
tableContent += `| Default versioning | No default versioning | \n`;
}

tableContent += `| Custom registry support | ${customRegistrySupport ? 'Yes' : 'No'} | \n`;
tableContent += `| Release timestamp support | ${releaseTimestampSupport ? 'Yes' : 'No'} | ${releaseTimestampNote ?? ''} |\n`;
tableContent += `| Source URL support | ${sourceUrlSupport === 'none' ? 'No' : 'Yes'} | ${sourceUrlNote ?? ''} |\n`;

md += tableContent + '\n';
md += formatUrls(urls);
md += `**Custom registry support**: \n\n`;
if (customRegistrySupport) {
md += `✅ Custom registries are supported.\n\n`;
} else {
md += `❌ No custom registry support.\n\n`;
}
md += await formatDescription('datasource', datasource);

if (defaultConfig) {
md +=
'**Default configuration**:\n\n```json\n' +
'## Default configuration\n\n```json\n' +
JSON.stringify(defaultConfig, undefined, 2) +
'\n```\n';
}
Expand Down
4 changes: 2 additions & 2 deletions tools/docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function replaceContent(content: string, txt: string): string {

export function formatUrls(urls: string[] | null | undefined): string {
if (Array.isArray(urls) && urls.length) {
return `**References**:\n\n${urls
return `## References\n\n${urls
.map((url) => ` - [${url}](${url})`)
.join('\n')}\n\n`;
}
Expand All @@ -65,7 +65,7 @@ export async function formatDescription(
if (!content) {
return '';
}
return `**Description**:\n\n${content}\n`;
return `## Description\n\n${content}\n`;
}

export function getModuleLink(module: string, title?: string): string {
Expand Down
4 changes: 2 additions & 2 deletions tools/docs/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export async function generateVersioning(
# ${displayName} Versioning
`;
md += '\n\n';
md += `**Identifier**: \`${id}\`\n\n`;
md += `## Identifier\n\n \`${id}\` \n\n`;
md += formatUrls(urls);
md += `**Ranges/Constraints:**\n\n`;
md += `## Ranges/Constraints\n\n`;
if (supportsRanges) {
md += `✅ Ranges are supported.\n\nValid \`rangeStrategy\` values are: ${(
supportedRangeStrategies ?? []
Expand Down

0 comments on commit 6dd189e

Please sign in to comment.