This is the bot that controls the workflow of Definitely Typed PRs.
- State: Production
- Dashboard: Azure — Logs — GH Actions — GH Webhook
TODO: Update these links for dtmergebot2
It is both a series of command line scripts which you can use to test different states, and an Azure Function App which handles incoming webhooks from the DefinitelyTyped repo.
This repo is deployed to Azure on every push to master. To ensure we can handle timeouts on older PRs, there is a GitHub Action that runs the bot every 6 hours against all open PRs, and has a bunch of useful flags for running manually too.
# Clone it
git clone https://github.com/microsoft/DefinitelyTyped-tools.git
cd DefinitelyTyped-tools
# Deps
pnpm install
# Validate it works
pnpm test
There are three main stages once the app has a PR number:
- Query the GitHub GraphQL API for PR metadata (
pr-info
) - Create a PR actions metadata object (
compute-pr-actions
) - Do work based on the resulting actions (
execute-pr-actions
)
There is an Azure function in PR-Trigger
that receives webhooks; this function's job is to find the PR number then it runs the above steps.
You probably don't need to do this. Use test to validate any change inside the src dir against integration tests.
However, you need to have a GitHub API access key in either: DT_BOT_AUTH_TOKEN
, BOT_AUTH_TOKEN
or AUTH_TOKEN
.
Ask Ryan for the bot's auth token (TypeScript team members: Look in the team OneNote).
Don't run the bot under your own auth token as this will generate a bunch of spam from duplicate comments.
# Windows
set BOT_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
# *nix
export BOT_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Then to run locally you'll need to install the Azure Functions cli.
# Build
pnpm run build
# Run the CLI to see what would happen to an existing PR
pnpm run single-info -- [PR_NUM]
# or
pnpm run single-info-debug -- [PR_NUM]
Run this to update the generate types:
# Code-gen the schema
pnpm run graphql-schema
Run this to update the cached values:
# Regenerate src/_tests/cachedQueries.js
pnpm run update-test-data
# Run tests, TypeScript is transpiled at runtime
pnpm test
Most of the tests run against a fixtured PR, these are high level integration tests that store the PR info and then re-run the latter two phases of the app.
To create fixtures of a current PR:
# To create a fixture for PR 43161
pnpm run create-fixture 43161
Then you can work against these fixtures offline with:
# Watch mode for all tests
pnpm test -- --watch
# Just run fixtures for one PR
pnpm test -- --testNamePattern 44299
Run a test with the debugger:
node --inspect --inspect-brk ./node_modules/.bin/jest -i --runInBand --testNamePattern 44299
Then use "Attach to Process ID" to connect to that test runner
If your changes require re-creating all fixtures:
pnpm run update-all-fixtures
Be careful with this, because PRs may now be in a different state e.g. it's now merged and it used to be a specific weird state.
You need a tool like ngrok to expose a URL from the webhooks section on DT.
Start two terminal sessions with:
yarn watch
(for TypeScript changes)yarn start
(for the app)
Then start a third with your localhost router like ngrok:
ngrok http 7071