Beispiel #1
0
def install_certificate(repo, args):
    """Asks user to enter the Phabricator API Token.

    Named for parity with arc's corresponding command.

    The response is saved in the ~/.arcrc file; moz-phab itself doesn't do any
    verification/parsing of the provided string (verification happens by passing
    it to the Phabricator server)."""
    logger.info(
        "LOGIN TO PHABRICATOR\nOpen this page in your browser and login "
        "to Phabricator if necessary:\n\n%s/conduit/login/\n",
        conduit.repo.phab_url,
    )
    token = prompt("Paste API Token from that page: ")

    # Call a method that requires authentication to both verify the token and clear
    # the default one-hour expiration of newly created tokens.
    with wait_message("Verifying token"):
        who = conduit.whoami(api_token=token)
    conduit.save_api_token(token)
    logger.info("Configured moz-phab for %s", who["realName"])
Beispiel #2
0
def show_commit_stack(
    commits,
    wip=None,
    validate=True,
    ignore_reviewers=False,
    show_rev_urls=False,
    show_updated_only=False,
):
    """Log the commit stack in a human readable form."""

    # keep output in columns by sizing the action column to the longest rev + 1 ("D")
    max_len = (max(len(c.get("rev-id", "") or "")
                   for c in commits) + 1 if commits else "")
    action_template = "(%" + str(max_len) + "s)"

    if validate:
        # preload all revisions
        ids = [int(c["rev-id"]) for c in commits if c.get("rev-id")]
        if ids:
            with wait_message("Loading existing revisions..."):
                revisions = conduit.get_revisions(ids=ids)

            # preload diffs
            with wait_message("Loading diffs..."):
                diffs = conduit.get_diffs(
                    [r["fields"]["diffPHID"] for r in revisions])

    for commit in reversed(commits):
        if show_updated_only and not commit["submit"]:
            continue

        closed = False
        change_bug_id = False
        is_author = True
        revision = None
        wip_removed = False
        wip_set = False
        reviewers_added = False

        if commit.get("rev-id"):
            action = action_template % ("D" + commit["rev-id"])
            if validate:
                revisions = conduit.get_revisions(ids=[int(commit["rev-id"])])
                if len(revisions) > 0:
                    revision = revisions[0]

                    # Check if target bug ID is the same as in the Phabricator revision
                    change_bug_id = ("bugzilla.bug-id" in revision["fields"]
                                     and revision["fields"]["bugzilla.bug-id"]
                                     and
                                     (commit["bug-id"] !=
                                      revision["fields"]["bugzilla.bug-id"]))

                    # Check if revision is closed
                    closed = revision["fields"]["status"]["closed"]

                    # Check if comandeering is required
                    whoami = conduit.whoami()
                    if "authorPHID" in revision["fields"] and (
                            revision["fields"]["authorPHID"] !=
                            whoami["phid"]):
                        is_author = False

                    # Do we remove "Changes Planned" status?
                    wip_removed = (not wip
                                   and revision["fields"]["status"]["value"]
                                   == "changes-planned")

                    # Do we set "Changes Planned" status?
                    wip_set = (wip and revision["fields"]["status"]["value"] !=
                               "changes-planned")

                    # Any reviewers added to a revision without them?
                    reviewers_added = bool(
                        not revision["attachments"]["reviewers"]["reviewers"]
                        and commit["reviewers"]["granted"])

                    # if SHA1 hasn't changed
                    # and we're not changing the WIP status
                    # and we're not adding reviewers to a revision without reviewers
                    # and we're not changing the bug-id
                    sha1_changed = (
                        commit["node"] != diffs[revision["fields"]["diffPHID"]]
                        ["attachments"]["commits"]["commits"][0]["identifier"])
                    if (not sha1_changed and not wip_removed and not wip_set
                            and not reviewers_added and not change_bug_id
                            and not closed):
                        commit["submit"] = False

        else:
            action = action_template % "New"

        logger.info("%s %s %s", action, commit["name"],
                    commit["title-preview"])
        if validate:
            if not commit["submit"]:
                logger.info(
                    " * This revision is not changed and will not be submitted."
                )

            else:
                if wip_removed:
                    logger.warning(
                        '!! "Changes Planned" status will change to "Request Review"'
                    )

                if change_bug_id:
                    logger.warning(
                        "!! Bug ID in Phabricator revision will change from %s to %s",
                        revision["fields"]["bugzilla.bug-id"],
                        commit["bug-id"],
                    )

                if not is_author:
                    logger.warning(
                        "!! You don't own this revision. Normally, you should only\n"
                        '   update revisions you own. You can "Commandeer" this\n'
                        "   revision from the web interface if you want to become\n"
                        "   the owner.")

                if closed:
                    logger.warning(
                        "!! This revision is closed!\n"
                        "   It will be reopened if submission proceeds.\n"
                        "   You can stop now and refine the stack range.")

                if not commit["bug-id"]:
                    logger.warning("!! Missing Bug ID")

                if commit["bug-id-orig"] and commit["bug-id"] != commit[
                        "bug-id-orig"]:
                    logger.warning(
                        "!! Bug ID changed from %s to %s",
                        commit["bug-id-orig"],
                        commit["bug-id"],
                    )

                if (not ignore_reviewers
                        and not commit["reviewers"]["granted"] +
                        commit["reviewers"]["request"]):
                    logger.warning("!! Missing reviewers")

        if show_rev_urls and commit["rev-id"]:
            logger.warning("-> %s/D%s", conduit.repo.phab_url,
                           commit["rev-id"])
