示例#1
0
def report(api_key, api_root, artifact_path, dry_run=False):
    """
    Report resuls to bugzilla

    :param api_key: BZ_API_KEY
    :param api_root: BZ_API_ROOT
    :param artifact_path: Path to processor artifact
    :param dry_run: Boolean indicating if bugs should be updated
    """
    if in_taskcluster():
        task = queue.task(os.getenv("TASK_ID"))
        dependencies = task.get("dependencies")
        data = queue.getLatestArtifact(dependencies[-1], artifact_path)
    else:
        with open(artifact_path, "r") as file:
            data = json.load(file)

    bug_number = data["bug_number"]
    diff = data["diff"]

    if not dry_run:
        bugsy = Bugsy(api_key=api_key, bugzilla_url=api_root)
        bugsy.request(f"bug/{bug_number}", "PUT", json=diff)

    # Log changes
    comment = diff.pop("comment", None)
    LOG.info(f"Commit changes ({bug_number}): {json.dumps(diff)}")

    if comment is not None:
        for line in comment["body"].splitlines():
            LOG.info(f">{line}")
示例#2
0
def main(argv=None):
    """
    Launch Bugmon

    :param argv: Command line to use instead of sys.argv (optional)
    :return:
    """
    console_init_logging()
    args = parse_args(argv)

    # Get the API root, default to bugzilla.mozilla.org
    api_root = os.environ.get("BZ_API_ROOT")
    api_key = os.environ.get("BZ_API_KEY")

    if api_root is None or api_key is None:
        raise BugException("BZ_API_ROOT and BZ_API_KEY must be set!")

    bugsy = Bugsy(api_key=api_key, bugzilla_url=api_root)

    if args.bugs:
        bug_list = ",".join(args.bugs)
        params = {"id": bug_list}
    else:
        with open(args.search) as f:
            params = json.load(f)
            params["include_fields"] = "_default"

    response = bugsy.request("bug", params=params)
    bugs = [EnhancedBug(bugsy, **bug) for bug in response["bugs"]]

    for bug in bugs:
        with tempfile.TemporaryDirectory() as temp_dir:
            try:
                bugmon = BugMonitor(bugsy, bug, temp_dir, args.dry_run)
                log.info(f"Analyzing bug {bug.id} "
                         f"(Status: {bugmon.bug.status}, "
                         f"Resolution: {bugmon.bug.resolution})")
                bugmon.process()
            except BugException as e:
                log.error(f"Error processing bug {bug.id}: {e}")