Skip to content

[Branch protection] Use new API endpoint - #8563

Merged
outofambit merged 34 commits into
developmentfrom
ku-protected-branch
Nov 14, 2019
Merged

outofambit merged 34 commits into
developmentfrom
ku-protected-branch

Conversation

@kuychaco

@kuychaco kuychaco commented Nov 1, 2019 •

Copy link
Copy Markdown
Contributor

Closes #7023

Description

Use new push_control endpoint 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

GitHub_Desktop-dev_and_first_pass_at_UI_for_warning_about_protected_branches_by_shiftkey_·_Pull_Request__7826_·_desktop_desktop

Testing

Manually tested the following cases on review-lab:

  • owner has no warning if admin not included and review is required
  • owner has warning if admin is included and review is required
  • collaborator on allow list has no warning
  • collaborator on team on allow list has no warning
  • collaborator not on allow list has warning
  • collaborator on allow list has warning if review is required

Release notes

Notes: [Feature] Suggest moving to a branch prior to committing to a protected branch

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),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread app/src/lib/stores/app-store.ts Outdated
// 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯!

@kuychaco
kuychaco marked this pull request as ready for review November 7, 2019 03:14
@kuychaco
kuychaco requested review from niik and outofambit November 7, 2019 21:53

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

two little things, but this looks great! 🎉 thanks @kuychaco!

Comment thread app/src/lib/stores/app-store.ts Outdated
Comment on lines +855 to +858
const pushableByUser =
allow_actor &&
required_status_checks.length === 0 &&
required_approving_review_count === 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread app/src/lib/stores/app-store.ts Outdated
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯!

Comment thread app/src/lib/api.ts Resolved
Comment thread app/src/lib/api.ts Resolved
kuychaco and others added 4 commits November 8, 2019 16:31
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]>
@kuychaco
kuychaco requested a review from outofambit November 13, 2019 22:46
@outofambit outofambit self-assigned this Nov 13, 2019
@outofambit
outofambit merged commit 8e27ec5 into development Nov 14, 2019
@outofambit
outofambit deleted the ku-protected-branch branch November 14, 2019 20:01
@outofambit outofambit added the metrics measuring user behavior for better decisions label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metrics measuring user behavior for better decisions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I accidentally commit locally to protected branches

2 participants