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

Add documentation button #57

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 22 additions & 2 deletions scripts/generate-index-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,36 @@ async function fetchOrgData({
}
}

async function getReadmeUrl(orgId: string, app: OrgIndex['apps'][number]): Promise<string | undefined> {
let readmeUrl: string | undefined;

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

readmeUrl = data.html_url ?? undefined;
} catch {
readmeUrl = undefined;
}

return readmeUrl;
}

async function fetchRepoData(
orgId: string,
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 ?? await getReadmeUrl(orgId, app);

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

Expand All @@ -143,7 +162,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
2 changes: 2 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 Down
14 changes: 13 additions & 1 deletion 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 @@ -101,7 +102,7 @@ function AppBlock({ app, setShowingAppDetails }: Props): JSX.Element {
const newQueryParams = new VSCodeQueryParams(app);
newQueryParams.branch = branch;
setQueryParams(newQueryParams);
}}/>
}} />

<VSCodeButton queryParams={queryParams} />

Expand All @@ -111,6 +112,17 @@ function AppBlock({ app, setShowingAppDetails }: Props): JSX.Element {
>
Instructions <TerminalIcon size={20} />
</button>

{!!app.docsUrl
&& <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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: `The url of the addon's documentation`
description: `The URL of the add-on'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
Loading