def __init__(self, circle_token=None): if circle_token: self.circle_token = circle_token elif os.environ.get('CCI_TOKEN', None): self.circle_token = os.environ['CCI_TOKEN'] assert self.circle_token, ('You must supply a CircleCI token ' 'in the environment variable CCI_TOKEN or ' 'via command line.') self.cci = circleclient.CircleClient(self.circle_token)
def connection(circle_token=None): if circle_token: self_circle_token = circle_token elif os.environ.get('CIRCLE_TOKEN', None): self_circle_token = os.environ['CIRCLE_TOKEN'] assert self_circle_token, ('You must supply a CircleCI token ' 'in the environment variable CIRCLE_TOKEN or ' 'via command line.') self_cci = circleclient.CircleClient(self_circle_token) return self_cci
def __init__(self): super(Bot, self).__init__() self.name = "appone" self.emoji = ":robot_face:" # When we instantiate a new bot object, we can access the app # credentials we set earlier in our local development environment. # Scopes provide and limit permissions to what our app # can access. It's important to use the most restricted # scope that your app will need. self.oauth = { "client_id": os.environ.get("SLACK_CLIENT_ID"), "client_secret": os.environ.get("SLACK_CLIENT_SECRET"), "scope": os.environ.get("SLACK_BOT_SCOPE", "bot") } self.user_name_map = {} self.channel_data_map = {} # NOTE: Python-slack requires a client connection to generate # an oauth token. We can connect to the client without authenticating # by passing an empty string as a token and then reinstantiating the # client with a valid OAuth token once we have one. bot_oauth_default = "xoxb-445512136161-446113431922-MbaetJ62o8U1mr4u91BTauSq" bot_oauth_token = os.environ.get("SLACK_BOT_OAUTH_ACCESS", bot_oauth_default) #dprint ("calling SlackClient with token %s" % (bot_oauth_token,)) self.client = SlackClient(bot_oauth_token) self.circleci_user_token = os.environ['CIRCLECI_HODOLIZER_TOKEN'] self.circleci_project_token = os.environ['CIRCLECI_HB_LITTLEBOT_TOKEN'] self.circleci_client = circleclient.CircleClient( self.circleci_user_token) self.circleci_repo_list = [] # We'll use this dictionary to store the state of each message object. # In a production envrionment you'll likely want to store this more # persistantly in a database. self.messages = {}
def __init__(self): '''This is the initial method for configuring''' self.token = 'f963b5e3eace0921e05203d60bbda3a81430a307' self.client = circleclient.CircleClient(api_token=self.token)
def client(): return circleclient.CircleClient(api_token='token')
def __init__(self, url, token, sleep_time=15, pushover=False, retry_failed=False): """ Instantiate a CircleWatcher. :param url: URL to build or project :type url: str :param token: CircleCI API token :type token: str :param sleep_time: time to sleep between polls, in seconds :type sleep_time: int :param pushover: whether to notify via Pushover on build completion :type pushover: bool :param retry_failed: whether or not to retry the build if it fails :type retry_failed: bool """ self._url = url self._token = token self._sleep_time = sleep_time if args.pushover: if not have_pushover: raise SystemExit( "ERROR: to use pushover notifications, please `pip " "install python-pushover` and configure it." ) if 'PUSHOVER_APIKEY' not in os.environ: raise SystemExit( "ERROR: to use pushover notifications, export your " "Pushover API key as the 'PUSHOVER_APIKEY' environment " "variable." ) if 'PUSHOVER_USERKEY' not in os.environ: raise SystemExit( "ERROR: to use pushover notifications, export your " "Pushover User Key as the 'PUSHOVER_USERKEY' environment " "variable." ) init(os.environ['PUSHOVER_APIKEY']) self._pushover_userkey = os.environ['PUSHOVER_USERKEY'] self._pushover = pushover self._retry_failed = retry_failed self._endpoint = self._endpoint_for_url(self._url) logger.debug('Connecting to CircleCI with API URL: %s', self._endpoint) # BEGIN hack around unreleased circleclient PR #11 if self._endpoint == 'https://circleci.com/api/v1': self._circle = circleclient.CircleClient(api_token=self._token) else: try: self._circle = circleclient.CircleClient( api_token=self._token, endpoint=self._endpoint ) except TypeError: raise SystemExit( 'CircleCI Enterprise installations require circleclient ' '>0.1.6; please try: pip install --upgrade ' 'git+https://github.com/qba73/circleclient.git') # END hack around unreleased circleclient PR #11 logger.debug( 'Connected to CircleCI as user: %s', self._circle.user.info()['name'] )
import os import json import requests from circleclient import circleclient token = "f2c6a6d316fac70907638112dea96a3c41d4dbc3" client = circleclient.CircleClient(token) #retrive User Data user = client.user.info() projects = client.projects.list_projects() print("user projects are: ", user['num_projects_followed']) print("User projects are: ", projects) def traverse(obj, path=None, callback=None): if path is None: path = [] if isinstance(obj, dict): value = {k: traverse(v, path + [k], callback) for k, v in obj.items()} elif isinstance(obj, list): value = [traverse(elem, path + [[]], callback) for elem in obj] else: value = obj if callback is None: # if a callback is provided, call it to get the new value return value else:
def go(): now = datetime.datetime.now(tz=pytz.utc) token = os.environ['CIRCLE_TOKEN'] client = circleclient.CircleClient(token) # print client.projects.list_projects() # print client.build.recent_all_projects() username = sys.argv[1] project = sys.argv[2] d0 = sys.argv[3] fn = sys.argv[4] print('username: %s' % username) print('project: %s' % project) print('d0: %s' % d0) print('fn: %s' % fn) print('circle token: %s' % token) from github import Github if not 'GITHUB_TOKEN' in os.environ: print('Set GITHUB_TOKEN for me to be smarter') active_branches = None else: github_token = os.environ['GITHUB_TOKEN'] try: g = Github(github_token) active_branches = [ _.name for _ in g.get_organization(username).get_repo( project).get_branches() ] except ssl.SSLError as e: print('error: %s' % e) active_branches = None print('active branches: %s' % active_branches) res = client.build.recent(username, project, limit=50, offset=0) builds = OrderedDict() for r in res: # print yaml.dump(r) if not r['all_commit_details']: print('skipping %s' % r['build_num']) continue build = read_build(client, username, project, token, r, d0) builds[build.get_build_num()] = build body = Tag(name='body') template = TEMPLATE template = template.replace('DATE', str(date_tag(now))) parsed = parse_html(template) table1 = get_build_table(builds) table2 = get_branch_table(d0, project, builds, active_branches) parsed.find(id='table1').replace_with(table1) parsed.find(id='table2').replace_with(table2) body.append(parsed) html = Tag(name='html') head = Tag(name='head') meta = Tag(name='meta') meta.attrs['content'] = "text/html; charset=utf-8" meta.attrs['http-equiv'] = "Content-Type" head.append(meta) html.append(head) html.append(body) # fn = os.path.join(d0, 'summary.html') with open(fn, 'w') as f: f.write(str(html)) print('Created ' + fn)
GECKOBOARD_TOOLS_JIRA_QUERY_LINKS_WIDGET_KEY = os.environ[ "GECKOBOARD_TOOLS_JIRA_QUERY_LINKS_WIDGET_KEY"] GECKOBOARD_PUSH_URL = os.getenv("GECKOBOARD_PUSH_URL", "https://push.geckoboard.com/v1/send/") JIRA_HOST = os.environ["JIRA_HOST"] JIRA_USERNAME = os.environ["JIRA_USERNAME"] JIRA_TOKEN = os.environ["JIRA_TOKEN"] CIRCLE_CI_API_TOKEN = os.environ["CIRCLE_CI_API_TOKEN"] # other variables TODAY = date.today().isoformat() # Clients JIRA_CLIENT = JiraClient(JIRA_HOST, basic_auth=(JIRA_USERNAME, JIRA_TOKEN)) GECKO_CLIENT = GeckoClient(GECKOBOARD_API_KEY) CIRCLE_CI_CLIENT = circleclient.CircleClient(CIRCLE_CI_API_TOKEN) if __name__ == "__main__": print("Creating Geckoboard datasets") DATASETS = create_datasets(DatasetSchemas, GECKO_CLIENT) print("Fetching stats from Jira") from jira_results import * print("Pushing Jira stats to Geckoboard") DATASETS.JIRA_BUGS_BY_LABELS.dataset.post(jira_bugs_by_labels) DATASETS.JIRA_BUG_AND_TICKET_COUNTERS.dataset.post( jira_bug_and_ticket_counters) print("Fetching test results from CircleCi") from circleci_results import *