diff options
author | Oliver Chang <oliverchang@users.noreply.github.com> | 2021-10-20 08:22:11 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 08:22:11 +1100 |
commit | c40dd1eb742203cf3476b64fb19e986ea2176394 (patch) | |
tree | a880746f229d89209cfef69b9433a362914d553c /infra | |
parent | b771fe7914a50597a92297747d8829cf8f0e4997 (diff) |
Get repository URL from environment variable instead. (#6582)
* Get repository URL from environment variable instead.
Fixes #6576.
* fix lint
* use https instead
Diffstat (limited to 'infra')
-rw-r--r-- | infra/cifuzz/config_utils.py | 16 | ||||
-rw-r--r-- | infra/cifuzz/config_utils_test.py | 26 |
2 files changed, 39 insertions, 3 deletions
diff --git a/infra/cifuzz/config_utils.py b/infra/cifuzz/config_utils.py index bc73536b..1763f7b6 100644 --- a/infra/cifuzz/config_utils.py +++ b/infra/cifuzz/config_utils.py @@ -126,6 +126,11 @@ class GenericCiEnvironment(BaseCiEnvironment): # Repo owner is a githubism. return None, repository + @property + def repo_url(self): + """Returns the repo URL.""" + return os.getenv('REPOSITORY_URL') + class GithubEnvironment(BaseCiEnvironment): """CI environment for GitHub.""" @@ -166,6 +171,12 @@ class GithubEnvironment(BaseCiEnvironment): # Use os.path.split to split owner from repo. return os.path.split(repository) + @property + def repo_url(self): + """Returns the GitHub repo URL.""" + repository = os.getenv('GITHUB_REPOSITORY') + return f'https://github.com/{repository}.git' + class ConfigError(Exception): """Error for invalid configuration.""" @@ -319,8 +330,6 @@ class BuildFuzzersConfig(BaseConfig): self.pr_ref = f'refs/pull/{event_data["pull_request"]["number"]}/merge' logging.debug('pr_ref: %s', self.pr_ref) - self.git_url = event_data['repository']['html_url'] - def __init__(self): """Get the configuration from CIFuzz from the environment. These variables are set by GitHub or the user.""" @@ -329,8 +338,9 @@ class BuildFuzzersConfig(BaseConfig): event = os.getenv('GITHUB_EVENT_NAME') self.pr_ref = None - self.git_url = None + self.git_url = self._ci_env.repo_url self.base_commit = None + self._get_config_from_event_path(event) self.base_ref = os.getenv('GITHUB_BASE_REF') diff --git a/infra/cifuzz/config_utils_test.py b/infra/cifuzz/config_utils_test.py index 32499bfd..d4ccd1eb 100644 --- a/infra/cifuzz/config_utils_test.py +++ b/infra/cifuzz/config_utils_test.py @@ -202,6 +202,32 @@ class GetProjectRepoOwnerAndNameTest(unittest.TestCase): (None, self.repo_name)) +class GetRepoUrlTest(unittest.TestCase): + """Tests for GenericCiEnvironment.repo_url.""" + + def setUp(self): + test_helpers.patch_environ(self) + self.github_env = config_utils.GithubEnvironment() + self.generic_ci_env = config_utils.GenericCiEnvironment() + + def test_unset_repository(self): + """Tests that the correct result is returned when repository is not set.""" + self.assertEqual(self.generic_ci_env.repo_url, None) + + def test_github_repository(self): + """Tests that the correct result is returned when repository contains the + owner and repo name (as it does on GitHub).""" + os.environ['GITHUB_REPOSITORY'] = 'repo/owner' + self.assertEqual('https://github.com/repo/owner.git', + self.github_env.repo_url) + + def test_nongithub_repository(self): + """Tests that the correct result is returned when repository contains the + just the repo name (as it does outside of GitHub).""" + os.environ['REPOSITORY_URL'] = 'https://repo/url' + self.assertEqual('https://repo/url', self.generic_ci_env.repo_url) + + class GetSanitizerTest(unittest.TestCase): """Tests for _get_sanitizer.""" |