Repository navigation
[Branch protection] Use new API endpoint - #8563
Conversation
We don't need database caching for our purposes now that we get exactly the info we need from the GitHub API. In-memory caching is enough to suit our purposes
Repo refresh happens frequently and we wan't to be mindful of API limits. Removing this means we don't refresh branch protection state on app focus, which is desirable since we don't expect protection rules to change often.
We've decided to keep collecting metrics for `commitsToRepositoryWithBranchProtections`, which requires us to store data on protected branches in a repository
| gitStore.updateLastFetched(), | ||
| gitStore.loadStashEntries(), | ||
| this.refreshAuthor(repository), | ||
| this.refreshBranchProtectionState(repository), |
There was a problem hiding this comment.
Rather than refreshing the branch protection state on repo refresh (which happens quite often, like on app focus), we are now only refreshing when the user checks out a branch, changes repositories, or does a push/pull/fetch. Since we do periodic background fetching, branch protection refreshing will happen periodically as well.
We are not refreshing branch protection state upon app focus, since that happens quite often and we want to mindful of API limits. We don't expect branch protection rules to be updated frequently, so it's safe to rely on the other forms of updating.
| // This is now purely for metrics collection for `commitsToRepositoryWithBranchProtections` | ||
| // Understanding how many users actually contribute to repos with branch protections gives us | ||
| // insight into who our users are and what kinds of work they do | ||
| this.updateBranchProtectionsFromAPI(repository) |
There was a problem hiding this comment.
Now that we're only using the repos/${owner}/${name}/branches?protected=true endpoint to gather metrics about if a user is committing to a repository that has protected branches, we can afford to update the data less frequently (individual rule changes don't matter to us, only if the repo has a non-zero number of protected branches). So for now I'm opting to simply update it on repo change.
outofambit
left a comment
There was a problem hiding this comment.
two little things, but this looks great! 🎉 thanks @kuychaco!
| const pushableByUser = | ||
| allow_actor && | ||
| required_status_checks.length === 0 && | ||
| required_approving_review_count === 0 |
There was a problem hiding this comment.
could this go into a helper method that lives somewhere in lib/? this is pretty crucial logic and i want to make sure its clearly encapsulated and documented.
i'm also a little unclear why we need to use the required status checks and review counts. are these enforced for pushing directly to a branch and not just for merges?
| // This is now purely for metrics collection for `commitsToRepositoryWithBranchProtections` | ||
| // Understanding how many users actually contribute to repos with branch protections gives us | ||
| // insight into who our users are and what kinds of work they do | ||
| this.updateBranchProtectionsFromAPI(repository) |
In `repositoryWithRefreshedGitHubRepository` Co-Authored-By: evelyn masso <[email protected]>
And out of `_selectRepositoryRefreshTasks` since it's not actually a refresh task Co-Authored-By: evelyn masso <[email protected]>
Co-Authored-By: evelyn masso <[email protected]>
Co-Authored-By: evelyn masso <[email protected]>
review-lab url format is `https://branch-name.review-lab.github.com` Co-Authored-By: evelyn masso <[email protected]>
Co-Authored-By: evelyn masso <[email protected]>
Co-Authored-By: evelyn masso <[email protected]>
Co-Authored-By: evelyn masso <[email protected]>
Co-Authored-By: evelyn masso <[email protected]>
Closes #7023
Description
Use new
push_controlendpoint introduced in https://github.com/github/github/issues/127973 to determine whether the user's current branch is protected.Relevant work PRs that this builds on top of: #7826, #7595 and #7529
Screenshots
Testing
Manually tested the following cases on review-lab:
Release notes
Notes: [Feature] Suggest moving to a branch prior to committing to a protected branch