Beispiel #3
0
def show_commit_stack(
    commits,
    validate=True,
    show_rev_urls=False,
    show_updated_only=False,
):
    """Log the commit stack in a human readable form."""

    # keep output in columns by sizing the action column to the longest rev + 1 ("D")
    max_len = (max(len(c.get("rev-id", "") or "")
                   for c in commits) + 1 if commits else "")
    action_template = "(%" + str(max_len) + "s)"

    if validate:
        # preload all revisions
        ids = [int(c["rev-id"]) for c in commits if c.get("rev-id")]
        if ids:
            with wait_message("Loading existing revisions..."):
                revisions = conduit.get_revisions(ids=ids)

            # preload diffs
            with wait_message("Loading diffs..."):
                diffs = conduit.get_diffs(
                    [r["fields"]["diffPHID"] for r in revisions])

    for commit in reversed(commits):
        if show_updated_only and not commit["submit"]:
            continue

        revision_is_closed = False
        revision_is_wip = False
        bug_id_changed = False
        is_author = True
        revision = None

        if commit.get("rev-id"):
            action = action_template % ("D" + commit["rev-id"])

            if validate:
                revisions = conduit.get_revisions(ids=[int(commit["rev-id"])])
                if revisions:
                    revision = revisions[0]
                    fields = revision["fields"]

                    # WIP if either in changes-planned state, or if the revision has the
                    # `draft` flag set.
                    revision_is_wip = (fields["status"]["value"]
                                       == "changes-planned"
                                       or fields["isDraft"])

                    # Check if target bug ID is the same as in the Phabricator revision
                    bug_id_changed = fields.get("bugzilla.bug-id") and (
                        commit["bug-id"] != fields["bugzilla.bug-id"])

                    # Check if revision is closed
                    revision_is_closed = fields["status"]["closed"]

                    # Check if comandeering is required
                    with wait_message("Figuring out who you are..."):
                        whoami = conduit.whoami()
                    if "authorPHID" in fields and (fields["authorPHID"] !=
                                                   whoami["phid"]):
                        is_author = False

                    # Any reviewers added to a revision without them?
                    reviewers_added = bool(
                        not revision["attachments"]["reviewers"]["reviewers"]
                        and commit["reviewers"]["granted"])

                    # if SHA1 hasn't changed
                    # and we're not changing the WIP or draft status
                    # and we're not adding reviewers to a revision without reviewers
                    # and we're not changing the bug-id
                    diff_phid = fields["diffPHID"]
                    diff_commits = diffs[diff_phid]["attachments"]["commits"][
                        "commits"]
                    sha1_changed = (
                        not diff_commits
                        or commit["node"] != diff_commits[0]["identifier"])
                    if (not sha1_changed and commit["wip"] == revision_is_wip
                            and not reviewers_added and not bug_id_changed
                            and not revision_is_closed):
                        commit["submit"] = False

        else:
            action = action_template % "New"

        logger.info("%s %s %s", action, commit["name"],
                    commit["title-preview"])
        if validate:
            if not commit["submit"]:
                logger.info(
                    " * This revision has not changed and will not be submitted."
                )
                continue

            if revision:
                if not commit["wip"] and revision_is_wip:
                    logger.warning(
                        '!! "Changes Planned" status will change to "Request Review"'
                    )
                if commit["wip"] and not revision_is_wip:
                    logger.warning(
                        '!! "Request Review" status will change to "Changes Planned"'
                    )

            if bug_id_changed:
                logger.warning(
                    "!! Bug ID in Phabricator revision will change from %s to %s",
                    revision["fields"]["bugzilla.bug-id"],
                    commit["bug-id"],
                )

            if not is_author:
                logger.warning(
                    "!! You don't own this revision. Normally, you should only\n"
                    '   update revisions you own. You can "Commandeer" this\n'
                    "   revision from the web interface if you want to become\n"
                    "   the owner.")

            if revision_is_closed:
                logger.warning(
                    "!! This revision is closed!\n"
                    "   It will be reopened if submission proceeds.\n"
                    "   You can stop now and refine the stack range.")

            if not commit["bug-id"]:
                logger.warning("!! Missing Bug ID")

            if commit["bug-id-orig"] and commit["bug-id"] != commit[
                    "bug-id-orig"]:
                logger.warning(
                    "!! Bug ID changed from %s to %s",
                    commit["bug-id-orig"],
                    commit["bug-id"],
                )

            if not commit["has-reviewers"]:
                logger.warning("!! Missing reviewers")
                if commit["wip"]:
                    logger.warning(
                        '   It will be submitted as "Changes Planned".\n'
                        "   Run submit again with --no-wip to prevent this.")

        if show_rev_urls and commit["rev-id"]:
            logger.warning("-> %s/D%s", conduit.repo.phab_url,
                           commit["rev-id"])
