From 13e14106b94eb30dc5271ac9cdb78df97a43dc1d Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Wed, 28 Feb 2024 15:25:02 -0800 Subject: [PATCH 1/5] Added dynamic release notes with GitHub API --- .astro/types.d.ts | 21 +++++++++++------ .env example | 2 ++ .gitignore | 3 ++- package-lock.json | 24 +++++++++++++++++++ package.json | 6 +++-- src/assets/github-mark-black.svg | 1 + src/assets/github-mark-white.svg | 1 + src/components/ReleaseNotes.astro | 28 ++++++++++++++++++++++ src/components/ReleaseVersion.astro | 14 +++++++++++ src/components/githubAPI.ts | 36 +++++++++++++++++++++++++++++ src/content/docs/index.mdx | 6 ++++- src/content/docs/releasenotes.mdx | 12 ++++++++++ 12 files changed, 143 insertions(+), 11 deletions(-) create mode 100644 .env example create mode 100644 src/assets/github-mark-black.svg create mode 100644 src/assets/github-mark-white.svg create mode 100644 src/components/ReleaseNotes.astro create mode 100644 src/components/ReleaseVersion.astro create mode 100644 src/components/githubAPI.ts create mode 100644 src/content/docs/releasenotes.mdx diff --git a/.astro/types.d.ts b/.astro/types.d.ts index 9aa22e7..a0cadf1 100644 --- a/.astro/types.d.ts +++ b/.astro/types.d.ts @@ -325,6 +325,20 @@ declare module 'astro:content' { collection: "docs"; data: InferEntrySchema<"docs"> } & { render(): Render[".mdx"] }; +"quickstart.mdx": { + id: "quickstart.mdx"; + slug: "quickstart"; + body: string; + collection: "docs"; + data: InferEntrySchema<"docs"> +} & { render(): Render[".mdx"] }; +"releasenotes.mdx": { + id: "releasenotes.mdx"; + slug: "releasenotes"; + body: string; + collection: "docs"; + data: InferEntrySchema<"docs"> +} & { render(): Render[".mdx"] }; "settings/connection.mdx": { id: "settings/connection.mdx"; slug: "settings/connection"; @@ -353,13 +367,6 @@ declare module 'astro:content' { collection: "docs"; data: InferEntrySchema<"docs"> } & { render(): Render[".mdx"] }; -"tips/quickstart.mdx": { - id: "tips/quickstart.mdx"; - slug: "tips/quickstart"; - body: string; - collection: "docs"; - data: InferEntrySchema<"docs"> -} & { render(): Render[".mdx"] }; "tips/setup.mdx": { id: "tips/setup.mdx"; slug: "tips/setup"; diff --git a/.env example b/.env example new file mode 100644 index 0000000..959836a --- /dev/null +++ b/.env example @@ -0,0 +1,2 @@ +# Github Token with `public_repo` scope https://github.com/settings/tokens +GITHUB_TOKEN= \ No newline at end of file diff --git a/.gitignore b/.gitignore index ee00f73..4efa686 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules .vscode-test/ *.vsix dist -.DS_Store \ No newline at end of file +.DS_Store +.env \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f2d1c53..fcda12a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,8 @@ "@astrojs/check": "^0.5.5", "@astrojs/starlight": "^0.19.1", "astro": "^4.3.5", + "dotenv": "^16.4.5", + "marked": "^12.0.0", "sharp": "^0.32.5", "typescript": "^5.3.3" } @@ -3132,6 +3134,17 @@ "resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz", "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==" }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dset": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/dset/-/dset-3.1.3.tgz", @@ -4351,6 +4364,17 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/marked": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.0.tgz", + "integrity": "sha512-Vkwtq9rLqXryZnWaQc86+FHLC6tr/fycMfYAhiOIXkrNmeGAyhSxjqu0Rs1i0bBqw5u0S7+lV9fdH2ZSVaoa0w==", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/mdast-util-definitions": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/mdast-util-definitions/-/mdast-util-definitions-6.0.0.tgz", diff --git a/package.json b/package.json index 0fa0921..ddcd97b 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,12 @@ "astro": "astro" }, "dependencies": { + "@astrojs/check": "^0.5.5", "@astrojs/starlight": "^0.19.1", "astro": "^4.3.5", + "dotenv": "^16.4.5", + "marked": "^12.0.0", "sharp": "^0.32.5", - "@astrojs/check": "^0.5.5", "typescript": "^5.3.3" } -} \ No newline at end of file +} diff --git a/src/assets/github-mark-black.svg b/src/assets/github-mark-black.svg new file mode 100644 index 0000000..37fa923 --- /dev/null +++ b/src/assets/github-mark-black.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/github-mark-white.svg b/src/assets/github-mark-white.svg new file mode 100644 index 0000000..d5e6491 --- /dev/null +++ b/src/assets/github-mark-white.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/ReleaseNotes.astro b/src/components/ReleaseNotes.astro new file mode 100644 index 0000000..14c32c6 --- /dev/null +++ b/src/components/ReleaseNotes.astro @@ -0,0 +1,28 @@ +--- +import { marked } from 'marked'; +import { fetchFromGitHub } from './githubAPI'; + +// Fetch the releases server-side +const releases = await fetchFromGitHub('releases'); + +// Check if releases is defined before trying to parse +let releasesBodyHtml = []; +if (releases) { + releasesBodyHtml = releases.map((release : any) => { + return { + name: release.name, + body: marked(release.body) + }; + }); +} +--- + +{releasesBodyHtml.map((release: any) => ( +
+

{release.name}

+
+
+
+
+
+))} \ No newline at end of file diff --git a/src/components/ReleaseVersion.astro b/src/components/ReleaseVersion.astro new file mode 100644 index 0000000..7510857 --- /dev/null +++ b/src/components/ReleaseVersion.astro @@ -0,0 +1,14 @@ +--- +import { fetchFromGitHub } from './githubAPI'; + +// Fetch the latest release server-side +const release = await fetchFromGitHub('releases/latest'); + +// Extract the version number +let version = ''; +if (release) { + version = release.tag_name; +} +--- + +{version} \ No newline at end of file diff --git a/src/components/githubAPI.ts b/src/components/githubAPI.ts new file mode 100644 index 0000000..e74032d --- /dev/null +++ b/src/components/githubAPI.ts @@ -0,0 +1,36 @@ +import dotenv from 'dotenv'; +dotenv.config(); + +// GitHub repository details +const baseURL = 'https://api.github.com/repos'; +const owner = 'codefori'; +const repo = 'vscode-ibmi'; +const token = process.env.GITHUB_TOKEN || ''; + +async function fetchFromGitHub(endpoint: string) { + console.log(token); + if (!token) { + console.error('No GitHub token provided. Setup .env file.'); + return null; + } + + const url = `${baseURL}/${owner}/${repo}/${endpoint}`; + const headers = { + 'Authorization': `token ${token}`, + 'Accept': 'application/vnd.github.v3+json' + }; + try { + const response = await fetch(url, { headers }); + if (!response.ok) { + console.error(`HTTP error! status: ${response.status}`); + return null; + } + const data = await response.json(); + return data; + } catch (error) { + console.error(`Failed to fetch from GitHub: ${error}`); + return null; + } +} + +export { fetchFromGitHub }; \ No newline at end of file diff --git a/src/content/docs/index.mdx b/src/content/docs/index.mdx index abfae21..c77b20e 100644 --- a/src/content/docs/index.mdx +++ b/src/content/docs/index.mdx @@ -3,13 +3,17 @@ title: Code for IBM i --- import { CardGrid, Card, Icon } from '@astrojs/starlight/components'; +import ReleaseVersion from './src/components/ReleaseVersion.astro'; -## IBM i development extension for VS Code +## IBM i development extension for VS Code Maintain and compile your RPGLE, CL, COBOL, C/CPP on the IBM i right from Visual Studio Code. ![intro_01.png](../../assets/intro_01.png) +### What's New in Code for IBM i +See our [Release Notes](./releasenotes/) for the latest updates and features. + ## Requirements - SSH Daemon must be started on IBM i. diff --git a/src/content/docs/releasenotes.mdx b/src/content/docs/releasenotes.mdx new file mode 100644 index 0000000..f6da80b --- /dev/null +++ b/src/content/docs/releasenotes.mdx @@ -0,0 +1,12 @@ +--- +title: Release notes +tableOfContents: false +hero: + image: + dark: ../../assets/github-mark-white.svg + light: ../../assets/github-mark-black.svg +--- + +import ReleaseNotes from './src/components/ReleaseNotes.astro'; + + \ No newline at end of file From 0fb9fdd6014213a0dbec4801898410215bde10de Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Thu, 29 Feb 2024 08:05:45 -0800 Subject: [PATCH 2/5] Added limiter to fetchFromGitHub function and add link card to release notes --- src/components/githubAPI.ts | 17 +++++++++++++---- src/content/docs/releasenotes.mdx | 7 +++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/githubAPI.ts b/src/components/githubAPI.ts index e74032d..8bb90cb 100644 --- a/src/components/githubAPI.ts +++ b/src/components/githubAPI.ts @@ -7,20 +7,29 @@ const owner = 'codefori'; const repo = 'vscode-ibmi'; const token = process.env.GITHUB_TOKEN || ''; -async function fetchFromGitHub(endpoint: string) { - console.log(token); +/** + * Fetch data from GitHub API. + * + * @param {string} endpoint - The API endpoint to fetch from. + * @param {number} limit - The maximum number of items to fetch (default is 5). + * @return {Promise} The data from the API, or null if an error occurred. + */ +async function fetchFromGitHub(endpoint: string, limit: number = 5) { + if (!token) { console.error('No GitHub token provided. Setup .env file.'); return null; } - const url = `${baseURL}/${owner}/${repo}/${endpoint}`; + const url = new URL(`${baseURL}/${owner}/${repo}/${endpoint}`); + url.searchParams.append('per_page', String(limit)); + const headers = { 'Authorization': `token ${token}`, 'Accept': 'application/vnd.github.v3+json' }; try { - const response = await fetch(url, { headers }); + const response = await fetch(url.toString(), { headers }); if (!response.ok) { console.error(`HTTP error! status: ${response.status}`); return null; diff --git a/src/content/docs/releasenotes.mdx b/src/content/docs/releasenotes.mdx index f6da80b..40408c6 100644 --- a/src/content/docs/releasenotes.mdx +++ b/src/content/docs/releasenotes.mdx @@ -1,5 +1,5 @@ --- -title: Release notes +title: Release Notes tableOfContents: false hero: image: @@ -8,5 +8,8 @@ hero: --- import ReleaseNotes from './src/components/ReleaseNotes.astro'; +import { LinkCard } from '@astrojs/starlight/components'; - \ No newline at end of file + + + \ No newline at end of file From 3a99851a5ab438e2831d32673e37f43612d570aa Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Thu, 29 Feb 2024 08:12:44 -0800 Subject: [PATCH 3/5] Update import paths for ReleaseVersion and ReleaseNotes components --- src/content/docs/index.mdx | 2 +- src/content/docs/releasenotes.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/index.mdx b/src/content/docs/index.mdx index c77b20e..b8fa839 100644 --- a/src/content/docs/index.mdx +++ b/src/content/docs/index.mdx @@ -3,7 +3,7 @@ title: Code for IBM i --- import { CardGrid, Card, Icon } from '@astrojs/starlight/components'; -import ReleaseVersion from './src/components/ReleaseVersion.astro'; +import ReleaseVersion from '../../components/ReleaseVersion.astro'; ## IBM i development extension for VS Code diff --git a/src/content/docs/releasenotes.mdx b/src/content/docs/releasenotes.mdx index 40408c6..24022d2 100644 --- a/src/content/docs/releasenotes.mdx +++ b/src/content/docs/releasenotes.mdx @@ -7,7 +7,7 @@ hero: light: ../../assets/github-mark-black.svg --- -import ReleaseNotes from './src/components/ReleaseNotes.astro'; +import ReleaseNotes from '../../components/ReleaseNotes.astro'; import { LinkCard } from '@astrojs/starlight/components'; From c5b701929e08065ae4b8701ef84f308caf7c0c8d Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Thu, 29 Feb 2024 08:20:47 -0800 Subject: [PATCH 4/5] Update GitHub token variable name to API_ because GITHUB_ is restricted apparently --- .env example | 2 +- src/components/githubAPI.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env example b/.env example index 959836a..49aee05 100644 --- a/.env example +++ b/.env example @@ -1,2 +1,2 @@ # Github Token with `public_repo` scope https://github.com/settings/tokens -GITHUB_TOKEN= \ No newline at end of file +API_GITHUB_TOKEN= \ No newline at end of file diff --git a/src/components/githubAPI.ts b/src/components/githubAPI.ts index 8bb90cb..7e9549b 100644 --- a/src/components/githubAPI.ts +++ b/src/components/githubAPI.ts @@ -5,7 +5,7 @@ dotenv.config(); const baseURL = 'https://api.github.com/repos'; const owner = 'codefori'; const repo = 'vscode-ibmi'; -const token = process.env.GITHUB_TOKEN || ''; +const token = process.env.API_GITHUB_TOKEN || ''; /** * Fetch data from GitHub API. From 6a0728869674e81e89a5e8b94673c2d461d63ed6 Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Thu, 29 Feb 2024 08:26:22 -0800 Subject: [PATCH 5/5] Add API_GITHUB_TOKEN environment variable to Workflow Build Action --- .github/workflows/astro.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/astro.yml b/.github/workflows/astro.yml index 4dbb0fc..6120513 100644 --- a/.github/workflows/astro.yml +++ b/.github/workflows/astro.yml @@ -65,6 +65,8 @@ jobs: run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} working-directory: ${{ env.BUILD_PATH }} - name: Build with Astro + env: + API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }} run: | ${{ steps.detect-package-manager.outputs.runner }} astro build \ --site "${{ steps.pages.outputs.origin }}" \