diff --git a/.gitattributes b/.gitattributes index af3ad12..50a89ee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ -/.yarn/** linguist-vendored -/.yarn/releases/* binary -/.yarn/plugins/**/* binary -/.pnp.* binary linguist-generated +/.yarn/** linguist-vendored +/.yarn/releases/* binary +/.yarn/plugins/**/* binary +/.pnp.* binary linguist-generated +"*seeds.sql" filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d40106a..6bc39b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,9 +16,9 @@ jobs: - name: Setup BEAM uses: erlef/setup-beam@v1 with: - otp-version: "26.0.2" - gleam-version: "1.2.1" - rebar3-version: "3" + otp-version: '26.0.2' + gleam-version: '1.2.1' + rebar3-version: '3' # elixir-version: "1.15.4" - name: Download gleam dependencies run: gleam deps download @@ -33,22 +33,39 @@ jobs: backend: name: Backend tests runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: gloogle + POSTGRES_USER: gloogle + options: >- + --health-cmd pg_isready --health-interval 10s --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 steps: - name: Checkout sources uses: actions/checkout@v3 - name: Setup BEAM uses: erlef/setup-beam@v1 with: - otp-version: "26.0.2" - gleam-version: "1.2.1" - rebar3-version: "3" - # elixir-version: "1.15.4" + otp-version: '26.0.2' + gleam-version: '1.2.1' + rebar3-version: '3' - name: Download gleam dependencies run: gleam deps download working-directory: apps/backend + - name: Populate DB + run: psql -U gloogle -h postgres < db/seeds.sql + working-directory: apps/backend + env: + PGPASSWORD: gloogle - name: Run gleam test run: gleam test working-directory: apps/backend + env: + POSTGRES_HOST: postgres - name: Check gleam format run: gleam format --check src test working-directory: apps/backend diff --git a/README.md b/README.md index a4e9d68..cfba08f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,34 @@ Some features are already implemented, and some others are still on the roadmap! +## Getting Started + +```sh +# Initialise the DB. +yarn backend:db:init +# Reset the DB when you need. +yarn backend:db:reset +``` + +```toml +# apps/backend/.mise.local.toml +# Used in env variables mainly. + +[env] +# Default server options. +PORT = 3000 +LOG_LEVEL = "DEBUG" + +# Local database. +DATABASE_URL = "postgres://gloogle:gloogle@localhost:5432/gloogle?sslmode=disable" + +# Used to access hex API. +HEX_API_KEY = "xxxxx" + +# Used to crawl starsgazers. +GITHUB_TOKEN = "xxxxx" +``` + ## Contributing If Gloogle please you, you can also contribute! Pull Requests are welcome! diff --git a/apps/backend/db/seeds.sql b/apps/backend/db/seeds.sql new file mode 100644 index 0000000..f70d7cd --- /dev/null +++ b/apps/backend/db/seeds.sql @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cfe79f71f428399b97e41b613ca89ff448d27ee12a4594c278f777c6383480ec +size 142547153 diff --git a/apps/backend/deno.jsonc b/apps/backend/deno.jsonc deleted file mode 100644 index 58b616a..0000000 --- a/apps/backend/deno.jsonc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "tasks": { - "db:init": "deno run --allow-run --allow-write --allow-read scripts/database/init.ts", - "db:drop": "deno run --allow-run --allow-write --allow-read scripts/database/drop.ts", - "db:reset": "deno run --allow-run --allow-write --allow-read scripts/database/reset.ts" - } -} diff --git a/apps/backend/deno.lock b/apps/backend/deno.lock deleted file mode 100644 index 46195ee..0000000 --- a/apps/backend/deno.lock +++ /dev/null @@ -1,87 +0,0 @@ -{ - "version": "3", - "remote": { - "https://deno.land/std@0.222.1/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834", - "https://deno.land/std@0.222.1/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917", - "https://deno.land/std@0.222.1/dotenv/mod.ts": "0180eaeedaaf88647318811cdaa418cc64dc51fb08354f91f5f480d0a1309f7d", - "https://deno.land/std@0.222.1/dotenv/parse.ts": "09977ff88dfd1f24f9973a338f0f91bbdb9307eb5ff6085446e7c423e4c7ba0c", - "https://deno.land/std@0.222.1/dotenv/stringify.ts": "275da322c409170160440836342eaa7cf012a1d11a7e700d8ca4e7f2f8aa4615", - "https://deno.land/std@0.222.1/path/_common/assert_path.ts": "dbdd757a465b690b2cc72fc5fb7698c51507dec6bfafce4ca500c46b76ff7bd8", - "https://deno.land/std@0.222.1/path/_common/basename.ts": "569744855bc8445f3a56087fd2aed56bdad39da971a8d92b138c9913aecc5fa2", - "https://deno.land/std@0.222.1/path/_common/common.ts": "ef73c2860694775fe8ffcbcdd387f9f97c7a656febf0daa8c73b56f4d8a7bd4c", - "https://deno.land/std@0.222.1/path/_common/constants.ts": "dc5f8057159f4b48cd304eb3027e42f1148cf4df1fb4240774d3492b5d12ac0c", - "https://deno.land/std@0.222.1/path/_common/dirname.ts": "684df4aa71a04bbcc346c692c8485594fc8a90b9408dfbc26ff32cf3e0c98cc8", - "https://deno.land/std@0.222.1/path/_common/format.ts": "92500e91ea5de21c97f5fe91e178bae62af524b72d5fcd246d6d60ae4bcada8b", - "https://deno.land/std@0.222.1/path/_common/from_file_url.ts": "d672bdeebc11bf80e99bf266f886c70963107bdd31134c4e249eef51133ceccf", - "https://deno.land/std@0.222.1/path/_common/glob_to_reg_exp.ts": "6cac16d5c2dc23af7d66348a7ce430e5de4e70b0eede074bdbcf4903f4374d8d", - "https://deno.land/std@0.222.1/path/_common/normalize.ts": "684df4aa71a04bbcc346c692c8485594fc8a90b9408dfbc26ff32cf3e0c98cc8", - "https://deno.land/std@0.222.1/path/_common/normalize_string.ts": "33edef773c2a8e242761f731adeb2bd6d683e9c69e4e3d0092985bede74f4ac3", - "https://deno.land/std@0.222.1/path/_common/relative.ts": "faa2753d9b32320ed4ada0733261e3357c186e5705678d9dd08b97527deae607", - "https://deno.land/std@0.222.1/path/_common/strip_trailing_separators.ts": "7024a93447efcdcfeaa9339a98fa63ef9d53de363f1fbe9858970f1bba02655a", - "https://deno.land/std@0.222.1/path/_common/to_file_url.ts": "7f76adbc83ece1bba173e6e98a27c647712cab773d3f8cbe0398b74afc817883", - "https://deno.land/std@0.222.1/path/_interface.ts": "8dfeb930ca4a772c458a8c7bbe1e33216fe91c253411338ad80c5b6fa93ddba0", - "https://deno.land/std@0.222.1/path/_os.ts": "8fb9b90fb6b753bd8c77cfd8a33c2ff6c5f5bc185f50de8ca4ac6a05710b2c15", - "https://deno.land/std@0.222.1/path/basename.ts": "7ee495c2d1ee516ffff48fb9a93267ba928b5a3486b550be73071bc14f8cc63e", - "https://deno.land/std@0.222.1/path/common.ts": "03e52e22882402c986fe97ca3b5bb4263c2aa811c515ce84584b23bac4cc2643", - "https://deno.land/std@0.222.1/path/constants.ts": "0c206169ca104938ede9da48ac952de288f23343304a1c3cb6ec7625e7325f36", - "https://deno.land/std@0.222.1/path/dirname.ts": "85bd955bf31d62c9aafdd7ff561c4b5fb587d11a9a5a45e2b01aedffa4238a7c", - "https://deno.land/std@0.222.1/path/extname.ts": "593303db8ae8c865cbd9ceec6e55d4b9ac5410c1e276bfd3131916591b954441", - "https://deno.land/std@0.222.1/path/format.ts": "6ce1779b0980296cf2bc20d66436b12792102b831fd281ab9eb08fa8a3e6f6ac", - "https://deno.land/std@0.222.1/path/from_file_url.ts": "911833ae4fd10a1c84f6271f36151ab785955849117dc48c6e43b929504ee069", - "https://deno.land/std@0.222.1/path/glob_to_regexp.ts": "7f30f0a21439cadfdae1be1bf370880b415e676097fda584a63ce319053b5972", - "https://deno.land/std@0.222.1/path/is_absolute.ts": "4791afc8bfd0c87f0526eaa616b0d16e7b3ab6a65b62942e50eac68de4ef67d7", - "https://deno.land/std@0.222.1/path/is_glob.ts": "a65f6195d3058c3050ab905705891b412ff942a292bcbaa1a807a74439a14141", - "https://deno.land/std@0.222.1/path/join.ts": "ae2ec5ca44c7e84a235fd532e4a0116bfb1f2368b394db1c4fb75e3c0f26a33a", - "https://deno.land/std@0.222.1/path/join_globs.ts": "5b3bf248b93247194f94fa6947b612ab9d3abd571ca8386cf7789038545e54a0", - "https://deno.land/std@0.222.1/path/mod.ts": "2821a1bb3a4148a0ffe79c92aa41aa9319fef73c6d6f5178f52b2c720d3eb02d", - "https://deno.land/std@0.222.1/path/normalize.ts": "4155743ccceeed319b350c1e62e931600272fad8ad00c417b91df093867a8352", - "https://deno.land/std@0.222.1/path/normalize_glob.ts": "cc89a77a7d3b1d01053b9dcd59462b75482b11e9068ae6c754b5cf5d794b374f", - "https://deno.land/std@0.222.1/path/parse.ts": "3e172974e3c71025f5fbd2bd9db4307acb9cc2de14cf6f4464bf40957663cabe", - "https://deno.land/std@0.222.1/path/posix/_util.ts": "1e3937da30f080bfc99fe45d7ed23c47dd8585c5e473b2d771380d3a6937cf9d", - "https://deno.land/std@0.222.1/path/posix/basename.ts": "d2fa5fbbb1c5a3ab8b9326458a8d4ceac77580961b3739cd5bfd1d3541a3e5f0", - "https://deno.land/std@0.222.1/path/posix/common.ts": "26f60ccc8b2cac3e1613000c23ac5a7d392715d479e5be413473a37903a2b5d4", - "https://deno.land/std@0.222.1/path/posix/constants.ts": "93481efb98cdffa4c719c22a0182b994e5a6aed3047e1962f6c2c75b7592bef1", - "https://deno.land/std@0.222.1/path/posix/dirname.ts": "76cd348ffe92345711409f88d4d8561d8645353ac215c8e9c80140069bf42f00", - "https://deno.land/std@0.222.1/path/posix/extname.ts": "e398c1d9d1908d3756a7ed94199fcd169e79466dd88feffd2f47ce0abf9d61d2", - "https://deno.land/std@0.222.1/path/posix/format.ts": "185e9ee2091a42dd39e2a3b8e4925370ee8407572cee1ae52838aed96310c5c1", - "https://deno.land/std@0.222.1/path/posix/from_file_url.ts": "951aee3a2c46fd0ed488899d024c6352b59154c70552e90885ed0c2ab699bc40", - "https://deno.land/std@0.222.1/path/posix/glob_to_regexp.ts": "76f012fcdb22c04b633f536c0b9644d100861bea36e9da56a94b9c589a742e8f", - "https://deno.land/std@0.222.1/path/posix/is_absolute.ts": "cebe561ad0ae294f0ce0365a1879dcfca8abd872821519b4fcc8d8967f888ede", - "https://deno.land/std@0.222.1/path/posix/is_glob.ts": "8a8b08c08bf731acf2c1232218f1f45a11131bc01de81e5f803450a5914434b9", - "https://deno.land/std@0.222.1/path/posix/join.ts": "7fc2cb3716aa1b863e990baf30b101d768db479e70b7313b4866a088db016f63", - "https://deno.land/std@0.222.1/path/posix/join_globs.ts": "a9475b44645feddceb484ee0498e456f4add112e181cb94042cdc6d47d1cdd25", - "https://deno.land/std@0.222.1/path/posix/mod.ts": "2301fc1c54a28b349e20656f68a85f75befa0ee9b6cd75bfac3da5aca9c3f604", - "https://deno.land/std@0.222.1/path/posix/normalize.ts": "baeb49816a8299f90a0237d214cef46f00ba3e95c0d2ceb74205a6a584b58a91", - "https://deno.land/std@0.222.1/path/posix/normalize_glob.ts": "9c87a829b6c0f445d03b3ecadc14492e2864c3ebb966f4cea41e98326e4435c6", - "https://deno.land/std@0.222.1/path/posix/parse.ts": "0b1fc4cb890dbb699ec1d2c232d274843b4a7142e1ad976b69fe51c954eb6080", - "https://deno.land/std@0.222.1/path/posix/relative.ts": "3907d6eda41f0ff723d336125a1ad4349112cd4d48f693859980314d5b9da31c", - "https://deno.land/std@0.222.1/path/posix/resolve.ts": "08b699cfeee10cb6857ccab38fa4b2ec703b0ea33e8e69964f29d02a2d5257cf", - "https://deno.land/std@0.222.1/path/posix/to_file_url.ts": "7aa752ba66a35049e0e4a4be5a0a31ac6b645257d2e031142abb1854de250aaf", - "https://deno.land/std@0.222.1/path/posix/to_namespaced_path.ts": "28b216b3c76f892a4dca9734ff1cc0045d135532bfd9c435ae4858bfa5a2ebf0", - "https://deno.land/std@0.222.1/path/relative.ts": "ab739d727180ed8727e34ed71d976912461d98e2b76de3d3de834c1066667add", - "https://deno.land/std@0.222.1/path/resolve.ts": "a6f977bdb4272e79d8d0ed4333e3d71367cc3926acf15ac271f1d059c8494d8d", - "https://deno.land/std@0.222.1/path/to_file_url.ts": "88f049b769bce411e2d2db5bd9e6fd9a185a5fbd6b9f5ad8f52bef517c4ece1b", - "https://deno.land/std@0.222.1/path/to_namespaced_path.ts": "b706a4103b104cfadc09600a5f838c2ba94dbcdb642344557122dda444526e40", - "https://deno.land/std@0.222.1/path/windows/_util.ts": "d5f47363e5293fced22c984550d5e70e98e266cc3f31769e1710511803d04808", - "https://deno.land/std@0.222.1/path/windows/basename.ts": "6bbc57bac9df2cec43288c8c5334919418d784243a00bc10de67d392ab36d660", - "https://deno.land/std@0.222.1/path/windows/common.ts": "26f60ccc8b2cac3e1613000c23ac5a7d392715d479e5be413473a37903a2b5d4", - "https://deno.land/std@0.222.1/path/windows/constants.ts": "5afaac0a1f67b68b0a380a4ef391bf59feb55856aa8c60dfc01bd3b6abb813f5", - "https://deno.land/std@0.222.1/path/windows/dirname.ts": "33e421be5a5558a1346a48e74c330b8e560be7424ed7684ea03c12c21b627bc9", - "https://deno.land/std@0.222.1/path/windows/extname.ts": "165a61b00d781257fda1e9606a48c78b06815385e7d703232548dbfc95346bef", - "https://deno.land/std@0.222.1/path/windows/format.ts": "bbb5ecf379305b472b1082cd2fdc010e44a0020030414974d6029be9ad52aeb6", - "https://deno.land/std@0.222.1/path/windows/from_file_url.ts": "ced2d587b6dff18f963f269d745c4a599cf82b0c4007356bd957cb4cb52efc01", - "https://deno.land/std@0.222.1/path/windows/glob_to_regexp.ts": "e45f1f89bf3fc36f94ab7b3b9d0026729829fabc486c77f414caebef3b7304f8", - "https://deno.land/std@0.222.1/path/windows/is_absolute.ts": "4a8f6853f8598cf91a835f41abed42112cebab09478b072e4beb00ec81f8ca8a", - "https://deno.land/std@0.222.1/path/windows/is_glob.ts": "8a8b08c08bf731acf2c1232218f1f45a11131bc01de81e5f803450a5914434b9", - "https://deno.land/std@0.222.1/path/windows/join.ts": "8d03530ab89195185103b7da9dfc6327af13eabdcd44c7c63e42e27808f50ecf", - "https://deno.land/std@0.222.1/path/windows/join_globs.ts": "a9475b44645feddceb484ee0498e456f4add112e181cb94042cdc6d47d1cdd25", - "https://deno.land/std@0.222.1/path/windows/mod.ts": "2301fc1c54a28b349e20656f68a85f75befa0ee9b6cd75bfac3da5aca9c3f604", - "https://deno.land/std@0.222.1/path/windows/normalize.ts": "78126170ab917f0ca355a9af9e65ad6bfa5be14d574c5fb09bb1920f52577780", - "https://deno.land/std@0.222.1/path/windows/normalize_glob.ts": "9c87a829b6c0f445d03b3ecadc14492e2864c3ebb966f4cea41e98326e4435c6", - "https://deno.land/std@0.222.1/path/windows/parse.ts": "dbdfe2bc6db482d755b5f63f7207cd019240fcac02ad2efa582adf67ff10553a", - "https://deno.land/std@0.222.1/path/windows/relative.ts": "3e1abc7977ee6cc0db2730d1f9cb38be87b0ce4806759d271a70e4997fc638d7", - "https://deno.land/std@0.222.1/path/windows/resolve.ts": "8dae1dadfed9d46ff46cc337c9525c0c7d959fb400a6308f34595c45bdca1972", - "https://deno.land/std@0.222.1/path/windows/to_file_url.ts": "40e560ee4854fe5a3d4d12976cef2f4e8914125c81b11f1108e127934ced502e", - "https://deno.land/std@0.222.1/path/windows/to_namespaced_path.ts": "4ffa4fb6fae321448d5fe810b3ca741d84df4d7897e61ee29be961a6aac89a4c" - } -} diff --git a/apps/backend/package.json b/apps/backend/package.json index ab32522..3f3dbac 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -2,7 +2,11 @@ "name": "backend", "packageManager": "yarn@4.2.2", "scripts": { - "backend:dev": "gleam run" + "backend:dev": "gleam run", + "backend:db:create": "docker run --name gloogle-postgres -it -e POSTGRES_PASSWORD=gloogle -e POSTGRES_USER=gloogle -d -p 5432:5432 postgres", + "backend:db:init": "yarn backend:db:create && sleep 5 && PGPASSWORD=gloogle psql -h localhost -U gloogle < db/seeds.sql", + "backend:db:drop": "docker stop gloogle-postgres && docker rm gloogle-postgres", + "backend:db:reset": "yarn backend:db:drop && yarn backend:db:init" }, "dependencies": { "@chouqueth/gleam": "^1.3.2" diff --git a/apps/backend/scripts/database/drop.ts b/apps/backend/scripts/database/drop.ts deleted file mode 100644 index e2e437c..0000000 --- a/apps/backend/scripts/database/drop.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as helpers from '../helpers.ts' - -const id = await helpers.getDatabaseID() -if (id) { - await helpers.dropDatabase() -} else { - console.info("🤔 It looks like you don't have a local setup, exiting…") -} diff --git a/apps/backend/scripts/database/init.ts b/apps/backend/scripts/database/init.ts deleted file mode 100644 index 38a692c..0000000 --- a/apps/backend/scripts/database/init.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as helpers from '../helpers.ts' - -const id = await helpers.getDatabaseID() -if (!id) { - await helpers.createDatabases() - await helpers.writeDotEnv() - console.info("🎉 Database successfully initiated!") -} else { - console.info("🤔 It looks like you already have a local setup, are you sure you want to relaunch setup? Then, run yarn db:reset.") -} diff --git a/apps/backend/scripts/database/reset.ts b/apps/backend/scripts/database/reset.ts deleted file mode 100644 index 474530e..0000000 --- a/apps/backend/scripts/database/reset.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as helpers from '../helpers.ts' - -const id = await helpers.getDatabaseID() -if (id) { - await helpers.dropDatabase() - await helpers.createDatabases() - console.info("🎉 Database successfully resetted!") -} else { - console.info("🤔 It looks like you don't have a local setup, creating it instead of resetting…") - await helpers.createDatabases() - await helpers.writeDotEnv() -} diff --git a/apps/backend/scripts/helpers.ts b/apps/backend/scripts/helpers.ts deleted file mode 100644 index da1e0d8..0000000 --- a/apps/backend/scripts/helpers.ts +++ /dev/null @@ -1,53 +0,0 @@ -import * as dotenv from 'https://deno.land/std@0.222.1/dotenv/mod.ts' -import * as path from 'https://deno.land/std@0.222.1/path/mod.ts' -import * as thread from './thread.ts' - -export const NAME = 'gloogle-postgres' - -export const createDatabases = async () => { - const runPg = ['run', '--name', NAME, '-e', 'POSTGRES_PASSWORD=gloogle', '-p', '5432:5432', '-d', 'postgres'] - await new Deno.Command('docker', { args: runPg }).output() - await thread.sleep() - console.info('🎉 Postgres container successfully created!') - const id = await getDatabaseID() - if (id) { - await new Deno.Command('docker', { args: ['exec', id, 'createdb', '-U', 'postgres', 'gloogle_development'] }).output() - await new Deno.Command('docker', { args: ['exec', id, 'createdb', '-U', 'postgres', 'gloogle_test'] }).output() - await thread.sleep() - } - console.info('🥳 Database gloogle_development successfully created!') - console.info('🥳 Database gloogle_test successfully created!') -} - -export const writeDotEnv = async () => { - const dirname = path.fromFileUrl(import.meta.url) - const envPath = path.resolve(dirname, '../../.env') - const envPathTest = path.resolve(dirname, '../../.env.test') - const envs = [[envPath, 'gloogle_development'], [envPathTest, 'gloogle_test']] - await Promise.all(envs.map(async ([envPath, dbName]) => { - const content = await dotenv.load({ envPath }) - const dbUrl = ['postgres://postgres:gloogle@localhost:5432', dbName].join('/') - const sslDisabled = [dbUrl, 'sslmode=disable'].join('?') - const newContent: Record = { ...content, DATABASE_URL: sslDisabled } - await Deno.writeTextFile(envPath, dotenv.stringify(newContent)) - })) - console.info('✏️ .env and .env.test correctly initialized!') -} - -export const getDatabaseID = async () => { - const { stdout } = await new Deno.Command('docker', { args: ['container', 'list'] }).output() - const parts = new TextDecoder().decode(stdout).split('\n') - const line = parts.find((line) => line.includes(NAME)) - if (!line) return null - return line.split(' ')[0] -} - -export const dropDatabase = async () => { - const id = await getDatabaseID() - if (!id) return - await new Deno.Command('docker', { args: ['container', 'stop', id] }).output() - await thread.sleep() - await new Deno.Command('docker', { args: ['container', 'rm', id] }).output() - await thread.sleep() - console.info('🎉 Database successfully dropped!') -} diff --git a/apps/backend/scripts/thread.ts b/apps/backend/scripts/thread.ts deleted file mode 100644 index e9a9cdf..0000000 --- a/apps/backend/scripts/thread.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const sleep = (timeout = 2000) => { - return new Promise((resolve) => { - setTimeout(resolve, timeout) - }) -} diff --git a/apps/backend/src/backend/config.gleam b/apps/backend/src/backend/config.gleam index 614cac7..e57bd98 100644 --- a/apps/backend/src/backend/config.gleam +++ b/apps/backend/src/backend/config.gleam @@ -61,13 +61,12 @@ pub fn is_dev() { } pub fn bucket_uri() { - let assert Ok(content) = os.get_env("BUCKET_URI") - content + os.get_env("BUCKET_URI") } pub fn scaleway_keys() { - let assert Ok(access_key) = os.get_env("SCALEWAY_ACCESS_KEY") - let assert Ok(secret_key) = os.get_env("SCALEWAY_SECRET_KEY") + use access_key <- result.try(os.get_env("SCALEWAY_ACCESS_KEY")) + use secret_key <- result.map(os.get_env("SCALEWAY_SECRET_KEY")) #(access_key, secret_key) } diff --git a/apps/backend/src/s3.gleam b/apps/backend/src/s3.gleam index d4386ad..c8725a2 100644 --- a/apps/backend/src/s3.gleam +++ b/apps/backend/src/s3.gleam @@ -8,9 +8,9 @@ import gleam/option.{type Option, None, Some} import gleam/result fn request(url: String, method: http.Method, body: Option(BitArray)) { - let bucket_uri = config.bucket_uri() let date = birl.to_erlang_universal_datetime(birl.now()) - let #(access_key, secret_key) = config.scaleway_keys() + use bucket_uri <- result.try(config.bucket_uri()) + use #(access_key, secret_key) <- result.try(config.scaleway_keys()) request.new() |> request.set_method(method) |> request.set_path(url) diff --git a/apps/backend/test/backend_test.gleam b/apps/backend/test/backend_test.gleam index 9f2f91d..4ad1a9e 100644 --- a/apps/backend/test/backend_test.gleam +++ b/apps/backend/test/backend_test.gleam @@ -1,27 +1,42 @@ import backend/gleam/parse import backend/gleam/type_search +import gleam/erlang/os import gleam/function import gleam/int -import gleam/io +import gleam/option +import gleam/pgo import gleam/result import gleeunit import gleeunit/should +const signature = "fn use_callback(a, b) -> c" + +const search_test = "fn (a, _) -> b" + pub fn main() { gleeunit.main() } -const signature = "fn use_callback(a, b) -> c" - -const search_test = "fn (a, _) -> b" +fn postgres_connect() { + let host = os.get_env("POSTGRES_HOST") |> result.unwrap("localhost") + pgo.Config( + ..pgo.default_config(), + host: host, + database: "gloogle", + user: "gloogle", + password: option.Some("gloogle"), + ssl: False, + ) + |> pgo.connect +} // gleeunit test functions end in `_test` pub fn type_search_test() { + let db = postgres_connect() let index = int.random(1000) use kind <- result.try(parse.parse_function(signature) |> result.nil_error) use skind <- result.try(parse.parse_function(search_test) |> result.nil_error) let search = type_search.add(type_search.empty(), kind, index) - Ok(search) - // type_search.find(search, skind) - // |> function.tap(should.equal(_, Ok([index]))) + type_search.find(search, skind, db) + |> function.tap(should.equal(_, Ok([index]))) } diff --git a/apps/frontend/src/frontend/view/body/body.gleam b/apps/frontend/src/frontend/view/body/body.gleam index 50f0358..bb47b9b 100644 --- a/apps/frontend/src/frontend/view/body/body.gleam +++ b/apps/frontend/src/frontend/view/body/body.gleam @@ -31,7 +31,7 @@ fn view_search_input(model: Model) { ]), h.div([a.class("search-title-with-hint")], [ h.text("Gloogle"), - h.div([a.class("pre-alpha-title")], [h.text("Beta")]), + h.div([a.class("pre-alpha-title")], [h.text("RC")]), ]), ]), h.text(frontend_strings.gloogle_description),