Beispiel #4
0
def show_commit_stack(commits,
                      validate=True,
                      ignore_reviewers=False,
                      show_rev_urls=False):
    """Log the commit stack in a human readable form."""

    # keep output in columns by sizing the action column to the longest rev + 1 ("D")
    max_len = (max(len(c.get("rev-id", "") or "")
                   for c in commits) + 1 if commits else "")
    action_template = "(%" + str(max_len) + "s)"

    if validate:
        # preload all revisions
        ids = [int(c["rev-id"]) for c in commits if c.get("rev-id")]
        if ids:
            with wait_message("Loading existing revisions..."):
                conduit.get_revisions(ids=ids)

    for commit in reversed(commits):
        closed = False
        change_bug_id = False
        is_author = True
        revision = None

        if commit.get("rev-id"):
            action = action_template % ("D" + commit["rev-id"])
            if validate:
                revisions = conduit.get_revisions(ids=[int(commit["rev-id"])])
                if len(revisions) > 0:
                    revision = revisions[0]

                    # Check if target bug ID is the same as in the Phabricator revision
                    change_bug_id = ("bugzilla.bug-id" in revision["fields"]
                                     and revision["fields"]["bugzilla.bug-id"]
                                     and
                                     (commit["bug-id"] !=
                                      revision["fields"]["bugzilla.bug-id"]))

                    # Check if revision is closed
                    closed = revision["fields"]["status"]["closed"]

                    # Check if comandeering is required
                    whoami = conduit.whoami()
                    if "authorPHID" in revision["fields"] and (
                            revision["fields"]["authorPHID"] !=
                            whoami["phid"]):
                        is_author = False
        else:
            action = action_template % "New"

        logger.info("%s %s %s", action, commit["name"],
                    commit["title-preview"])
        if validate:
            if change_bug_id:
                logger.warning(
                    "!! Bug ID in Phabricator revision will be changed from %s to %s",
                    revision["fields"]["bugzilla.bug-id"],
                    commit["bug-id"],
                )

            if not is_author:
                logger.warning(
                    "!! You don't own this revision. Normally, you should only\n"
                    '   update revisions you own. You can "Commandeer" this\n'
                    "   revision from the web interface if you want to become\n"
                    "   the owner.")

            if closed:
                logger.warning(
                    "!! This revision is closed!\n"
                    "   It will be reopened if submission proceeds.\n"
                    "   You can stop now and refine the stack range.")

            if not commit["bug-id"]:
                logger.warning("!! Missing Bug ID")

            if commit["bug-id-orig"] and commit["bug-id"] != commit[
                    "bug-id-orig"]:
                logger.warning(
                    "!! Bug ID changed from %s to %s",
                    commit["bug-id-orig"],
                    commit["bug-id"],
                )

            if (not ignore_reviewers and not commit["reviewers"]["granted"] +
                    commit["reviewers"]["request"]):
                logger.warning("!! Missing reviewers")

        if show_rev_urls and commit["rev-id"]:
            logger.warning("-> %s/D%s", conduit.repo.phab_url,
                           commit["rev-id"])