How to use the rbtools.api.client.RBClient function in RBTools

To help you get started, we’ve selected a few RBTools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / version-control-tools / testing / vcttesting / reviewboard / mach_commands.py View on Github external
password = os.environ.get('BUGZILLA_PASSWORD')

        # RBClient is persisting login cookies from call to call
        # in $HOME/.rbtools-cookies. We want to be able to easily switch
        # between users, so we clear that cookie between calls to the
        # server and reauthenticate every time.
        try:
            os.remove(os.path.join(os.environ.get('HOME'), '.rbtools-cookies'))
        except Exception:
            pass

        if anonymous:
            return RBClient(self.mr.reviewboard_url,
                            transport_cls=NoCacheTransport)

        return RBClient(self.mr.reviewboard_url, username=username,
                        password=password, transport_cls=NoCacheTransport)
github reviewboard / rbtools / rbtools / clients / tests.py View on Github external
def setUp(self):
        super(SVNRepositoryInfoTests, self).setUp()

        self.spy_on(urlopen, call_fake=self._urlopen)

        self.api_client = RBClient('http://localhost:8080/')
        self.root_resource = self.api_client.get_root()
github mozilla / version-control-tools / testing / vcttesting / reviewboard / __init__.py View on Github external
def ReviewBoardClient(url, username, password):

    return RBClient(url, save_cookies=False,
                    allow_caching=False,
                    username=username, password=password)
github jantman / misc-scripts / reviewboard_reminder_mail.py View on Github external
def main(url, group_names, days_old=7, dry_run=False):
    """ do something """
    try:
        user = os.environ['RBUSER']
    except KeyError:
        raise SystemExit("please set RBUSER environment variable for reviewboard user")
    try:
        passwd = os.environ['RBPASS']
    except KeyError:
        raise SystemExit("please set RBPASS environment variable for reviewboard password")
    #client = RBClient(url, user, passwd)
    client = RBClient(url)
    root = client.get_root()
    if not root:
        raise SystemExit("Error - could not get RBClient root.")

    for g_name in group_names:
        o = get_group_id_by_name(root, g_name, dry_run=dry_run)
        if not o:
            raise SystemExit("ERROR: no group '%s' found." % g_name)
        logger.debug("Found group '%s' id=%d" % (g_name, o))

    reviews = get_reviews_for_groups(root, group_names, dry_run=dry_run)

    old_reviews = filter_reviews_older_than(root, reviews, days_old, dry_run=dry_run)
    logger.info("found %d reviews for target groups and last updated %d or more days ago" % (len(old_reviews), days_old))

    if len(old_reviews) < 1:
github apache / sqoop / dev-support / upload-patch.py View on Github external
# Saving details of the JIRA for various use
print "Getting details for JIRA %s" % (options.jira)
jiraDetails = jira_get_issue(options)

# Verify that JIRA is properly marked with versions (otherwise precommit hook would fail)
versions = []
for version in jiraDetails.get("fields").get("versions"):
  versions = versions + [version.get("name")]
for version in jiraDetails.get("fields").get("fixVersions"):
  versions = versions + [version.get("name")]
if not versions:
  exit("Both 'Affected Version(s)' and 'Fix Version(s)' JIRA fields are empty. Please fill one of them with desired version first.")

# Review board handling
rbClient = RBClient(options.rb_url, username=options.rb_user, password=options.rb_password)
rbRoot = rbClient.get_root()

# The RB REST API don't have call to return repository by name, only by ID, so one have to
# manually go through all the repositories and find the one that matches the corrent name.
rbRepoId = -1
for repo in rbRoot.get_repositories(max_results=500):
  if repo.name == options.rb_repository:
    rbRepoId = repo.id
    break
# Verification that we have found required repository
if rbRepoId == -1:
  exit("Did not found repository '%s' on review board" % options.rb_repository)
else:
  if options.verbose:
    print "Review board repository %s has id %s" % (options.rb_repository, rbRepoId)
github reviewboard / ReviewBot / bot / reviewbot / tasks.py View on Github external
'entry_point': entry_point,
                'version': tool_class.version,
                'description': tool_class.description,
                'tool_options': json.dumps(tool_class.options),
                'timeout': tool_class.timeout,
                'working_directory_required':
                    tool_class.working_directory_required,
            })
        else:
            logger.warning('%s dependency check failed.', ep.name)

    logger.info('Done iterating Tools')
    hostname = panel.hostname

    try:
        api_client = RBClient(
            payload['url'],
            cookie_file=COOKIE_FILE,
            agent=AGENT,
            session=payload['session'])
        api_root = api_client.get_root()
    except Exception as e:
        logger.exception('Could not reach RB server: %s', e)

        return {
            'status': 'error',
            'error': 'Could not reach Review Board server: %s' % e,
        }

    try:
        api_tools = _get_extension_resource(api_root).get_tools()
        api_tools.create(hostname=hostname, tools=json.dumps(tools))
github mozilla / version-control-tools / pylib / reviewboardmods / reviewboardmods / pushhooks.py View on Github external
def ReviewBoardClient(url, username=None, password=None, apikey=None):
    """Obtain a RBClient instance."""
    if username and apikey:
        rbc = RBClient(url, save_cookies=False, allow_caching=False)
        login_resource = rbc.get_path(
            'extensions/mozreview.extension.MozReviewExtension/'
            'bugzilla-api-key-logins/')
        login_resource.create(username=username, api_key=apikey)
    else:
        rbc = RBClient(url, username=username, password=password,
                       save_cookies=False, allow_caching=False)

    return rbc
github reviewboard / ReviewBot / bot / reviewbot / repositories.py View on Github external
def fetch_repositories(url, user=None, token=None):
    """Fetch repositories from Review Board.

    Args:
        url (unicode):
            The configured url for the connection.

        user (unicode):
            The configured user for the connection.

        token (unicode):
            The configured API token for the user.
    """
    logging.info('Fetching repositories from Review Board: %s', url)
    # TODO: merge with COOKIE_FILE/AGENT in tasks.py
    root = RBClient(url, username=user, api_token=token,
                    cookie_file='reviewbot-cookies.txt',
                    agent='ReviewBot').get_root()

    for tool_type in ('Mercurial', 'Git'):
        repos = root.get_repositories(tool=tool_type, only_links='',
                                      only_fields='path,mirror_path,name')

        for repo in repos.all_items:
            repo_source = None

            for path in (repo.path, repo.mirror_path):
                if (os.path.exists(path) or path.startswith('http') or
                    path.startswith('git')):
                    repo_source = path
                    break
github reviewboard / ReviewBot / bot / reviewbot / tasks.py View on Github external
bool:
        Whether the task completed successfully.
    """
    try:
        routing_key = RunTool.request.delivery_info['routing_key']
        route_parts = routing_key.partition('.')
        tool_name = route_parts[0]

        log_detail = ('(server=%s, review_request_id=%s, diff_revision=%s)'
                      % (server_url, review_request_id, diff_revision))

        logger.info('Running tool "%s" %s', tool_name, log_detail)

        try:
            logger.info('Initializing RB API %s', log_detail)
            api_client = RBClient(server_url,
                                  cookie_file=COOKIE_FILE,
                                  agent=AGENT,
                                  session=session)
            api_root = api_client.get_root()
        except Exception as e:
            logger.error('Could not contact Review Board server: %s %s',
                         e, log_detail)
            return False

        logger.info('Loading requested tool "%s" %s', tool_name, log_detail)
        tools = [
            entrypoint.load()
            for entrypoint in pkg_resources.iter_entry_points(
                group='reviewbot.tools', name=tool_name)
        ]