From 1e311c59f461574ad644c4db43785b6e7b9183d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dandelion=20Man=C3=A9?=
Date: Mon, 23 Apr 2018 14:21:01 -0400
Subject: [PATCH] Add README and update flow for GitHub demo data (#129)
Keeping the GitHub demo data up-to-date is important, and there isn't
good documentation for how to do that.
This commit adds a short README.md for the demo data, and adds an update
flag to fetchGithubRepoTest.sh that can be used to easily update it.
Test plan:
Modify example-repo.json (e.g. by deleting it entirely). Run
fetchGithubRepoTest.sh -u and confirm that the data was regenerated
without change. Run fetchGithubRepoTest.sh and confirm the test passes.
Note: The end cursor is sensitive to the timezone, which seems to be
cached with the GitHub token. An erroneous switch to Israel timezone
made it into master; this commit reverts back to US/Pacific.
---
src/plugins/github/demoData/README.md | 22 +++++++
src/plugins/github/demoData/example-repo.json | 2 +-
src/plugins/github/fetchGithubRepoTest.sh | 59 ++++++++++++++-----
3 files changed, 68 insertions(+), 15 deletions(-)
create mode 100644 src/plugins/github/demoData/README.md
diff --git a/src/plugins/github/demoData/README.md b/src/plugins/github/demoData/README.md
new file mode 100644
index 0000000..dfa16fc
--- /dev/null
+++ b/src/plugins/github/demoData/README.md
@@ -0,0 +1,22 @@
+# DemoData Instructions
+
+This folder contains example data for testing the GitHub plugin. The example
+data is generated by running our GitHub API fetch against the SourceCred
+example repo at https://github.com/sourcecred/example-repo/.
+
+The demo data should be regenerated any time either the example repository or
+the GitHub api query changes. To regenerate the demo data, run the following
+command:
+
+```shell
+$ GITHUB_TOKEN="your_token_here" src/plugins/github/fetchGithubRepoTest.sh -u
+```
+
+You can also just verify that the data is up-to-date by running:
+```shell
+$ GITHUB_TOKEN="your_token_here" src/plugins/github/fetchGithubRepoTest.sh
+```
+
+There is a known issue where GitHub's end cursor output depends on your current
+timezone. The example data is canonically generated from the US/Pacific
+timezone.
diff --git a/src/plugins/github/demoData/example-repo.json b/src/plugins/github/demoData/example-repo.json
index d38193d..3257716 100644
--- a/src/plugins/github/demoData/example-repo.json
+++ b/src/plugins/github/demoData/example-repo.json
@@ -295,7 +295,7 @@
}
],
"pageInfo": {
- "endCursor": "Y3Vyc29yOnYyOpO5MjAxOC0wMy0wMVQwNjoyNDo1NiswMjowMLkyMDE4LTAzLTAxVDA2OjI0OjU2KzAyOjAwzgX6q7Y=",
+ "endCursor": "Y3Vyc29yOnYyOpO5MjAxOC0wMi0yOFQyMDoyNDo1Ni0wODowMLkyMDE4LTAyLTI4VDIwOjI0OjU2LTA4OjAwzgX6q7Y=",
"hasNextPage": false
}
},
diff --git a/src/plugins/github/fetchGithubRepoTest.sh b/src/plugins/github/fetchGithubRepoTest.sh
index b026943..8056d97 100755
--- a/src/plugins/github/fetchGithubRepoTest.sh
+++ b/src/plugins/github/fetchGithubRepoTest.sh
@@ -2,27 +2,58 @@
set -eu
-main() {
- if ! [ -d bin ]; then
- printf >&2 'Backend applications have not been built.\n'
- printf >&2 'Please run "yarn backend".\n'
- return 1
- fi
+data_file=src/plugins/github/demoData/example-repo.json
+
+usage() {
+ printf 'usage: %s [-u|--updateSnapshot] [--help]\n' "$0"
+ printf 'Required environment variables:\n'
+ printf ' GITHUB_TOKEN: A 40-character hex string API token.\n'
+ printf 'Flags:\n'
+ printf ' -u|--updateSnapshot\n'
+ printf ' Update the stored file instead of checking its contents\n'
+ printf ' --help\n'
+ printf ' Show this message\n'
+}
+
+fetch() {
if [ -z "${GITHUB_TOKEN:-}" ]; then
printf >&2 'Please set the GITHUB_TOKEN environment variable\n'
printf >&2 'to a 40-character hex string API token from GitHub.\n'
return 1
fi
- output="$(mktemp)"
+ yarn backend >&2
node bin/fetchAndPrintGithubRepo.js \
- sourcecred example-repo "${GITHUB_TOKEN}" \
- >"${output}" \
- ;
- diff -uw \
- src/plugins/github/demoData/example-repo.json \
- "${output}" \
- ;
+ sourcecred example-repo "${GITHUB_TOKEN}"
+}
+
+check() {
+ output="$(mktemp)"
+ fetch >"${output}"
+ diff -uw "${data_file}" "${output}"
rm "${output}"
}
+update() {
+ fetch >"${data_file}"
+}
+
+main() {
+ cd "$(git rev-parse --show-toplevel)"
+ if [ $# -eq 0 ]; then
+ check
+ elif [ $# -eq 1 ]; then
+ if [ "$1" = "-u" ] || [ "$1" = "--updateSnapshot" ]; then
+ update
+ elif [ "$1" = "--help" ]; then
+ usage
+ else
+ usage >&2
+ return 1
+ fi
+ else
+ usage >&2
+ return 1
+ fi
+}
+
main "$@"