Skip to content

Commit 523d5d6

Browse files
authored
repo_synchroniser: add configurable tag message (bug 1961090) (#34)
1 parent 90cabbf commit 523d5d6

File tree

11 files changed

+86
-12
lines changed

11 files changed

+86
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ source_url = "/clones/test-repo-git"
121121
tag_pattern = "^FIREFOX_(\\d+)\\.\\d+\\.\\d+esr_(BUILD\\d+|RELEASE)$"
122122
destination_url = "/clones/mozilla-esr\\1"
123123
tags_destination_branch = "default"
124+
# Default
125+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
124126
```
125127

126128
### Pulse parameters

config-development.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ source_url = "https://github.com/mozilla-conduit/ff-test"
3333
tag_pattern = "^(DEV)_(BETA|NIGHTLY)_(\\d+)_(BASE|END)$"
3434
destination_url = "ssh://hg.mozilla.org/conduit-testing/ff-test-dev"
3535
tags_destination_branch = "dev-tags"
36+
# Default
37+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
3638

3739

3840
[[tracked_repositories]]
@@ -50,3 +52,5 @@ source_url = "https://github.com/mozilla-conduit/test-repo"
5052
tag_pattern = "^(DEV)_(BETA|NIGHTLY)_(\\d+)_(BASE|END)$"
5153
destination_url = "ssh://hg.mozilla.org/conduit-testing/test-repo-github-dev"
5254
tags_destination_branch = "dev-tags"
55+
# Default
56+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"

config-docker.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ source_url = "/clones/test-repo-git"
3030
tag_pattern = "^FIREFOX_BETA_(\\d+)_(BASE|END)$"
3131
destination_url = "/clones/mozilla-beta"
3232
tags_destination_branch = "tags"
33+
# Default
34+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
3335

3436
# ESR
3537
[[branch_mappings]]
@@ -43,4 +45,5 @@ source_url = "/clones/test-repo-git"
4345
tag_pattern = "^FIREFOX_(\\d+)\\.\\d+\\.\\d+esr_(BUILD\\d+|RELEASE)$"
4446
destination_url = "/clones/mozilla-esr\\1"
4547
tags_destination_branch = "default"
46-
48+
# Default
49+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"

config-production.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ source_url = "https://github.com/mozilla-firefox/firefox"
5050
tag_pattern = "^(FIREFOX|DEVEDITION|FIREFOX-ANDROID)_(\\d+(_\\d+)+)b\\d+_(BUILD\\d+|RELEASE)$"
5151
destination_url = "ssh://hg.mozilla.org/releases/mozilla-beta/"
5252
tags_destination_branch = "tags"
53+
# Default
54+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
5355

5456

5557
#
@@ -68,6 +70,8 @@ source_url = "https://github.com/mozilla-firefox/firefox"
6870
tag_pattern = "^(FIREFOX|DEVEDITION|FIREFOX-ANDROID)_(\\d+)(_\\d+)+esr_(BUILD\\d+|RELEASE)$"
6971
destination_url = "ssh://hg.mozilla.org/releases/mozilla-esr\\2/"
7072
tags_destination_branch = "tags"
73+
# Default
74+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
7175

7276
#
7377
# relbranches
@@ -95,6 +99,8 @@ source_url = "https://github.com/mozilla-firefox/firefox"
9599
tag_pattern = "^(FIREFOX|DEVEDITION|FIREFOX-ANDROID)_(BETA|NIGHTLY)_(\\d+)_(BASE|END)$"
96100
destination_url = "ssh://hg.mozilla.org/releases/mozilla-central/"
97101
tags_destination_branch = "tags"
102+
# Default
103+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
98104

99105

100106
#
@@ -112,6 +118,8 @@ source_url = "https://github.com/mozilla-firefox/firefox"
112118
tag_pattern = "^(FIREFOX|DEVEDITION|FIREFOX-ANDROID)_(\\d+(_\\d+)+)_(BUILD\\d+|RELEASE)$"
113119
destination_url = "ssh://hg.mozilla.org/releases/mozilla-release/"
114120
tags_destination_branch = "tags"
121+
# Default
122+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
115123

116124
#
117125
# relbranches
@@ -143,6 +151,8 @@ source_url = "https://github.com/mozilla-firefox/infra-testing"
143151
tag_pattern = ".*"
144152
destination_url = "ssh://hg.mozilla.org/conduit-testing/m-c/"
145153
tags_destination_branch = "tags"
154+
# Default
155+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
146156

147157

148158
#####################
@@ -164,3 +174,5 @@ source_url = "https://github.com/mozilla-conduit/review/"
164174
tag_pattern = ".*"
165175
destination_url = "ssh://hg.mozilla.org/conduit-testing/review/"
166176
tags_destination_branch = "tags"
177+
# Default
178+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"

config-staging.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ source_url = "https://github.com/mozilla-conduit/ff-test"
3333
tag_pattern = "^(STAGE)_(BETA|NIGHTLY)_(\\d+)_(BASE|END)$"
3434
destination_url = "ssh://hg.mozilla.org/conduit-testing/ff-test-stage"
3535
tags_destination_branch = "stage-tags"
36+
# Default
37+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"
3638

3739

3840
[[tracked_repositories]]
@@ -50,3 +52,5 @@ source_url = "https://github.com/mozilla-conduit/test-repo"
5052
tag_pattern = "^(STAGE)_(BETA|NIGHTLY)_(\\d+)_(BASE|END)$"
5153
destination_url = "ssh://hg.mozilla.org/conduit-testing/test-repo-github-stage"
5254
tags_destination_branch = "stage-tags"
55+
# Default
56+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"

config.toml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ source_url = "/home/fbessou/dev/MOZI/fake-forge/git/firefox-releases"
2929
tag_pattern = "^FIREFOX_BETA_(\\d+)_(BASE|END)$"
3030
destination_url = "/home/fbessou/dev/MOZI/fake-forge/hg/mozilla-beta"
3131
tags_destination_branch = "tags"
32+
# Default
33+
#tag_message_suffix = "a=tagging CLOSED TREE DONTBUILD"

git_hg_sync/mapping.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from git_hg_sync.events import Push
1010

11+
DEFAULT_TAG_MESSAGE_SUFFIX = "a=tagging CLOSED TREE DONTBUILD"
12+
1113

1214
@dataclass
1315
class SyncBranchOperation:
@@ -26,6 +28,7 @@ class SyncTagOperation:
2628
# Destination (hg)
2729
tag: str
2830
tags_destination_branch: str
31+
tag_message_suffix: str
2932

3033

3134
SyncOperation: TypeAlias = SyncBranchOperation | SyncTagOperation
@@ -88,6 +91,7 @@ class TagMapping(Mapping):
8891
tag_pattern: str
8992
destination_url: str
9093
tags_destination_branch: str
94+
tag_message_suffix: str = DEFAULT_TAG_MESSAGE_SUFFIX
9195

9296
@cached_property
9397
def _tag_pattern(self) -> re.Pattern:
@@ -108,6 +112,7 @@ def match(self, event: Push) -> Sequence[MappingMatch]:
108112
tag=tag_name,
109113
source_commit=commit,
110114
tags_destination_branch=self.tags_destination_branch,
115+
tag_message_suffix=self.tag_message_suffix,
111116
),
112117
)
113118
)

git_hg_sync/repo_synchronizer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
logger = get_proxy_logger("sync_repo")
1212

13-
GIT_SSH_COMMAND_ENV_VAR = "GIT_SSH_COMMAND"
1413
REQUEST_USER_ENV_VAR = "AUTOLAND_REQUEST_USER"
1514

1615

@@ -46,8 +45,7 @@ def _get_clone_repo(self) -> Repo:
4645
return repo
4746

4847
def _commit_has_mercurial_metadata(self, repo: Repo, git_commit: str) -> bool:
49-
stdout = repo.git.cinnabar(["git2hg", git_commit])
50-
return not all(char == "0" for char in stdout.strip())
48+
return not all(char == "0" for char in self._git2hg(repo, git_commit))
5149

5250
def _fetch_all_from_remote(self, repo: Repo, remote: str) -> None:
5351
try:
@@ -142,10 +140,14 @@ def sync(
142140
repo, tag_operation.source_commit
143141
):
144142
raise MercurialMetadataNotFoundError(tag_operation)
143+
hg_sha = self._git2hg(repo, tag_operation.source_commit)
144+
tag_message = f"No bug - Tagging {hg_sha} with {tag_operation.tag} {tag_operation.tag_message_suffix}"
145145
try:
146146
repo.git.cinnabar(
147147
[
148148
"tag",
149+
"--message",
150+
tag_message,
149151
"--onto",
150152
f"refs/heads/{tag_operation.tags_destination_branch}",
151153
tag_operation.tag,
@@ -161,3 +163,6 @@ def sync(
161163
"pushing branch and tags to destination",
162164
lambda: repo.git.push(*push_args),
163165
)
166+
167+
def _git2hg(self, repo: Repo, git_commit: str) -> str:
168+
return repo.git.cinnabar(["git2hg", git_commit]).strip()

tests/test_integration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99
from git import Repo
1010
from mozlog import get_proxy_logger
11-
from utils import hg_cat
11+
from utils import hg_cat, hg_log, hg_rev
1212

1313
from git_hg_sync.__main__ import get_connection, get_queue, start_app
1414
from git_hg_sync.config import Config, PulseConfig
@@ -114,3 +114,9 @@ def test_full_app(
114114
# test
115115
assert "BAR CONTENT" in hg_cat(hg_remote_repo_path, "bar.txt", "default")
116116
assert "FIREFOX_128_0esr_RELEASE" in hg_cat(hg_remote_repo_path, ".hgtags", "tags")
117+
118+
# test tag commit message
119+
tag_log = hg_log(hg_remote_repo_path, "tags", ["-T", "{desc}"])
120+
assert "No bug - Tagging" in tag_log
121+
assert "FIREFOX_128_0esr_RELEASE" in tag_log
122+
assert hg_rev(hg_remote_repo_path, "default") in tag_log

tests/test_repo_synchronizer.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55
from git import Repo
6-
from utils import hg_cat
6+
from utils import hg_cat, hg_log, hg_rev
77

88
from git_hg_sync.__main__ import get_connection, get_queue
99
from git_hg_sync.config import PulseConfig, TrackedRepository
@@ -38,6 +38,11 @@ def test_sync_process_(
3838
repo.index.add([foo_path])
3939
repo.index.commit("add foo.txt")
4040

41+
branch = "bar"
42+
tag_branch = "tags"
43+
tag = "mytag"
44+
tag_suffix = "some suffix"
45+
4146
# Push to mercurial repository
4247
subprocess.run(
4348
[
@@ -71,19 +76,28 @@ def test_sync_process_(
7176
git_local_repo_path = tmp_path / "clones" / "myrepo"
7277
syncrepos = RepoSynchronizer(git_local_repo_path, str(git_remote_repo_path))
7378
operations: list[SyncBranchOperation | SyncTagOperation] = [
74-
SyncBranchOperation(source_commit=git_commit_sha, destination_branch="bar"),
79+
SyncBranchOperation(source_commit=git_commit_sha, destination_branch=branch),
7580
SyncTagOperation(
76-
source_commit=git_commit_sha, tag="mytag", tags_destination_branch="tags"
81+
source_commit=git_commit_sha,
82+
tag=tag,
83+
tags_destination_branch=tag_branch,
84+
tag_message_suffix=tag_suffix,
7785
),
7886
]
7987

8088
request_user = "request_user@example.com"
8189
syncrepos.sync(str(hg_remote_repo_path), operations, request_user)
8290

8391
# test
84-
assert "BAR CONTENT" in hg_cat(hg_remote_repo_path, "bar.txt", "bar")
85-
86-
assert "BAR CONTENT" in hg_cat(hg_remote_repo_path, "bar.txt", "mytag")
92+
assert "BAR CONTENT" in hg_cat(hg_remote_repo_path, "bar.txt", branch)
93+
assert "BAR CONTENT" in hg_cat(hg_remote_repo_path, "bar.txt", tag)
94+
95+
# test tag commit message
96+
tag_log = hg_log(hg_remote_repo_path, tag_branch, ["-T", "{desc}"])
97+
assert "No bug - Tagging" in tag_log
98+
assert tag_suffix in tag_log
99+
assert tag in tag_log
100+
assert hg_rev(hg_remote_repo_path, branch) in tag_log
87101

88102

89103
def test_get_connection_and_queue(pulse_config: PulseConfig) -> None:

0 commit comments

Comments
 (0)