Skip to content

Commit

Permalink
fix(node): fetch default branch from env
Browse files Browse the repository at this point in the history
Fixes #1072
  • Loading branch information
bcoe committed May 11, 2021
1 parent 6726988 commit c0bdd41
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ def lint(session):

@nox.session(python=['3.6', '3.8'])
def test(session):
session.install('pytest', 'pytest-cov', 'requests_mock', 'watchdog')
session.install('pytest', 'pytest-cov', 'watchdog')
session.run('pip', 'install', '-e', '.')
session.run('pytest', '--cov-report', 'term-missing', '--cov', 'autosynth', 'synthtool', 'tests', *session.posargs)
7 changes: 3 additions & 4 deletions synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ def _load_repo_metadata(metadata_file: str = "./.repo-metadata.json") -> Dict:


def _get_default_branch_name(repository_name: str) -> str:
github_req = requests.get(f"https://api.github.com/repos/{repository_name}")
github_req.raise_for_status()

return github_req.json()["default_branch"]
# This default should be switched to "main" once we've migrated
# the majority of our repositories:
return os.getenv("DEFAULT_BRANCH", "master")
8 changes: 2 additions & 6 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
from pathlib import Path
from pytest import raises
import os
import requests_mock
import synthtool as s
from . import util

from unittest import mock

MOCK = Path(__file__).parent / "generationmock"
template_dir = Path(__file__).parent.parent / "synthtool/gcp/templates"
Expand All @@ -43,10 +42,7 @@ def test_handles_empty_string():


def test_get_default_branch():
with requests_mock.Mocker() as m:
m.get(
"https://api.github.com/repos/repo_name", text='{"default_branch": "main"}',
)
with mock.patch.dict(os.environ, {"DEFAULT_BRANCH": "main"}):
assert _get_default_branch_name("repo_name") == "main"


Expand Down

0 comments on commit c0bdd41

Please sign in to comment.