Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/repo-select
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Nov 29, 2024
2 parents f8613bb + b52f2db commit 777beb1
Show file tree
Hide file tree
Showing 29 changed files with 1,553 additions and 967 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"],
"ignoreWords": ["ubiquibot", "Supabase", "supabase", "SUPABASE", "sonarjs", "mischeck"]
"ignoreWords": ["ubiquibot", "Supabase", "supabase", "SUPABASE", "sonarjs", "mischeck", "Typebox"]
}
14 changes: 13 additions & 1 deletion .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ const config: KnipConfig = {
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["@mswjs/data", "@supabase/supabase-js", "@ubiquity-os/ubiquity-os-kernel", "ajv", "yaml", "simple-git", "@actions/core", "esbuild"],
ignoreDependencies: [
"@mswjs/data",
"@supabase/supabase-js",
"@ubiquity-os/ubiquity-os-kernel",
"ajv",
"yaml",
"simple-git",
"@actions/core",
"esbuild",
"@ubiquity-os/plugin-sdk",
"markdown-it",
"@types/markdown-it",
],
eslint: true,
};

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ The browser automatically URI encodes it:
```

###### Example from `command-start-stop/manifest.json`

## How to run

1. Clone the repository
2. Run `yarn` to install dependencies
3. OAuth: Obtain your _GitHub OAuth App_ client ID and secret from your OAuth app settings, and set the callback URL to match the one given by Supabase when enabling GitHub provider OAuth.
4. Replace the hardcoded `SUPABASE_URL` and `SUPABASE_KEY` in `build/esbuild-build.ts` with your Supabase URL and key (Optionally use `.env` and use `process.env` instead.)
5. Run `yarn start` and visit `localhost:8080` in your browser.
6. Once logged in you should see the orgs that you own.
7. Select an org > select a config (dev | prod) > select a plugin > edit/add/remove > push to GitHub.

TODO: Update readme with a better overview of the project.
5 changes: 3 additions & 2 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export const esbuildOptions: BuildOptions = {
define: createEnvDefines([], {
SUPABASE_STORAGE_KEY: generateSupabaseStorageKey(),
NODE_ENV: process.env.NODE_ENV || "development",
SUPABASE_URL: "https://wfzpewmlyiozupulbuur.supabase.co",
SUPABASE_URL: process.env.SUPABASE_URL || "https://wfzpewmlyiozupulbuur.supabase.co",
SUPABASE_ANON_KEY:
process.env.SUPABASE_ANON_KEY ||
/* cspell:disable-next-line */
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndmenBld21seWlvenVwdWxidXVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTU2NzQzMzksImV4cCI6MjAxMTI1MDMzOX0.SKIL3Q0NOBaMehH0ekFspwgcu3afp3Dl9EDzPqs1nKs",
}),
Expand Down Expand Up @@ -57,7 +58,7 @@ function createEnvDefines(environmentVariables: string[], generatedAtBuild: Reco
}

export function generateSupabaseStorageKey(): string | null {
const SUPABASE_URL = "https://wfzpewmlyiozupulbuur.supabase.co";
const SUPABASE_URL = process.env.SUPABASE_URL || "https://wfzpewmlyiozupulbuur.supabase.co";
if (!SUPABASE_URL) {
console.error("SUPABASE_URL environment variable is not set");
return null;
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
"dependencies": {
"@octokit/rest": "^21.0.2",
"@supabase/supabase-js": "^2.46.1",
"@ubiquity-os/plugin-sdk": "^1.0.11",
"@ubiquity-os/ubiquity-os-kernel": "^2.5.3",
"ajv": "^8.17.1",
"dotenv": "^16.4.4",
"markdown-it": "^14.1.0",
"yaml": "^2.6.0"
},
"devDependencies": {
Expand All @@ -50,6 +52,7 @@
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "^29.5.12",
"@types/markdown-it": "^14.1.2",
"@types/node": "20.14.5",
"cspell": "8.14.4",
"cypress": "13.6.6",
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<tbody id="manifest-gui-body"></tbody>
<tfoot
><tr
><td></td><td><button id="remove"></button><button id="add"></button></td></tr
><td></td><td><button id="reset-to-default"></button><button id="remove"></button><button id="add"></button></td></tr
></tfoot>
</table>
</section>
Expand Down
66 changes: 14 additions & 52 deletions static/main.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,39 @@
import { AuthService } from "./scripts/authentication";
import { ManifestDecoder } from "./scripts/decode-manifest";
import { ManifestFetcher } from "./scripts/fetch-manifest";
import { ManifestRenderer } from "./scripts/render-manifest";
import { OrgWithInstall } from "./types/github";
import { renderOrgPicker } from "./scripts/rendering/org-select";
import { toastNotification } from "./utils/toaster";

async function handleAuth() {
const auth = new AuthService();
await auth.renderGithubLoginButton();
const token = await auth.getGitHubAccessToken();
if (!token) {
// await auth.signInWithGithub(); force a login?
}

return auth;
}

export async function mainModule() {
const auth = await handleAuth();
const decoder = new ManifestDecoder();
const renderer = new ManifestRenderer(auth);
const search = window.location.search.substring(1);

if (search) {
const decodedManifest = await decoder.decodeManifestFromSearch(search);
return renderer.renderManifest(decodedManifest);
}
renderer.manifestGuiBody.dataset.loading = "false";

try {
/**
* "ubiquity-os", "ubiquity-os-marketplace" === dev config
* "ubiquity" === prod config
*/
const ubiquityOrgsToFetchOfficialConfigFrom = ["ubiquity-os"];
const fetcher = new ManifestFetcher(ubiquityOrgsToFetchOfficialConfigFrom, auth.octokit, decoder);
const cache = fetcher.checkManifestCache();
if (auth.isActiveSession()) {
const userOrgs = await auth.getGitHubUserOrgs();
localStorage.setItem("userOrgs", JSON.stringify(userOrgs));
const fetcher = new ManifestFetcher(ubiquityOrgsToFetchOfficialConfigFrom, auth.octokit);

const appInstallations = await auth.octokit?.apps.listInstallationsForAuthenticatedUser();
const installs = appInstallations?.data.installations;
if (auth.isActiveSession()) {
renderer.manifestGuiBody.dataset.loading = "true";
const killNotification = toastNotification("Fetching manifest data...", { type: "info", shouldAutoDismiss: true });

const orgsWithInstalls = userOrgs.map((org) => {
const orgInstall = installs?.find((install) => {
if (install.account && "login" in install.account) {
return install.account.login.toLowerCase() === org.toLowerCase();
}
return false;
});
return {
org,
install: orgInstall,
};
}) as OrgWithInstall[];
renderer.renderOrgPicker(orgsWithInstalls.map((org) => org.org));
const userOrgs = await auth.getGitHubUserOrgs();
const userOrgRepos = await auth.getGitHubUserOrgRepos(userOrgs);
localStorage.setItem("orgRepos", JSON.stringify(userOrgRepos));
renderOrgPicker(renderer, userOrgs);

if (Object.keys(cache).length === 0) {
const manifestCache = await fetcher.fetchMarketplaceManifests();
localStorage.setItem("manifestCache", JSON.stringify(manifestCache));
// this is going to extract URLs from our official config which we'll inject into `- plugin: ...`
await fetcher.fetchOfficialPluginConfig();
}
await fetcher.fetchMarketplaceManifests();
await fetcher.fetchOfficialPluginConfig();
renderer.manifestGuiBody.dataset.loading = "false";
killNotification();
} else {
renderer.renderOrgPicker([]);
renderOrgPicker(renderer, []);
}
} catch (error) {
if (error instanceof Error) {
Expand All @@ -76,10 +44,4 @@ export async function mainModule() {
}
}

mainModule()
.then(() => {
console.log("mainModule loaded");
})
.catch((error) => {
console.error(error);
});
mainModule().catch(console.error);
Loading

0 comments on commit 777beb1

Please sign in to comment.