A Cloudflare worker for creating GitHub PRs for new course reviews for ubccsss.org's courses database. Reviews are verified using reCAPTCHA.
$ git clone
$ cd course-review-worker
$ npm install
$ npm i @cloudflare/wrangler -g
$ wrangler login # select y to login via browser
- Development : default
- Production :
--env production
Below are the environment variables that are used by the worker. Each one of them has a value for production and development. They can be set in wrangler.toml
.
ENVIRONMENT
: The environment the worker is running inOWNER
: owner of the GitHub repositoryREPO
: name of the GitHub repositoryBASE_BRANCH
: base branch of the GitHub repositoryUSERS
: comma-separated list of user reviewers for the PRTEAMS
: comma-separated list of team reviewers for the PRLABELS
: comma-separated list of labels to apply to new PRsORIGIN
: acceptable origin for requests to the worker
ACCESS_TOKEN
: GitHub access tokenRECAPTCHA_SECRET_KEY
: Google reCAPTCHA secret key
Secrets can be managed using wrangler or using the Cloudflare dashboard.
const pr = await fetch(WORKER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
recaptcha: {
token: token,
},
details: {
course: course,
user: user,
review: review,
reference: reference,
difficulty: difficulty,
quality: quality,
sessionTaken: sessionTaken,
},
}),
})
Complete example call with error handling here.
index.js
contains the Worker's script.
wrangler.toml
contains the worker's configuration.
Running the worker locally:
$ wrangler dev # runs dev environment
$ wrangler dev --env production # runs production envirnment
Publishing the worker to Cloudflare:
$ wrangler publish # publishes dev environment
$ wrangler publish --env production # publishes production environment
Further documentation on Cloudflare workers can be found here.
Further documentation on Wrangler can be found here.