From 8464dcc4dd87d53884302360672e168f6ec06619 Mon Sep 17 00:00:00 2001 From: Paul McLanahan Date: Fri, 15 Apr 2022 14:25:02 -0400 Subject: [PATCH] Ensure all uses of git specify a branch name --- bedrock/base/views.py | 2 +- bedrock/settings/base.py | 5 ++++- bedrock/sitemaps/management/commands/fetch_sitemaps.py | 2 +- bedrock/sitemaps/management/commands/update_sitemaps_data.py | 2 +- bedrock/utils/tests/test_git.py | 2 +- bin/open-ftl-pr.sh | 1 + lib/l10n_utils/management/commands/_ftl_repo_base.py | 4 ++-- lib/l10n_utils/management/commands/l10n_update.py | 2 +- lib/l10n_utils/management/commands/open_ftl_pr.py | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bedrock/base/views.py b/bedrock/base/views.py index 304a14e92fb..f6756fa12ed 100644 --- a/bedrock/base/views.py +++ b/bedrock/base/views.py @@ -56,7 +56,7 @@ def get_template_names(self): def get_l10n_repo_info(): - fluent_repo = git.GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL) + fluent_repo = git.GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL, settings.FLUENT_REPO_BRANCH) data = { "latest_ref": fluent_repo.current_hash, "last_updated": fluent_repo.last_updated, diff --git a/bedrock/settings/base.py b/bedrock/settings/base.py index 76d4d3118fd..a53ad5d629f 100644 --- a/bedrock/settings/base.py +++ b/bedrock/settings/base.py @@ -256,12 +256,14 @@ def data_path(*args): FLUENT_DEFAULT_PERCENT_REQUIRED = config("FLUENT_DEFAULT_PERCENT_REQUIRED", default="80", parser=int) FLUENT_REPO = config("FLUENT_REPO", default="mozmeao/www-l10n") FLUENT_REPO_URL = f"https://github.com/{FLUENT_REPO}" +FLUENT_REPO_BRANCH = config("FLUENT_REPO_BRANCH", default="master") FLUENT_REPO_PATH = DATA_PATH / "www-l10n" # will be something like ":" FLUENT_REPO_AUTH = config("FLUENT_REPO_AUTH", default="") FLUENT_LOCAL_PATH = ROOT_PATH / "l10n" FLUENT_L10N_TEAM_REPO = config("FLUENT_L10N_TEAM_REPO", default="mozilla-l10n/www-l10n") FLUENT_L10N_TEAM_REPO_URL = f"https://github.com/{FLUENT_L10N_TEAM_REPO}" +FLUENT_L10N_TEAM_REPO_BRANCH = config("FLUENT_L10N_TEAM_REPO_BRANCH", default="master") FLUENT_L10N_TEAM_REPO_PATH = DATA_PATH / "l10n-team" # 10 seconds during dev and 10 min in prod FLUENT_CACHE_TIMEOUT = config("FLUENT_CACHE_TIMEOUT", default="10" if DEBUG else "600", parser=int) @@ -464,6 +466,7 @@ def lazy_langs(): } SITEMAPS_REPO = config("SITEMAPS_REPO", default="https://github.com/mozmeao/www-sitemap-generator.git") +SITEMAPS_REPO_BRANCH = config("SITEMAPS_REPO_BRANCH", default="master") SITEMAPS_PATH = DATA_PATH / "sitemaps" # Pages that have different URLs for different locales, e.g. @@ -1081,7 +1084,7 @@ def get_app_name(hostname): WWW_CONFIG_PATH = config("WWW_CONFIG_PATH", default=data_path("www_config")) WWW_CONFIG_REPO = config("WWW_CONFIG_REPO", default="https://github.com/mozmeao/www-config.git") -WWW_CONFIG_BRANCH = config("WWW_CONFIG_BRANCH", default="master") +WWW_CONFIG_BRANCH = config("WWW_CONFIG_BRANCH", default="main") LEGAL_DOCS_PATH = DATA_PATH / "legal_docs" LEGAL_DOCS_REPO = config("LEGAL_DOCS_REPO", default="https://github.com/mozilla/legal-docs.git") diff --git a/bedrock/sitemaps/management/commands/fetch_sitemaps.py b/bedrock/sitemaps/management/commands/fetch_sitemaps.py index 07979640cf3..bec5acd6cb7 100644 --- a/bedrock/sitemaps/management/commands/fetch_sitemaps.py +++ b/bedrock/sitemaps/management/commands/fetch_sitemaps.py @@ -22,7 +22,7 @@ def handle(self, *args, **options): self.stdout._out = StringIO() data_path = settings.SITEMAPS_PATH.joinpath("data") - repo = GitRepo(settings.SITEMAPS_PATH, settings.SITEMAPS_REPO) + repo = GitRepo(settings.SITEMAPS_PATH, settings.SITEMAPS_REPO, settings.SITEMAPS_REPO_BRANCH) repo.update() for src_path in data_path.rglob("*.*"): diff --git a/bedrock/sitemaps/management/commands/update_sitemaps_data.py b/bedrock/sitemaps/management/commands/update_sitemaps_data.py index c48e169a78c..3d766d10581 100644 --- a/bedrock/sitemaps/management/commands/update_sitemaps_data.py +++ b/bedrock/sitemaps/management/commands/update_sitemaps_data.py @@ -23,7 +23,7 @@ def handle(self, *args, **options): if options["quiet"]: self.stdout._out = StringIO() - repo = GitRepo(settings.SITEMAPS_PATH, settings.SITEMAPS_REPO, name="Sitemaps") + repo = GitRepo(settings.SITEMAPS_PATH, settings.SITEMAPS_REPO, settings.SITEMAPS_REPO_BRANCH, name="Sitemaps") self.stdout.write("Updating git repo") repo.update() if not (options["force"] or repo.has_changes()): diff --git a/bedrock/utils/tests/test_git.py b/bedrock/utils/tests/test_git.py index 0fccbb8eee8..23145e1d1da 100644 --- a/bedrock/utils/tests/test_git.py +++ b/bedrock/utils/tests/test_git.py @@ -79,7 +79,7 @@ def test_git_clone(): g.clone() git_mock["path"].mkdir.assert_called_with(parents=True, exist_ok=True) - git_mock["git"].assert_called_with("clone", "--depth", "1", "--branch", "master", "https://example.com", ".") + git_mock["git"].assert_called_with("clone", "--depth", "1", "--branch", "main", "https://example.com", ".") @patch.object(git, "rmtree") diff --git a/bin/open-ftl-pr.sh b/bin/open-ftl-pr.sh index 238487a9aec..34fc24954f0 100755 --- a/bin/open-ftl-pr.sh +++ b/bin/open-ftl-pr.sh @@ -17,5 +17,6 @@ source docker/bin/set_git_env_vars.sh docker run --rm \ -e FLUENT_REPO_AUTH \ -e FLUENT_L10N_TEAM_REPO \ + -e FLUENT_L10N_TEAM_REPO_BRANCH \ "$DEPLOYMENT_DOCKER_IMAGE" \ python manage.py open_ftl_pr diff --git a/lib/l10n_utils/management/commands/_ftl_repo_base.py b/lib/l10n_utils/management/commands/_ftl_repo_base.py index 64a3b43e5e5..ec0e57f4059 100644 --- a/lib/l10n_utils/management/commands/_ftl_repo_base.py +++ b/lib/l10n_utils/management/commands/_ftl_repo_base.py @@ -24,8 +24,8 @@ def handle(self, *args, **options): if options["quiet"]: self.stdout._out = StringIO() - self.l10n_repo = GitRepo(settings.FLUENT_L10N_TEAM_REPO_PATH, settings.FLUENT_L10N_TEAM_REPO_URL) - self.meao_repo = GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL) + self.l10n_repo = GitRepo(settings.FLUENT_L10N_TEAM_REPO_PATH, settings.FLUENT_L10N_TEAM_REPO_URL, settings.FLUENT_L10N_TEAM_REPO_BRANCH) + self.meao_repo = GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL, settings.FLUENT_REPO_BRANCH) def update_l10n_team_files(self): try: diff --git a/lib/l10n_utils/management/commands/l10n_update.py b/lib/l10n_utils/management/commands/l10n_update.py index f00f2f55b98..337f251f016 100644 --- a/lib/l10n_utils/management/commands/l10n_update.py +++ b/lib/l10n_utils/management/commands/l10n_update.py @@ -25,7 +25,7 @@ def handle(self, *args, **options): self.update_fluent_files(options["clean"]) def update_fluent_files(self, clean=False): - repo = GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL) + repo = GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL, settings.FLUENT_REPO_BRANCH) if clean: repo.reclone() else: diff --git a/lib/l10n_utils/management/commands/open_ftl_pr.py b/lib/l10n_utils/management/commands/open_ftl_pr.py index 684d6a823c4..4421d3919fb 100644 --- a/lib/l10n_utils/management/commands/open_ftl_pr.py +++ b/lib/l10n_utils/management/commands/open_ftl_pr.py @@ -129,7 +129,7 @@ def open_pr(self): pr = self.github.create_pull( title=title, body=body, - base="master", + base=self.l10n_repo.branch_name, head=self.branch_name, ) self.stdout.write(f"Opened a pull-request: {pr.html_url}")