Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1758000: use repo root and Phabricator repo IDs to retrieve callsign #17

Merged
merged 1 commit into from
Mar 15, 2022
Merged
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
20 changes: 17 additions & 3 deletions hgext/differentiator.py
Original file line number Diff line number Diff line change
@@ -3,10 +3,12 @@

import json
import os
import pathlib
import re
import subprocess

from mercurial import (
error,
registrar,
templatekw,
)
@@ -20,10 +22,22 @@

def get_local_repo_callsign(repo) -> str:
"""Returns the callsign from the local repository's `.arcconfig` file."""
ctx = repo[b"tip"]
arcconfig = json.loads(repo.filectx(b".arcconfig", changeid=ctx.node()).data())
repo_path = pathlib.Path(repo.root)
repo_id = int(repo_path.name)

return arcconfig["repository.callsign"].encode("utf-8")
# Search Conduit for all repositories.
response = call_conduit("diffusion.repository.search", {})

# Retrieve the repo objects.
repo_objects = response["response"]["data"]

for repo_object in repo_objects:
# If the repo ID we parsed from the working directory matches the
# ID of the current object, return the callsign for this object.
if repo_id == repo_object["id"]:
return repo_object["fields"]["callsign"]

raise error.Abort(b"No repo found with ID %s" % repo_id)


def call_conduit(method: str, params: dict) -> dict: