Make GitHub post-commit more reliable with "main" branch.

Review Request #11251 — Created Oct. 27, 2020 and submitted

Information

Review Board
release-3.0.x

Reviewers

Now that Git supports it, more and more people are choosing to name
their mainline branch something other than "master". While before we
were relatively confident that one of the branches fetched would have
this name, that's no longer the case. This is particularly bad for the
case where there's only one branch, because if none of the branches were
marked as default, the frontend would never fetch the commits.

This change updates the GitHub get_branches method to make sure that
there's always a default branch set. If a branch is found named
"master", we'll use that one, then it will try "main", and finally if
neither is chosen, we'll just mark the first branch as the default.

At the moment GitHub doesn't have a way for us to know what's the
default (there's a user setting for when new repositories are created,
but that doesn't tell us anything about existing repositories,
especially those that are part of organizations rather than personal
repos). Hopefully they'll add this to their API at some point and we'll
be able to simplify this then.

Created a new repository with only one branch, named "main". Saw that I
could open the "New Review Request" page and that the main branch was
selected and commits were properly loaded.

Summary ID
Make GitHub post-commit more reliable with "main" branch.
Now that Git supports it, more and more people are choosing to name their mainline branch something other than "master". While before we were relatively confident that one of the branches fetched would have this name, that's no longer the case. This is particularly bad for the case where there's only one branch, because if none of the branches were marked as default, the frontend would never fetch the commits. This change updates the GitHub `get_branches` method to make sure that there's always a default branch set. If a branch is found named "master", we'll use that one, then it will try "main", and finally if neither is chosen, we'll just mark the first branch as the default. At the moment GitHub doesn't have a way for us to know what's the default (there's a user setting for when new repositories are created, but that doesn't tell us anything about existing repositories, especially those that are part of organizations rather than personal repos). Hopefully they'll add this to their API at some point and we'll be able to simplify this then. Testing Done: Created a new repository with only one branch, named "main". Saw that I could open the "New Review Request" page and that the main branch was selected and commits were properly loaded.
b650f901eb0570ad8a0e6390a614d12196c39a66
Description From Last Updated

Can you add unit tests for the priority matching and the 1-branch case?

chipx86chipx86
chipx86
  1. 
      
  2. Show all issues

    Can you add unit tests for the priority matching and the 1-branch case?

  3. 
      
david
chipx86
  1. Ship It!
  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.0.x (0379aef)