From 44cc80c271171c7f79a362547c62895c2c7813de Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 11 Sep 2024 13:02:30 +0100 Subject: [PATCH] Add seeding script The app will no longer work unless the seed script is run. We don't always want to seed this data as we hit the prod GH API. For now the seeding can be run by passing a flag to the script/bootstrap command. --- README.md | 6 ++++++ package.json | 3 ++- script/bootstrap | 7 +++++++ script/seed | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 script/seed diff --git a/README.md b/README.md index 3d3d9b6..30cb970 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,9 @@ In order for Towtruck to communicate with the GitHub API, it needs several piece - `CLIENT_ID`: A unique alphanumeric ID assigned to the GitHub App. - `CLIENT_SECRET`: A token used to authenticate API requests. These are generated by GitHub in the app settings. - `WEBHOOK_SECRET`: A user-defined secret used to authenticate GitHub to Towtruck for receiving webhooks. This must be exactly the same as it is entered in the app settings on GitHub. + + +### Seedings + +Once all the other setup steps have been completed run `script/seed` or `script/bootstrap --seed` to seed the data. +This will call the Github API which is rate limit so take care not to to run the script too often. diff --git a/package.json b/package.json index b2fc985..e103676 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "test": "node --test", "lint": "eslint .", "lint:fix": "eslint . --fix", - "format": "prettier --write ." + "format": "prettier --write .", + "seed": "node --env-file=.env ./dataScripts/fetchAllRepos.js" }, "author": "dxw", "license": "MIT", diff --git a/script/bootstrap b/script/bootstrap index 59b35ab..c05e1c9 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -17,3 +17,10 @@ nvm install echo "==> Installing node modules..." npm install + +if [ -n "$1" ]; then + echo "==> Seeding data..." + npm run seed +else + echo "==> Skipping seeding data..." +fi diff --git a/script/seed b/script/seed new file mode 100755 index 0000000..75a6ecd --- /dev/null +++ b/script/seed @@ -0,0 +1,10 @@ +#!/bin/bash + +# script/seed: Seeds the necessary data + +set -e + +cd "$(dirname "$0")/.." + +echo "==> Seeding data..." +npm run seed