Skip to content

Commit

Permalink
Add a new button linked to documentation
Browse files Browse the repository at this point in the history
Add a new optional property 'docsUrl' to the index schema that allows to
set the documentation's url. In case it isn't used, the readme is
automatically linked. If the readme does not exist, the repo url
is linked.
  • Loading branch information
FilipZajdel committed Dec 5, 2024
1 parent 83fbdbc commit afb6962
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 16 deletions.
3 changes: 2 additions & 1 deletion index/hello-nrfcloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"tag": "v2.0.1",
"sdk": "v2.8.0-rc2"
}
]
],
"docsUrl": "https://hello-nrfcloud.github.io/firmware/html/index.html"
}
]
}
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@octokit/rest": "^20.0.1",
"@primer/octicons-react": "^19.8.0",
"ajv": "^8.12.0",
"ajv-formats": "3.0.1",
"ansi-colors": "^4.1.3",
"classnames": "^2.3.2",
"date-fns": "^2.30.0",
Expand Down
14 changes: 12 additions & 2 deletions resources/output_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@
"dfu",
"thread",
"matter",
"bt-mesh"
"bt-mesh",
"sidewalk",
"lora-basics-modem",
"CSS",
"FSK",
"ble",
"blecon",
"connectivity"
]
}
},
Expand All @@ -152,7 +159,7 @@
},
"date": {
"type": "string",
"format": "date"
"format": "date-time"
},
"sdk": {
"type": "string"
Expand Down Expand Up @@ -186,6 +193,9 @@
},
"apps": {
"type": "string"
},
"docsUrl": {
"type": "string"
}
},
"required": [
Expand Down
28 changes: 20 additions & 8 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,39 @@
"type": "string",
"description": "The name of the application license, e.g. \"Apache 2.0\". Inferred from the repo if missing."
},
"apps": {
"type": "string",
"description": "Glob pattern to find directories containing applications.\n\nApplications need a *.conf file and a CMakeLists.txt file at their root. The glob expressions are used to match directories, so no file pattern is necessary.\n\nBy default, the VS Code extension will assume that there's just a single application sitting at the root of the repo."
},
"releases": {
"type": "array",
"description": "The collection of project`s releases.",
"items": {
"type": "object",
"properties": {
"tag": {
"type": "string"
"type": "string",
"description": "Git tag of the released version."
},
"name": {
"type": "string"
"type": "string",
"description": "The title of the release."
},
"date": {
"type": "string"
"type": "string",
"format": "date-time",
"description": "The date of publishing the release."
},
"sdk": {
"type": "string"
"type": "string",
"description": "The nRF Connect SDK version the release is compatible with."
}
},
"required": [
"tag",
"name",
"date"
"date",
"sdk"
],
"additionalProperties": false
},
Expand All @@ -106,16 +117,17 @@
"type": "string",
"description": "The default git branch that the repository is checked out. Inferred from the repo if missing."
},
"apps": {
"docsUrl": {
"type": "string",
"description": "Glob pattern to find directories containing applications.\n\nApplications need a *.conf file and a CMakeLists.txt file at their root. The glob expressions are used to match directories, so no file pattern is necessary.\n\nBy default, the VS Code extension will assume that there's just a single application sitting at the root of the repo."
"description": "The url of the addon's documentation"
}
},
"additionalProperties": false,
"required": [
"name",
"kind",
"tags"
"tags",
"releases"
]
},
"description": "A list of applications contributed by the organization."
Expand Down
15 changes: 13 additions & 2 deletions scripts/generate-index-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,22 @@ async function fetchRepoData(
app: OrgIndex['apps'][number],
): Promise<AppIndex['apps'][number]> {
try {
const repoUrl = `https://github.com/${orgId}/${app.name}`;

const { data: repoData } = await octokit.repos.get({
owner: orgId,
repo: app.name,
});

const repoUrl = `https://github.com/${orgId}/${app.name}`;
let docsUrl = app.docsUrl;
if (docsUrl === undefined) {
const { data } = await octokit.repos.getReadme({
owner: orgId,
repo: app.name,
});

docsUrl = data.html_url ?? repoUrl;
}

console.log(colours.green(`Fetched data for ${orgId}/${app.name}`));

Expand All @@ -143,7 +153,8 @@ async function fetchRepoData(
forks: repoData.forks_count,
apps: app.apps,
releases: app.releases,
tags: app.tags
tags: app.tags,
docsUrl: docsUrl,
};
} catch {
throw new Error(`Failed to fetch data for ${orgId}/${app.name}`);
Expand Down
3 changes: 3 additions & 0 deletions scripts/validate-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import Ajv, { ErrorObject } from 'ajv';
import addFormats from 'ajv-formats';
import colours from 'ansi-colors';

import orgIndexSchema from '../resources/schema.json';
Expand All @@ -22,6 +23,7 @@ function reportError(file: string, error: ErrorObject) {

async function run() {
const ajv = new Ajv();
addFormats(ajv);
const files = await readOrgIndexFiles();

const validate = ajv.compile(orgIndexSchema);
Expand All @@ -33,6 +35,7 @@ async function run() {
if (!isValid) {
validate.errors?.forEach((error) => reportError(file, error));
isError = true;
console.log(`${orgIndex} ${file}`)
}
}

Expand Down
11 changes: 11 additions & 0 deletions site/src/app/AppBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
StarIcon,
TerminalIcon,
VerifiedIcon,
BookIcon,
} from '@primer/octicons-react';

import { useState } from 'react';
Expand Down Expand Up @@ -111,6 +112,16 @@ function AppBlock({ app, setShowingAppDetails }: Props): JSX.Element {
>
Instructions <TerminalIcon size={20} />
</button>

<a
className="button bg-[#768692] text-white"
href={app.docsUrl}
title={`Open documentation for ${app.name}`}
target={'_blank'}
rel={'noopener noreferrer'}
>
Documentation <BookIcon size={20} />
</a>
</div>
<div className="flex w-full justify-between gap-3 text-xs text-gray-600">
<div className="flex items-center gap-1" title={`${app.stars} stars`}>
Expand Down
11 changes: 8 additions & 3 deletions site/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const appMetadataSchema = {
properties: {
tag: { type: 'string', description: 'Git tag of the released version.' },
name: { type: 'string', description: 'The title of the release.' },
date: { type: 'string', format: 'date', description: 'The date of publishing the release.' },
date: { type: 'string', format: 'date-time', description: 'The date of publishing the release.' },
sdk: { type: 'string', description: 'The nRF Connect SDK version the release is compatible with.' },
},
required: ['tag', 'name', 'date', 'sdk'],
Expand All @@ -120,6 +120,10 @@ export const appMetadataSchema = {
type: 'string',
description: 'The default git branch that the repository is checked out. Inferred from the repo if missing.'
},
docsUrl: {
type: 'string',
description: `The url of the addon's documentation`
}
},
additionalProperties: false,
required: ['name', 'kind', 'tags', 'releases'],
Expand Down Expand Up @@ -196,7 +200,7 @@ export const appSchema = {
properties: {
tag: { type: 'string' },
name: { type: 'string' },
date: { type: 'string', format: 'date' },
date: { type: 'string', format: 'date-time' },
sdk: { type: 'string' },
},
required: ['tag', 'name', 'date', 'sdk'],
Expand All @@ -209,7 +213,8 @@ export const appSchema = {
forks: { type: 'integer' },
defaultBranch: { type: 'string' },
lastUpdate: { type: 'string', format: 'date-time' },
apps: { type: 'string' }
apps: { type: 'string' },
docsUrl: { type: 'string' },
},
required: [
'id',
Expand Down

0 comments on commit afb6962

Please sign in to comment.