Repository: googleapis/synthtool

Issue:
requests.exceptions.HTTPError: 404 Client Error: Not Found for url
When using synthtool to generate a new library for templates (or, for any case where the call doesn't match the repo), this error occurs:

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/synthtool/synthtool/languages/node.py", line 358, in <module>
    owlbot_main()
  File "/synthtool/synthtool/languages/node.py", line 349, in owlbot_main
    templates = common_templates.node_library(
  File "/synthtool/synthtool/gcp/common.py", line 301, in node_library
    return self._generic_library("node_library", **kwargs)
  File "/synthtool/synthtool/gcp/common.py", line 64, in _generic_library
    kwargs["metadata"]["repo"]["default_branch"] = _get_default_branch_name(
  File "/synthtool/synthtool/gcp/common.py", line 374, in _get_default_branch_name
    github_req.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.github.com/repos/googleapis/nodejs-essential-contacts
```

This error makes sense because the repository hasn't been published, but we still need to continue this call as we need to generate the base templates.

This issue can be traced to this [fix](https://github.com/googleapis/synthtool/pull/1031).


Discussion:

Patch:
diff --git a/noxfile.py b/noxfile.py
index 7499af9..d78d449 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -39,4 +39,4 @@ def lint(session):
 def test(session):
     session.install('pytest', 'pytest-cov', 'requests_mock', '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
+    session.run('pytest', '--cov-report', 'term-missing', '--cov', 'autosynth', 'synthtool', 'tests', *session.posargs)
diff --git a/synthtool/gcp/common.py b/synthtool/gcp/common.py
index 86ae323..ff102a4 100644
--- a/synthtool/gcp/common.py
+++ b/synthtool/gcp/common.py
@@ -20,7 +20,6 @@ import fnmatch
 from copy import deepcopy
 from pathlib import Path
 from typing import Dict, List, Optional
-import requests
 import jinja2
 
 from synthtool import shell, _tracked_paths
@@ -370,7 +369,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")


Test patch:
diff --git a/tests/test_common.py b/tests/test_common.py
index b32e1b3..0e75185 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -16,10 +16,9 @@ from synthtool.gcp.common import decamelize, _get_default_branch_name
 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"