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.
This commit is contained in:
Dandelion Mané 2018-04-23 14:21:01 -04:00 committed by GitHub
parent d025e78b1d
commit 1e311c59f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 15 deletions

View File

@ -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.

View File

@ -295,7 +295,7 @@
}
],
"pageInfo": {
"endCursor": "Y3Vyc29yOnYyOpO5MjAxOC0wMy0wMVQwNjoyNDo1NiswMjowMLkyMDE4LTAzLTAxVDA2OjI0OjU2KzAyOjAwzgX6q7Y=",
"endCursor": "Y3Vyc29yOnYyOpO5MjAxOC0wMi0yOFQyMDoyNDo1Ni0wODowMLkyMDE4LTAyLTI4VDIwOjI0OjU2LTA4OjAwzgX6q7Y=",
"hasNextPage": false
}
},

View File

@ -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 "$@"