Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sync/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from . import log
from .env import Environment
from .errors import AbortError
from .lando import git2hg
from .lando import git2hg, hg2git
from .repos import cinnabar, cinnabar_map, pygit2_get

from typing import Dict
Expand Down Expand Up @@ -215,6 +215,12 @@ def canonical_rev(self) -> str:
return self.cinnabar.git2hg(self.sha1)
return self.sha1

@property
def canonical_rev_git(self) -> str:
if self.cinnabar:
raise ValueError(f"Commit {self.sha1} doesn't have a canonical git SHA1")
return self.sha1

@property
def msg(self) -> bytes:
return self.pygit2_commit.raw_message
Expand Down Expand Up @@ -539,6 +545,16 @@ def bug(self) -> int | None:
assert isinstance(bugs[0], int)
return bugs[0]

@property
def canonical_rev_git(self) -> str:
if self.cinnabar:
if "gecko-commit-git" not in self.notes:
self.notes["gecko-commit-git"] = hg2git(self.sha1)
sha1 = self.notes["gecko-commit-git"]
assert sha1 is not None
return sha1
return self.sha1

def has_wpt_changes(self) -> bool:
prefix = env.config["gecko"]["path"]["wpt"]
return not self.is_empty(prefix)
Expand Down
28 changes: 15 additions & 13 deletions sync/lando.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import json
import urllib.request
import requests

from .env import Environment
from . import log

env = Environment()

logger = log.get_logger(__name__)

def hg2git(hg_hash: str) -> str:
response = requests.get(env.config["lando"]["api_url"] + "/hg2git/firefox/" + hg_hash)
data = response.json()
assert isinstance(data, dict)
assert isinstance(data["git_hash"], str)

return data["git_hash"]


def git2hg(git_hash: str) -> str:
response = urllib.request.urlopen(
env.config["lando"]["api_url"] + "/git2hg/firefox/" + git_hash
) # nosec B310
data = response.read()
map = json.loads(data.decode("utf-8"))
assert isinstance(map, dict)
assert isinstance(map["hg_hash"], str)

return map["hg_hash"]
response = requests.get(env.config["lando"]["api_url"] + "/git2hg/firefox/" + git_hash)
data = response.json()
assert isinstance(data, dict)
assert isinstance(data["hg_hash"], str)

return data["hg_hash"]
5 changes: 4 additions & 1 deletion sync/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ def repository(self) -> str:
def add_commit(self, gecko_commit: GeckoCommit) -> tuple[Commit | None, bool]:
git_work = self.wpt_worktree.get()

metadata = {"gecko-commit": gecko_commit.canonical_rev}
metadata = {
"gecko-commit": gecko_commit.canonical_rev,
"gecko-commit-git": gecko_commit.canonical_rev_git,
}

if os.path.exists(os.path.join(git_work.working_dir, gecko_commit.canonical_rev + ".diff")):
# If there's already a patch file here then don't try to create a new one
Expand Down
10 changes: 8 additions & 2 deletions test/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ def test_next_try_push_infra_fail_try_rebase(
bookmarks="mozilla/central",
)
downstream.update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
upstream.gecko_push(git_gecko, git_wpt, "mozilla-central", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value="test_revision"):
upstream.gecko_push(
git_gecko, git_wpt, "mozilla-central", rev, raise_on_error=True
)

sync.data["affected-tests"] = {"testharness": ["example"]}
sync.data["skip"] = False
Expand Down Expand Up @@ -475,7 +478,10 @@ def test_next_try_push_infra_fail_try_rebase_failed(
bookmarks="mozilla/central",
)
downstream.update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
upstream.gecko_push(git_gecko, git_wpt, "mozilla-central", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value="test_revision"):
upstream.gecko_push(
git_gecko, git_wpt, "mozilla-central", rev, raise_on_error=True
)

try_push = sync.next_try_push(try_cls=MockTryCls)
with try_push.as_mut(lock):
Expand Down
16 changes: 11 additions & 5 deletions test/test_landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def test_landing_reapply(
rev = upstream_gecko_commit(test_changes=test_changes, bug=1111, message=b"Add change1 file")

update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value="test_revision"):
pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
sync_1 = pushed.pop()

# Update central
Expand All @@ -359,7 +360,8 @@ def test_landing_reapply(
rev = upstream_gecko_commit(test_changes=test_changes, bug=1112, message=b"Add change2 file")

update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value="test_revision"):
pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
sync_2 = pushed.pop()

hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)
Expand Down Expand Up @@ -393,7 +395,8 @@ def test_landing_reapply(
rev = upstream_gecko_commit(test_changes=test_changes, bug=1113, message=b"Add change3 file")

update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value="test_revision"):
pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)

# Now start a landing
with patch.object(trypush.TryCommit, "read_treeherder", autospec=True) as mock_read:
Expand Down Expand Up @@ -541,7 +544,9 @@ def create_and_upstream_gecko_bug(
rev = upstream_gecko_commit(test_changes=test_changes, bug=bug, message=b"Change CONFIG")

update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
git_rev = "test_revision"
with patch("sync.commit.hg2git", return_value=git_rev):
upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)

syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
sync = syncs["open"].pop()
Expand All @@ -550,7 +555,8 @@ def create_and_upstream_gecko_bug(
hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
upstream.gecko_push(git_gecko, git_wpt, "mozilla-central", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value=git_rev):
upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)

# Set commits PR number so they will be skipped.
for commit_item in git_wpt.iter_commits(sync.wpt_commits.head.sha1):
Expand Down
4 changes: 3 additions & 1 deletion test/test_sync.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import git
import pytest
from unittest.mock import patch
from sync import index, upstream
from sync.gitutils import update_repositories
from sync.lock import SyncLock
Expand All @@ -12,7 +13,8 @@ def test_delete(env, git_gecko, git_wpt, upstream_gecko_commit):
rev = upstream_gecko_commit(test_changes=test_changes, bug=bug, message=b"Change README")

update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
_, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)
with patch("sync.commit.hg2git", return_value="test_revision"):
_, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)

sync = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug, flat=True).pop()
process_name = sync.process_name
Expand Down
Loading
Loading