Skip to content

Commit

Permalink
Merge pull request #10 from FernandVEYRIER/feat/config-generation
Browse files Browse the repository at this point in the history
feat: better onboarding process
  • Loading branch information
0x4007 authored Mar 12, 2024
2 parents 899bd93 + 2cc6281 commit 1579b6e
Show file tree
Hide file tree
Showing 19 changed files with 744 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Run Cypress testing suite
on:
workflow_dispatch:
pull_request:
pull_request_target:
types: [opened, synchronize]

jobs:
Expand All @@ -21,6 +21,7 @@ jobs:
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FRONTEND_URL: "http://localhost:8080"
SUPABASE_URL: "https://wfzpewmlyiozupulbuur.supabase.co"
SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndmenBld21seWlvenVwdWxidXVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTU2NzQzMzksImV4cCI6MjAxMTI1MDMzOX0.SKIL3Q0NOBaMehH0ekFspwgcu3afp3Dl9EDzPqs1nKs
- uses: actions/upload-artifact@v4
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Knip

on:
pull_request:
pull_request_target:
types: [ opened, synchronize ]

permissions: write-all

Expand All @@ -27,4 +28,4 @@ jobs:
comment_id: ${{ github.workflow }}-reporter
command_script_name: knip-ci
annotations: true
ignore_results: false
ignore_results: false
27 changes: 15 additions & 12 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-expect-error - Could not find a declaration file for module
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
import { execSync } from "child_process";
import { config } from "dotenv";
import esbuild from "esbuild";
import * as dotenv from "dotenv";
import extraRpcs from "../lib/chainlist/constants/extraRpcs";

const typescriptEntries = ["static/scripts/onboarding/onboarding.ts"];
const cssEntries = ["static/styles/rewards/rewards.css", "static/styles/audit-report/audit.css", "static/styles/onboarding/onboarding.css"];
export const entries = [...typescriptEntries, ...cssEntries];
Expand Down Expand Up @@ -29,7 +30,10 @@ export const esBuildContext: esbuild.BuildOptions = {
".svg": "dataurl",
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { allNetworkUrls }),
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY", "FRONTEND_URL"], {
extraRpcs: allNetworkUrls,
commitHash: execSync(`git rev-parse --short HEAD`).toString().trim(),
}),
};

esbuild
Expand All @@ -42,22 +46,21 @@ esbuild
process.exit(1);
});

