def _process_branches(self, branches):
        self.reporter_try = {}
        self.reporter_ok = {}

        config = abdt_repoconfig.Data()
        config.branch_url_format = (
            'http://my.git/gitweb?p=r.git;a=log;h=refs/heads/{branch}')
        config.review_url_format = 'http://my.phabricator/{review}'

        self.reporter = abdt_reporeporter.RepoReporter(
            self.arcyd_reporter,
            'abdi_processrepo__t:Test repo:machine name',
            'abdi_processrepo__t:Test repo',
            abdt_shareddictoutput.ToDict(self.reporter_try),
            abdt_shareddictoutput.ToDict(self.reporter_ok))

        self.reporter.set_config(config)

        with contextlib.closing(self.reporter):
            abdi_processrepo.process_branches(
                branches,
                self.conduit,
                self.mailer,
                self.plugin_manager,
                self.reporter)
Example #2
0
def _process_repo(repo, unused_repo_name, args, arcyd_conduit, url_watcher,
                  mail_sender):

    fetch_if_needed(url_watcher, abdi_repoargs.get_repo_snoop_url(args), repo,
                    args.repo_desc)

    admin_emails = set(_flatten_list(args.admin_emails))

    # TODO: this should be a URI for users not conduit
    mailer = abdmail_mailer.Mailer(mail_sender, admin_emails, args.repo_desc,
                                   args.instance_uri)

    branch_url_callable = None
    if args.branch_url_format:

        def make_branch_url(branch_name):
            return args.branch_url_format.format(branch=branch_name,
                                                 repo_url=args.repo_url)

        branch_url_callable = make_branch_url

    branch_naming = abdt_compositenaming.Naming(abdt_classicnaming.Naming(),
                                                abdt_rbranchnaming.Naming())

    branches = abdt_git.get_managed_branches(repo, args.repo_desc,
                                             branch_naming,
                                             branch_url_callable)

    abdi_processrepo.process_branches(branches, arcyd_conduit, mailer)
 def _process_branches(self, branches):
     with contextlib.closing(self.reporter):
         abdi_processrepo.process_branches(
             branches,
             self.conduit,
             self.mailer,
             self.plugin_manager,
             self.reporter)
def _run_once(args, out, reporter, arcyd_reporter, conduits, url_watcher):

    sys_clone = phlsys_git.GitClone(args.repo_path)
    config = _determine_config(args, sys_clone)

    did_fetch = _fetch_if_needed(
        url_watcher, args, out, arcyd_reporter, config.description)

    if did_fetch:
        # determine the config again now that we've fetched the repo
        config = _determine_config(args, sys_clone)

    arcyd_conduit = _connect(conduits, args, arcyd_reporter)

    reporter.set_config(config)

    sender = phlmail_sender.MailSender(
        phlsys_sendmail.Sendmail(), args.arcyd_email)

    mailer = abdmail_mailer.Mailer(
        sender,
        config.admin_emails,
        config.description,
        args.instance_uri)  # TODO: this should be a URI for users not conduit

    pluginManager = phlsys_pluginmanager.PluginManager(
        args.plugins, args.trusted_plugins)

    out.display("process (" + config.description + "): ")

    branch_url_callable = None
    if config.branch_url_format:
        def make_branch_url(branch_name):
            return config.branch_url_format.format(branch=branch_name)
        branch_url_callable = make_branch_url

    arcyd_reporter.tag_timer_decorate_object_methods(sys_clone, 'git')
    arcyd_clone = abdt_git.Clone(
        sys_clone, "origin", config.description, branch_url_callable)
    branches = arcyd_clone.get_managed_branches()
    for branch in branches:
        arcyd_reporter.tag_timer_decorate_object_methods_individually(
            branch, 'branch')

    try:
        abdi_processrepo.process_branches(
            branches,
            arcyd_conduit,
            mailer,
            pluginManager,
            reporter)
    except Exception:
        reporter.on_traceback(traceback.format_exc())
        raise

    reporter.on_completed()
def _process_repo(
        repo,
        unused_repo_name,
        args,
        arcyd_conduit,
        url_watcher,
        mail_sender):

    fetch_if_needed(
        url_watcher,
        abdi_repoargs.get_repo_snoop_url(args),
        repo,
        args.repo_desc)

    admin_emails = set(_flatten_list(args.admin_emails))

    # TODO: this should be a URI for users not conduit
    mailer = abdmail_mailer.Mailer(
        mail_sender,
        admin_emails,
        args.repo_desc,
        args.instance_uri)

    branch_url_callable = None
    if args.branch_url_format:
        def make_branch_url(branch_name):
            return args.branch_url_format.format(
                branch=branch_name,
                repo_url=args.repo_url)
        branch_url_callable = make_branch_url

    branch_naming = abdt_compositenaming.Naming(
        abdt_classicnaming.Naming(),
        abdt_rbranchnaming.Naming())

    branches = abdt_git.get_managed_branches(
        repo,
        args.repo_desc,
        branch_naming,
        branch_url_callable)

    abdi_processrepo.process_branches(branches, arcyd_conduit, mailer)
