Git Product home page Git Product logo

dt-mergebot's Introduction

This is the bot which controls the workflow of Definitely Typed PRs.

Meta

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 which runs the bot every 6 hours against all open PRs, and has a bunch of useful flags for running manually too.

Setup

# Clone it
git clone https://github.com/DefinitelyTyped/dt-mergebot.git
cd dt-mergebot

# Deps
npm install

# Validate it works
npm test

How the app works

There are three main stages once the app has a PR number:

How the bot works

There is an Azure function in PR-Trigger which receives webhooks; this function's job is to find the PR number then it runs the above steps.

Running Locally

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.

Development

# Build
npm run build

# Run the CLI to see what would happen to an existing PR
npm run single-info -- [PR_NUM]
# or
npm run single-info-debug -- [PR_NUM]

If you update any queries

Run this to update the generate types:

# Code-gen the schema
npm run graphql-schema

If you change project columns or labels

Run this to update the cached values:

# Regenerate src/_tests/cachedQueries.json
npm run update-test-data

Tests

# Run tests, TypeScript is transpiled at runtime
npm test

Most of the tests run against a fixtured PR, these are high level integration tests which 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
npm run create-fixture -- 43161

Then you can work against these fixtures offline with:

# Watch mode for all tests
npm test -- --watch
# Just run fixtures for one PR
npm 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:

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

Running with real webhooks

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

dt-mergebot's People

Contributors

andrewbranch avatar brc-dd avatar d-fischer avatar dependabot[bot] avatar elibarzilay avatar ffflorian avatar jablko avatar jakebailey avatar maxim-mazurok avatar orta avatar ryancavanaugh avatar sandersn avatar searyanc avatar stof avatar weswigham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dt-mergebot's Issues

`lastEditedAt` unused

There's no need to get lastEditedAt in pr-query.ts, since it's unused now, and unlikely to be useful.

Bot saying it's fine to merge when there's not been approval

in DefinitelyTyped/DefinitelyTyped#44282

Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 - keep an eye on this comment as I'll be updating it with information as things progress.

Code Reviews

Because you edited one package and updated the tests (👏), I can merge this once someone else signs off on it.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ❌ Most recent commit is approved by type definition owners, DT maintainers or others

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "pr_number": 44282,
  "author": "fishcharlie",
  "owners": [],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "2579430",
  "headCommitOid": "25794304acf8c1fd70712bd068beb07b0e09755e",
  "mergeIsRequested": false,
  "stalenessInDays": 0,
  "lastCommitDate": "2020-04-27T23:58:24.000Z",
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44282/files",
  "hasMergeConflict": false,
  "authorIsOwner": false,
  "isFirstContribution": true,
  "popularityLevel": "Well-liked by everyone",
  "anyPackageIsNew": false,
  "packages": [
    "benchmark"
  ],
  "files": [
    {
      "filePath": "types/benchmark/benchmark-tests.ts",
      "kind": "test",
      "package": "benchmark"
    },
    {
      "filePath": "types/benchmark/index.d.ts",
      "kind": "definition",
      "package": "benchmark"
    }
  ],
  "otherApprovalCount": 0,
  "ownerApprovalCount": 0,
  "maintainerApprovalCount": 0,
  "hasDismissedReview": false,
  "travisResult": "pass",
  "reviewersWithStaleReviews": [],
  "approvalFlags": 0,
  "isChangesRequested": false
}

Better workflow for "Author is Owner" / "No Other Owners"

Since recently, the demand for updating single owner definitions outstrips the capacity for DT maintainers to perform reviews. It used to be that I could count on adding features to my typings and it be no longer than 2 or 3 days and it would be merged but it's changed since the bot has taken over more responsibility. I am looking for a better workflow for single owner definitions.

The single owner scenario should be treated with responsibility of maintaining the quality of the package, not a DT maintainer. It takes me about 8 hours to bring a certain definition up to date with a new JS release. A DT maintainer is not going to put as much effort into the review as I, the single owner, did and it's half insulting to assume so.

