Default branch may not exist on a repo without commits
@@ -397,21 +397,8 @@ impl GithubRepo {
.get_branch(&company.github_org, &self.name, &self.default_branch)
.await;
- if let Err(e) = branch {
- info!(
- "Failed to find default branch {} on {}. Returning early. err: {:?}",
- self.default_branch, self.name, e
- );
-
- if !e.to_string().contains("404") && !e.to_string().contains("Not Found") {
- bail!("could not get branch {} repo {}: {}", self.default_branch, self.name, e);
- } else {
- // Return early. Likely the repo no longer exists.
- return Ok(());
- }
- }
- let default_branch = branch?;
-
+ match branch {
+ Ok(default_branch) => {
// Add branch protection to disallow force pushing to the default branch.
// Only do this if it is not already protected.
if !default_branch.protected {
@@ -444,6 +431,18 @@ impl GithubRepo {
}
}
}
+ },
+ Err(err) => {
+ info!(
+ "Failed to find default branch {} on {}. Returning early. err: {:?}",
+ self.default_branch, self.name, e
+ );
+
+ if !e.to_string().contains("404") && !e.to_string().contains("Not Found") {
+ bail!("could not get branch {} repo {}: {}", self.default_branch, self.name, e);
+ }
+ }
+ }
// Get this repository's teams.
let mut ts: Vec<octorust::types::Team> = Default::default();
