Skip to content

Commit

Permalink
Fix: add_issue_templates encountered an UnboundLocalError: cannot acc…
Browse files Browse the repository at this point in the history
…ess local variable 'default_branch'
  • Loading branch information
hiroshinishio committed Aug 30, 2024
1 parent 7d6face commit 0af0e8e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions services/github/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import requests
from fastapi import Request
from github import Github, GithubException
from github.Branch import Branch
from github.ContentFile import ContentFile
from github.PullRequest import PullRequest
from github.Repository import Repository
Expand Down Expand Up @@ -67,19 +66,23 @@ def add_issue_templates(full_name: str, installer_name: str, token: str) -> None
repo: Repository = gh.get_repo(full_name_or_id=full_name)

# Create a new branch
default_branch = None
default_branch_name: str = repo.default_branch
retries = 0
while retries < MAX_RETRIES:
try:
default_branch: Branch = repo.get_branch(branch=default_branch_name)
default_branch = repo.get_branch(branch=default_branch_name)
break
except GithubException as e:
retries += 1
msg = f"Error: {e.data['message']}. Retrying to get the default branch for repo: {full_name} and branch: {default_branch_name}."
logging.info(msg)
time.sleep(10)
time.sleep(20)
new_branch_name: str = f"{PRODUCT_ID}/add-issue-templates-{str(object=uuid4())}"
ref = f"refs/heads/{new_branch_name}"
if default_branch is None:
msg = f"Error: Could not get the default branch for repo: {full_name} and branch: {default_branch_name}."
raise RuntimeError(msg)
repo.create_git_ref(ref=ref, sha=default_branch.commit.sha)

# Add issue templates to the new branch
Expand Down

0 comments on commit 0af0e8e

Please sign in to comment.