If the single owner is good enough for reviewing and allowing commits from others then they should surely be good enough for their own changes. They should be treated as if they own that part of the repo. In fact maybe having a way to allow git submodules to pull in definitions wouldn't be a bad idea (it would speed up the DT CI build).

Looking at the current DT board. There are ~300 recently merged PRs...none of which are tagged "No Other Owners". Those are all waiting in other boards.

My current options are...

  • Add another "owner" simply to allow the bot to ping someone else to review/approve the changes. Who is qualified? Who cares? The NPM Credits section shows "These definitions were written by" which would be technically incorrect unless it starts showing these definitions were Written By: Owners , Reviewed By: Everyone that's ever approved changes on the file.

  • Wait for some unknown period of time until a volunteer comes along (~3 weeks?)

  • Go try to hunt down a DT maintainer, and request their review. (Tried it and did not work)

  • Become a DT maintainer? Does that allow me to approve my own changes?

  • Forget using DT and maintain my own private repo.

Allow for regular contributors to get away with 'infractions'

For modules which aren't too popular, and for users who have submitted a lot of PRs (like 20-30+) we could

  • Allow with no tests
  • Allow other reviewers
  • Allow PRs which touch tsconfig or tslint for that project

We could say only allow 1 of these at a time per PR, and to give at least a day before self merging is allowed.

Delay on processing of new PRs or alternative processing

After I added information when failing to find a PR, I saw a failure that had the information below for a pull_request / opened event. The PR does exist, and its URL is even mentioned in the event payload. So I'm guessing that there might be some processing delays (maybe there's a separate db that the gql api uses that needs to update) -- and therefore it's probably best to delay the processing of such events by a few seconds.

It's probably best to do this in addition to some manual per-pr sequentialization of handling incoming requests, since there are probably a small outburst of events when a pr is created.

Another possibility, since there are other cases when several events fire at the same time is, and since the processing always looks at the whole state so there's no need to process each and every event for the same PR:

  • When an event is received, figure out the PR number, and immediately return some "OK" answer.
  • Wait for several seconds for each of these (after returning the OK).
  • In this period, if there are new events for the same PR, then ignore them (or maybe extend the waiting period for the existing one).
  • Then do one processing of the PR.
Failed because of: No PR with this number exists, ({
  "data":{"repository":{"pullRequest":null,"__typename":"Repository"}},
  "loading":false,
  "networkStatus":7,
  "stale":false,
  "errors":[{
    "type":"NOT_FOUND",
    "path":["repository","pullRequest"],
    "locations":[{"line":3,"column":5}],
    "message":"Could not resolve to a PullRequest with the number of 46330."
  }]
})

There's no way to declare that module is auto generated

It's a follow-up to discussion with @orta
and it's related to Maxim-Mazurok/google-api-typings-generator#245

I'm maintaining a repo that is generating d.ts for Google client-side APIs (here's why: Google API in NodeJS VS Client)

Google APIs are updated constantly. Almost every hour at least one API is changed. Sometimes it's just revision number bump. Sometimes it's change of wording in comments. Sometimes it's bigger.
So, we're using Github Actions in order to generate new typings and put them in types branch.
Another action compares our types branch with typings in DT and if it's different - opens/updates PR: example PR.
You can find more info about this, including some flow-charts in this PR and linked issues.

There are currently a few problems:

  1. When we're changing comments - bot still wants tests to be changed.
  2. Another problem is when someone reviews my PR. Good example. As you can see, bot kept moving it form one column one the project board to another, making it fo to the bottom of list every time.

Since we don't really care about revision-only updates, I disabled them.

But still, it takes quiet some time to merge these changes and I'm feeling bad about wasting reviewers time.

Can we come up with some solution that would auto-merge auto-generated modules? Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.