def publish()

in integration/run.py [0:0]


def publish(repo_dir, repo_callsign, revision):
    """
    Publish diff on Phabricator
    from the base of the repository
    """

    def _dump(path, payload):
        if os.path.exists(path):
            logger.info("Skip overriding arc config", path=path)
            return

        with open(path, "w") as f:
            json.dump(payload, f, indent=4, sort_keys=True)
            logger.info("Setup arc configuration", path=path)

    # Write arcrc config files
    phab_url = taskcluster.secrets["phabricator"]["url"]
    base_url = phab_url.replace("/api/", "/")
    phab_token = taskcluster.secrets["phabricator"]["token"]
    _dump(os.path.expanduser("~/.arcrc"), {"hosts": {phab_url: {"token": phab_token}}})
    _dump(
        os.path.join(repo_dir, ".hg", ".arcconfig"),
        {"repository.callsign": repo_callsign, "phabricator.uri": base_url},
    )

    logger.info(
        "Publishing a revision on phabricator", url=phab_url, local_revision=revision
    )
    cmd = ["moz-phab", "submit", "--yes", "--no-lint", "--no-bug", f"{revision}"]
    output = subprocess.check_output(cmd, cwd=repo_dir)

    # Parse output to get the revision url on the last line
    last_line = output.splitlines()[-1]
    match = re.search(rf"^-> ({base_url}D\d+)$", last_line.decode("utf-8"))
    assert match is not None, f"No revision found in moz-phab output:\n{output}"

    return match.group(1)