From c0bdd417c250aaebc0b3b2d70799d773e896e567 Mon Sep 17 00:00:00 2001 From: bcoe Date: Tue, 11 May 2021 09:37:30 -0700 Subject: [PATCH] fix(node): fetch default branch from env Fixes #1072 --- noxfile.py | 2 +- synthtool/gcp/common.py | 7 +++---- tests/test_common.py | 8 ++------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/noxfile.py b/noxfile.py index 7499af9c4..9d98d1b3c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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) \ No newline at end of file diff --git a/synthtool/gcp/common.py b/synthtool/gcp/common.py index 86ae323c3..c8ab88a80 100644 --- a/synthtool/gcp/common.py +++ b/synthtool/gcp/common.py @@ -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") diff --git a/tests/test_common.py b/tests/test_common.py index b32e1b3ce..0e75185ca 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -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" @@ -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"