コード例 #1
0
ファイル: cli.py プロジェクト: rb1450/code-coverage
def setup_cli(ask_repository=True, ask_revision=True):
    """
    Setup CLI options parser and taskcluster bootstrap
    """
    parser = argparse.ArgumentParser(description="Mozilla Code Coverage Bot")
    if ask_repository:
        parser.add_argument("--repository",
                            default=os.environ.get("REPOSITORY"))
    if ask_revision:
        parser.add_argument("--revision", default=os.environ.get("REVISION"))
    parser.add_argument("--cache-root",
                        required=True,
                        help="Cache root, used to pull changesets")
    parser.add_argument(
        "--working-dir",
        required=True,
        help="Working dir to download artifacts and build reports",
    )
    parser.add_argument(
        "--task-name-filter",
        default="*",
        help="Filter Taskcluster tasks using a glob expression",
    )
    parser.add_argument(
        "--taskcluster-secret",
        help="Taskcluster Secret path",
        default=os.environ.get("TASKCLUSTER_SECRET"),
    )
    parser.add_argument("--taskcluster-client-id",
                        help="Taskcluster Client ID")
    parser.add_argument("--taskcluster-access-token",
                        help="Taskcluster Access token")
    args = parser.parse_args()

    # Auth on Taskcluster
    taskcluster_config.auth(args.taskcluster_client_id,
                            args.taskcluster_access_token)

    # Then load secrets
    secrets.load(args.taskcluster_secret)

    init_logger(
        "bot",
        channel=secrets.get("APP_CHANNEL", "dev"),
        PAPERTRAIL_HOST=secrets.get("PAPERTRAIL_HOST"),
        PAPERTRAIL_PORT=secrets.get("PAPERTRAIL_PORT"),
        sentry_dsn=secrets.get("SENTRY_DSN"),
    )

    return args
コード例 #2
0
def main(revision,
         cache_root,
         taskcluster_secret,
         taskcluster_client_id,
         taskcluster_access_token,
         ):
    secrets.load(taskcluster_secret, taskcluster_client_id, taskcluster_access_token)

    init_logger(config.PROJECT_NAME,
                PAPERTRAIL_HOST=secrets.get('PAPERTRAIL_HOST'),
                PAPERTRAIL_PORT=secrets.get('PAPERTRAIL_PORT'),
                SENTRY_DSN=secrets.get('SENTRY_DSN'),
                MOZDEF=secrets.get('MOZDEF'),
                )

    c = CodeCov(revision, cache_root, taskcluster_client_id, taskcluster_access_token)
    c.go()
コード例 #3
0
def main():
    args = parse_cli()

    # Auth on Taskcluster
    taskcluster_config.auth(args.taskcluster_client_id,
                            args.taskcluster_access_token)

    # Then load secrets
    secrets.load(args.taskcluster_secret)

    init_logger(
        config.PROJECT_NAME,
        channel=secrets.get("APP_CHANNEL", "dev"),
        PAPERTRAIL_HOST=secrets.get("PAPERTRAIL_HOST"),
        PAPERTRAIL_PORT=secrets.get("PAPERTRAIL_PORT"),
        sentry_dsn=secrets.get("SENTRY_DSN"),
    )

    c = CodeCov(args.repository, args.revision, args.task_name_filter,
                args.cache_root)
    c.go()
コード例 #4
0
def main():
    # CLI args
    parser = argparse.ArgumentParser()
    parser.add_argument("--nb-tasks",
                        type=int,
                        default=5,
                        help="NB of tasks to create")
    parser.add_argument("--group",
                        type=str,
                        default=slugId(),
                        help="Task group to create/update")
    parser.add_argument(
        "--dry-run",
        action="store_true",
        default=False,
        help="List actions without triggering any new task",
    )
    parser.add_argument("history",
                        type=open,
                        help="JSON payload of /v2/history endpoint")
    args = parser.parse_args()

    # Setup Taskcluster
    taskcluster_config.auth()
    secrets.load(os.environ["TASKCLUSTER_SECRET"])

    # List existing tags & commits
    print("Group", args.group)
    queue = taskcluster_config.get_service("queue")
    try:
        group = queue.listTaskGroup(args.group)
        commits = [
            task["task"]["payload"]["env"]["REVISION"]
            for task in group["tasks"]
            if task["status"]["state"] not in ("failed", "exception")
        ]
        print("Found {} commits processed in task group {}".format(
            len(commits), args.group))
    except Exception as e:
        print("Invalid task group : {}".format(e))
        commits = []

    # Read the history file
    history = json.load(args.history)

    # Load initial dates from our history
    history_dates = {
        item["changeset"]: datetime.fromtimestamp(item["date"]).date()
        for item in history
    }
    dates = [
        history_dates[commit] for commit in commits if commit in history_dates
    ]

    # Trigger a task for each commit
    nb = 0
    for commit in history:
        date = datetime.fromtimestamp(commit["date"])
        if nb >= args.nb_tasks:
            break
        if commit["changeset"] in commits:
            print(
                f"Skipping commit {commit['changeset']} from {date} : already processed"
            )
            continue

        if date.date() in dates:
            print(
                f"Skipping commit {commit['changeset']} from {date} : same day"
            )
            continue

        print(f"Triggering commit {commit['changeset']} from {date}")
        if args.dry_run:
            print(">>> No trigger on dry run")
        else:
            out = trigger_task(args.group, commit)
            print(">>>", out["status"]["taskId"])
        nb += 1
        dates.append(date.date())
コード例 #5
0
# -*- coding: utf-8 -*-
import argparse
import os

from taskcluster.utils import slugId

from code_coverage_bot.secrets import secrets
from code_coverage_bot.taskcluster import taskcluster_config

CODECOV_URL = "https://codecov.io/api/gh/marco-c/gecko-dev/commit"
HOOK_GROUP = "project-relman"
HOOK_ID = "code-coverage-{app_channel}"

taskcluster_config.auth(os.environ.get("TASKCLUSTER_CLIENT_ID"),
                        os.environ.get("TASKCLUSTER_ACCESS_TOKEN"))
secrets.load(os.environ["TASKCLUSTER_SECRET"])
queue = taskcluster_config.get_service("queue")


def list_commits(tasks):
    """
    Read the revision from an existing code coverage task
    """
    for task_id in tasks:
        try:
            task = queue.task(task_id)
            env = task["payload"]["env"]
            yield env["REPOSITORY"], env["REVISION"]
        except Exception as e:
            print("Failed to load task {}: {}".format(task_id, e))
コード例 #6
0
import requests
from taskcluster.utils import slugId

from cli_common import taskcluster
from code_coverage_bot.github import GitHubUtils
from code_coverage_bot.secrets import secrets

CODECOV_URL = 'https://codecov.io/api/gh/marco-c/gecko-dev/commit'
MC_REPO = 'https://hg.mozilla.org/mozilla-central'
HOOK_GROUP = 'project-releng'
HOOK_ID = 'services-{app_channel}-codecoverage/bot-generation'

secrets.load(
    os.environ['TASKCLUSTER_SECRET'],
    os.environ['TASKCLUSTER_CLIENT_ID'],
    os.environ['TASKCLUSTER_ACCESS_TOKEN'],
)
github = GitHubUtils(
    '/tmp',
    os.environ['TASKCLUSTER_CLIENT_ID'],
    os.environ['TASKCLUSTER_ACCESS_TOKEN'],
)


def list_commits(maximum=None, unique=None, skip_commits=[]):
    '''
    List all the commits ingested on codecov
    '''
    assert unique in (None, 'week', 'day')
    params = {