Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GitHub webhooks #69

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

danlivings-dxw
Copy link
Contributor

This PR allows Towtruck to listen for several types of events on the POST /api/github/webhooks endpoint. This can be used to incrementally update the database and spreading out the requests it makes to the GitHub API, rather than issuing a large number of requests in a short window of time as it does when seeding.

The events it listens for are:

  • pull_request.opened and pull_request.closed to update the list of open pull requests
  • issues.opened and issues.closed to update the list of open issues
  • push and issues.edited to update the list of dependencies
  • dependabot_alert to update the list of vulnerabilities
  • repository to update basic information about repositories

NB: this pull request depends on #63, which should be merged first.

@danlivings-dxw danlivings-dxw linked an issue Oct 10, 2024 that may be closed by this pull request
@danlivings-dxw danlivings-dxw force-pushed the feature/use-github-webhooks branch 3 times, most recently from 61f8d54 to 6f0fd81 Compare October 17, 2024 14:59
Base automatically changed from feature/use-sqlite-db to main October 17, 2024 15:02
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been several years since I was regularly in js world - is it standard practice to not keep tests in a dedicated dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've mostly been following the lead set by Rich on this when he was still at dxw - I'm not clued up enough on JS best practices to know whether or not having separate source and test folders is preferred or not.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests yes (so this is fine), integration tests no

This will allow webhooks to call this function to ensure that new
dependencies have lifetime information if it is available.
The logic used to fetch and store information about repositories and
dependencies will need to be reused to allow webhooks to make changes to
the database. Using the logic in the application rather than in one-off
seeding scripts makes it more important that it is tested to avoid
unexpected changes to behaviour. This moves the actual seed scripts to
wrapper scripts in the `seed` folder, which call the methods in the
original files that have been refactored to be more testable.
To update dependency or repository information in an efficient way,
Towtruck should listen to GitHub events rather than polling for updates.
Towtruck needs to listen to the following events:

- `pull_request.opened` and `pull_request.closed` to update the list of
  open pull requests
- `issues.opened` and `issues.closed` to update the list of open issues
- `push` and `issues.edited` to update the list of dependencies
- `dependabot_alert` to update the list of vulnerabilities
- `repository` to update basic information about repositories
@Gweaton
Copy link

Gweaton commented Oct 30, 2024

Thanks for tackling this feature, Dan, there's a lot of complexity at work and it looks like your refactoring and test improvements will improve readability and maintainability of the codebase. I've found it a little tricky to review due to the number of changes here (+1,484 −67!).

As someone who likes to review a PR commit by commit, I’m finding it a little difficult to review the second refactoring commit here with the number of changes, and I’m a little concerned I’ll miss something.

Suggestion: Would it be possible to split the big refactor into its own PR made up of smaller commits?

Here’s how I’d structure it:

  1. Add deleteAllRepositories function
  2. Add deleteAllDependencies function
  3. Use new functions in seed script.

I’d find it much easier to digest the changes in these smaller chunks, and could hopefully give you a more thorough review.

This PR could then consist of a few smaller commits, one for each of the Github events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add webhooks
4 participants