def _do(repo, args, reporter, arcyd_reporter, conduits, url_watcher):

    with arcyd_reporter.tag_timer_context('process branches prolog'):

        arcyd_reporter.tag_timer_decorate_object_methods_individually(
            repo, 'git')

        fetch_if_needed(
            url_watcher,
            abdi_repoargs.get_repo_snoop_url(args),
            repo,
            args.repo_desc)

        options = _determine_options(args, repo)

        arcyd_conduit = _connect(conduits, args, arcyd_reporter)

        reporter.set_config(options)

        sender = phlmail_sender.MailSender(
            phlsys_sendmail.Sendmail(), arcyd_reporter.arcyd_email)

        # TODO: this should be a URI for users not conduit
        mailer = abdmail_mailer.Mailer(
            sender,
            options.admin_emails,
            options.description,
            args.instance_uri)

        pluginManager = phlsys_pluginmanager.PluginManager(
            args.plugins, args.trusted_plugins)

        branch_url_callable = None
        if options.branch_url_format:
            def make_branch_url(branch_name):
                return options.branch_url_format.format(
                    branch=branch_name,
                    repo_url=args.repo_url)
            branch_url_callable = make_branch_url

        branch_naming = abdt_compositenaming.Naming(
            abdt_classicnaming.Naming(),
            abdt_rbranchnaming.Naming())

        branches = abdt_git.get_managed_branches(
            repo,
            options.description,
            branch_naming,
            branch_url_callable)

        for branch in branches:
            arcyd_reporter.tag_timer_decorate_object_methods_individually(
                branch, 'branch')

    try:
        with arcyd_reporter.tag_timer_context('process branches'):
            abdi_processrepo.process_branches(
                branches,
                arcyd_conduit,
                mailer,
                pluginManager,
                reporter)
    except Exception:
        reporter.on_traceback(traceback.format_exc())
        raise

    reporter.on_completed()
 def _process_branches(self, branches):
     abdi_processrepo.process_branches(
         branches,
         self.conduit,
         self.mailer)
 def _process_branches(self, branches):
     abdi_processrepo.process_branches(branches, self.conduit, self.mailer)
def _run_once(args, out, reporter):

    sender = phlmail_sender.MailSender(
        phlsys_sendmail.Sendmail(), args.arcyd_email)

    mailer = abdmail_mailer.Mailer(
        sender,
        [args.admin_email],
        args.repo_desc,
        args.instance_uri)  # TODO: this should be a URI for users not conduit

    pluginManager = phlsys_pluginmanager.PluginManager(
        args.plugins, args.trusted_plugins)

    # prepare delays in the event of trouble when fetching or connecting
    # TODO: perhaps this policy should be decided higher-up
    delays = [
        datetime.timedelta(seconds=1),
        datetime.timedelta(seconds=1),
        datetime.timedelta(seconds=10),
        datetime.timedelta(seconds=10),
        datetime.timedelta(seconds=100),
        datetime.timedelta(seconds=100),
        datetime.timedelta(seconds=1000),
    ]

    # log.error if we get an exception when fetching
    def on_tryloop_exception(e, delay):
        reporter.on_tryloop_exception(e, delay)
        logging.error(str(e) + "\nwill wait " + str(delay))

    def prune_and_fetch():
        phlsys_subprocess.run_commands("git remote prune origin")
        phlsys_subprocess.run_commands("git fetch")

    with phlsys_fs.chdir_context(args.repo_path):
        out.display("fetch (" + args.repo_desc + "): ")
        phlsys_tryloop.try_loop_delay(
            prune_and_fetch,
            delays,
            onException=on_tryloop_exception)

    # XXX: until conduit refreshes the connection, we'll suffer from
    #      timeouts; reduce the probability of this by using a new
    #      conduit each time.

    # create an array so that the 'connect' closure binds to the 'conduit'
    # variable as we'd expect, otherwise it'll just modify a local variable
    # and this 'conduit' will remain 'None'
    # XXX: we can do better in python 3.x (nonlocal?)
    conduit = [None]

    def connect():
        # nonlocal conduit # XXX: we'll rebind in python 3.x, instead of array
        conduit[0] = phlsys_conduit.Conduit(
            args.instance_uri,
            args.arcyd_user,
            args.arcyd_cert,
            https_proxy=args.https_proxy)

    phlsys_tryloop.try_loop_delay(
        connect, delays, onException=on_tryloop_exception)

    out.display("process (" + args.repo_desc + "): ")
    arcyd_conduit = abdt_conduit.Conduit(conduit[0])

    branch_url_callable = None
    if args.branch_url_format:
        def make_branch_url(branch_name):
            return args.branch_url_format.format(branch=branch_name)
        branch_url_callable = make_branch_url

    arcyd_clone = abdt_git.Clone(
        args.repo_path, "origin", args.repo_desc, branch_url_callable)
    branches = arcyd_clone.get_managed_branches()

    try:
        abdi_processrepo.process_branches(
            branches,
            arcyd_conduit,
            mailer,
            pluginManager,
            reporter)
    except Exception:
        reporter.on_traceback(traceback.format_exc())
        raise

    reporter.on_completed()