function createEnvDefines(envVarNames: string[], extras: Record<string, unknown>): Record<string, string> {
function createEnvDefines(environmentVariables: string[], generatedAtBuild: Record<string, unknown>): Record<string, string> {
const defines: Record<string, string> = {};
dotenv.config();
for (const name of envVarNames) {
config();
for (const name of environmentVariables) {
const envVar = process.env[name];
if (envVar !== undefined) {
defines[name] = JSON.stringify(envVar);
} else {
throw new Error(`Missing environment variable: ${name}`);
}
}
for (const key in extras) {
if (Object.prototype.hasOwnProperty.call(extras, key)) {
defines[key] = JSON.stringify(extras[key]);
Object.keys(generatedAtBuild).forEach((key) => {
if (Object.prototype.hasOwnProperty.call(generatedAtBuild, key)) {
defines[key] = JSON.stringify(generatedAtBuild[key]);
}
}
defines["extraRpcs"] = JSON.stringify(allNetworkUrls);
});
return defines;
}
49 changes: 39 additions & 10 deletions cypress/e2e/main.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { OAuthToken } from "../../static/scripts/onboarding/github-login-button";

describe("Homepage tests", () => {
const ORG_NAME = "Ubiquity";
let loginToken: OAuthToken;

beforeEach(() => {
cy.fixture("get-user.json").then((file) => {
Expand Down Expand Up @@ -37,6 +40,29 @@ describe("Homepage tests", () => {
req.reply(file);
}).as("githubPutConfigFile");
});
cy.fixture("get-orgs.json").then((file) => {
cy.intercept("GET", `https://api.github.com/user/orgs**`, (req) => {
req.reply(file);
}).as("githubGetUserOrgs");
});
cy.fixture("get-org-installations.json").then((file) => {
cy.intercept("GET", `https://api.github.com/orgs/${ORG_NAME.toLowerCase()}/installations**`, (req) => {
req.reply(file);
}).as("githubGetOrgInstallations");
});
cy.fixture("get-search.json").then((file) => {
cy.intercept("GET", `https://api.github.com/search/repositories**`, (req) => {
req.reply(file);
}).as("githubSearch");
});
cy.fixture("put-config.json").then((file) => {
cy.intercept("PUT", `https://api.github.com/repos/${ORG_NAME.toLowerCase()}/ubiquibot-config/contents/.github**`, (req) => {
req.reply(file);
}).as("githubPutContents");
});
cy.fixture("user-token.json").then((content) => {
loginToken = content;
});
});

it("Console is cleared of errors and warnings", () => {
Expand All @@ -49,20 +75,23 @@ describe("Homepage tests", () => {
cy.get("body").should("exist");
});

it("Create onboarding repository", () => {
it.only("Create onboarding repository", () => {
cy.visit("/");
cy.intercept("https://github.com/login/oauth/authorize**", (req) => {
req.reply({
statusCode: 200,
});
// Simulate login token
window.localStorage.setItem("sb-wfzpewmlyiozupulbuur-auth-token", JSON.stringify(loginToken));
}).as("githubLogin");
cy.get("#github-login-button").click();
cy.visit("/");
cy.wait("@githubGetUserOrgs");
cy.get("#setBtn").click();
cy.log("Display warning on empty WALLET_PRIVATE_KEY");
cy.get(":nth-child(2) > .status-log.warn").contains(/.+/);
cy.get("#walletPrivateKey").type("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
cy.get("#setBtn").click();
cy.log("Display warning on empty ORG_NAME");
cy.get(":nth-child(4) > .status-log.warn").contains(/.+/);
cy.get("#orgName").type(ORG_NAME);
cy.get("#setBtn").click();
cy.log("Display warning on empty GITHUB_PAT");
cy.get(":nth-child(3) > .status-log.warn").contains(/.+/);
cy.get("#githubPat").type("ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
cy.get("#walletPrivateKey").type("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
cy.get("#orgName").select("ubiquity");
cy.get("#setBtn").click();
cy.get("#outKey").then((e) => {
expect(e.val()).not.to.be.empty;
Expand Down
84 changes: 84 additions & 0 deletions cypress/fixtures/get-org-installations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"total_count": 1,
"installations": [
{
"id": 47252474,
"account": {
"login": "ubiquity",
"id": 159901852,
"node_id": "O_kgDOCYfonA",
"avatar_url": "https://avatars.githubusercontent.com/u/159901852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ubiquity",
"html_url": "https://github.com/ubiquity",
"followers_url": "https://api.github.com/users/ubiquity/followers",
"following_url": "https://api.github.com/users/ubiquity/following{/other_user}",
"gists_url": "https://api.github.com/users/ubiquity/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ubiquity/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ubiquity/subscriptions",
"organizations_url": "https://api.github.com/users/ubiquity/orgs",
"repos_url": "https://api.github.com/users/ubiquity/repos",
"events_url": "https://api.github.com/users/ubiquity/events{/privacy}",
"received_events_url": "https://api.github.com/users/ubiquity/received_events",
"type": "Organization",
"site_admin": false
},
"repository_selection": "selected",
"access_tokens_url": "https://api.github.com/app/installations/47252474/access_tokens",
"repositories_url": "https://api.github.com/installation/repositories",
"html_url": "https://github.com/organizations/ubiquity/settings/installations/47252474",
"app_id": 236521,
"app_slug": "ubiquibot",
"target_id": 159901852,
"target_type": "Organization",
"permissions": {
"issues": "write",
"actions": "write",
"members": "read",
"contents": "write",
"metadata": "read",
"pull_requests": "write"
},
"events": [
"commit_comment",
"create",
"delete",
"fork",
"gollum",
"issues",
"issue_comment",
"label",
"member",
"membership",
"merge_queue_entry",
"milestone",
"organization",
"public",
"pull_request",
"pull_request_review",
"pull_request_review_comment",
"pull_request_review_thread",
"push",
"release",
"repository",
"repository_dispatch",
"star",
"team",
"team_add",
"watch",
"workflow_dispatch",
"workflow_job",
"workflow_run"
],
"created_at": "2024-02-13T19:37:30.000+09:00",
"updated_at": "2024-03-11T20:40:33.000+09:00",
"single_file_name": null,
"has_multiple_single_files": false,
"single_file_paths": [

],
"suspended_by": null,
"suspended_at": null
}
]
}
30 changes: 30 additions & 0 deletions cypress/fixtures/get-orgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"login": "ubiquity2",
"id": 76412718,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc2NDEyNzE4",
"url": "https://api.github.com/orgs/ubiquity2",
"repos_url": "https://api.github.com/orgs/ubiquity2/repos",
"events_url": "https://api.github.com/orgs/ubiquity2/events",
"hooks_url": "https://api.github.com/orgs/ubiquity2/hooks",
"issues_url": "https://api.github.com/orgs/ubiquity2/issues",
"members_url": "https://api.github.com/orgs/ubiquity2/members{/member}",
"public_members_url": "https://api.github.com/orgs/ubiquity2/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/76412717?v=4",
"description": "The Metaverse Bank 2."
},
{
"login": "ubiquity",
"id": 76412717,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc2NDEyNzE3",
"url": "https://api.github.com/orgs/ubiquity",
"repos_url": "https://api.github.com/orgs/ubiquity/repos",
"events_url": "https://api.github.com/orgs/ubiquity/events",
"hooks_url": "https://api.github.com/orgs/ubiquity/hooks",
"issues_url": "https://api.github.com/orgs/ubiquity/issues",
"members_url": "https://api.github.com/orgs/ubiquity/members{/member}",
"public_members_url": "https://api.github.com/orgs/ubiquity/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/76412717?v=4",
"description": "The Metaverse Bank."
}
]
116 changes: 116 additions & 0 deletions cypress/fixtures/get-search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"total_count": 1,
"incomplete_results": false,
"items": [
{
"id": 770341621,
"node_id": "R_kgDOLep69Q",
"name": "ubiquibot-config",
"full_name": "ubiquity/ubiquibot-config",
"private": true,
"owner": {
"login": "ubiquity",
"id": 159901852,
"node_id": "O_kgDOCYfonA",
"avatar_url": "https://avatars.githubusercontent.com/u/159901852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ubiquity",
"html_url": "https://github.com/ubiquity",
"followers_url": "https://api.github.com/users/ubiquity/followers",
"following_url": "https://api.github.com/users/ubiquity/following{/other_user}",
"gists_url": "https://api.github.com/users/ubiquity/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ubiquity/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ubiquity/subscriptions",
"organizations_url": "https://api.github.com/users/ubiquity/orgs",
"repos_url": "https://api.github.com/users/ubiquity/repos",
"events_url": "https://api.github.com/users/ubiquity/events{/privacy}",
"received_events_url": "https://api.github.com/users/ubiquity/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/ubiquity/ubiquibot-config",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/ubiquity/ubiquibot-config",
"forks_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/forks",
"keys_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/teams",
"hooks_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/hooks",
"issue_events_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/issues/events{/number}",
"events_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/events",
"assignees_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/assignees{/user}",
"branches_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/branches{/branch}",
"tags_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/tags",
"blobs_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/statuses/{sha}",
"languages_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/languages",
"stargazers_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/stargazers",
"contributors_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/contributors",
"subscribers_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/subscribers",
"subscription_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/subscription",
"commits_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/contents/{+path}",
"compare_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/merges",
"archive_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/downloads",
"issues_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/issues{/number}",
"pulls_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/pulls{/number}",
"milestones_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/milestones{/number}",
"notifications_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/labels{/name}",
"releases_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/releases{/id}",
"deployments_url": "https://api.github.com/repos/ubiquity/ubiquibot-config/deployments",
"created_at": "2024-03-11T11:39:17Z",
"updated_at": "2024-03-11T11:39:17Z",
"pushed_at": "2024-03-11T11:39:18Z",
"git_url": "git://github.com/ubiquity/ubiquibot-config.git",
"ssh_url": "git@github.com:ubiquity/ubiquibot-config.git",
"clone_url": "https://github.com/ubiquity/ubiquibot-config.git",
"svn_url": "https://github.com/ubiquity/ubiquibot-config",
"homepage": null,
"size": 2,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [

],
"visibility": "private",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"score": 1.0
}
]
}
Loading

0 comments on commit 1579b6e

Please sign in to comment.