def initialize(self): self.circleci = Api(self.args['circleci_token']) self.last_state = None self.light_id = self.args['entity_id'] self.effect_by_state() self.run_every(self.on_ci_state_update, datetime.datetime.now(), 10)
def __init__(self, token): try: self.ci = Api(token) self.username = self.ci.get_user_info()['login'] app.logger.info("Initialised connection to Circleci with user: %s", self.username) return None except Exception as e: app.logger.error( "Unable to initialise connection to CircleCi api: %s", repr(e)) return None
def run(self): if self.circleci is None: self.circleci = Api(self.circleci_token) if self.workflows: if self.workflow_branch and not self.workflow_name: self.output = dict( full_text='workflow_name must be specified!' ) return project = {p['reponame']: p for p in self.circleci.get_projects()}.get(self.repo_name) if not self.workflow_branch: self.workflow_branch = project.get('default_branch') workflow_info = project['branches'].get(self.workflow_branch)['latest_workflows'].get(self.workflow_name) self.last_build_started = self._format_time(workflow_info.get('created_at')) self.repo_status = workflow_info.get('status') self.last_build_duration = '' # TODO: gather this information once circleCI exposes it else: self.repo_summary = self.circleci.get_project_build_summary( self.repo_owner, self.repo_name, limit=1) if len(self.repo_summary) != 1: return self.repo_summary = self.repo_summary[0] self.repo_status = self.repo_summary.get('status') self.last_build_started = self._format_time(self.repo_summary.get('queued_at')) try: self.last_build_duration = TimeWrapper( self.repo_summary.get('build_time_millis') / 1000, default_format=self.duration_format) except TypeError: self.last_build_duration = 0 if self.repo_status_map: self.repo_status = self.repo_status_map.get(self.repo_status, self.repo_status) self.output = dict( full_text=formatp(self.format, **vars(self)), short_text=self.short_format.format(**vars(self)), ) if self.status_color_map: self.output['color'] = self.status_color_map.get(self.repo_status, self.color) else: self.output['color'] = self.color
def deploy(): """Deploy SupportService to LightSail. Uses a feature flag to disable automatically deploying specific environments. It can be found in the production environment of the support-service project. """ l = LaunchDarklyApi(os.environ.get('LD_API_KEY'), 'ldsolutions.tk') a = AwsApi(logger, keyPairName='SupportService') c = ConfigGenerator() ci = Api(os.environ.get('CIRCLE_TOKEN')) envs = l.getEnvironments('support-service') for env in envs: hostname = env['hostname'] ctx = {"key": "circleci", "custom": {"hostname": hostname}} params = { "build_parameters": { "CIRCLE_JOB": "deploy_instance", "LD_HOST": hostname } } if client.variation("auto-deploy-env", ctx, False): # run deploy job for environment resp = ci.trigger_build('launchdarkly', 'SupportService', branch='master', params=params) click.echo( "Sending Deploy Job to CircleCI for {0}".format(hostname)) click.echo("CircleCI Build URL: {0}".format(resp['build_url'])) else: click.echo( "Not Auto Deploying, auto-deploy-env flag is off for {0}". format(hostname))
def on_event(self, event, extension): """ Event handler """ if event.id == 'api_token': extension.circle = Api(event.new_value)
def on_event(self, event, extension): """ Handle event """ extension.circle = Api(event.preferences['api_token'])
def setUp(self): self.c = Api(os.getenv('CIRCLE_TOKEN'))
""" ld_lambda Process LaunchDarkly webhooks to trigger a CI build when a new environment is created. """ import os import json import logging from circleci.api import Api logger = logging.getLogger() logger.setLevel(logging.INFO) circleci = Api(os.environ.get("CIRCLE_TOKEN")) def trigger_deloy(): params = { 'build_parameters[CIRCLE_JOB]': 'deploy' } circleci.trigger_build( username='******', project='SupportService', params=params ) def handler(event, context): """ AWS Lambda Handler """
def __init__(self, token, user='******', project='connectedhomeip'): self.api = Api(token) self.user = user self.project = project self.vcs_type = 'github'
import logging import paho.mqtt.client as mqtt from circleci.api import Api from ruamel.yaml import YAML logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s") CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.yaml') LOGGER = logging.getLogger('lamp') LOGGER.info("Loading config: " + CONFIG_PATH) CONFIG = YAML(typ='safe').load(open(CONFIG_PATH)) circleci = Api(CONFIG['circle_token']) client = mqtt.Client() if 'username' in CONFIG: client.username_pw_set(CONFIG['username'], CONFIG['password']) client.connect(CONFIG['host'], CONFIG['port'], 60) client.loop_start() try: while True: LOGGER.info("Fetching build status...") build = circleci.get_recent_builds()[0] status = build['status'] LOGGER.info("Status is: {}".format(status)) client.publish(CONFIG['topic'], status, 2, True) time.sleep(5)
from collections import defaultdict import json import os from circleci.api import Api DESTDIR = os.environ.get('DESTDIR', None) CIRCLE_TOKEN = os.environ.get('CIRCLE_TOKEN', None) assert len(CIRCLE_TOKEN) >= 1, "Missing CIRCLE_TOKEN environment variable." circleci = Api(CIRCLE_TOKEN) def find_most_recent_store_builds(store_job_name_prefix='store-'): all_recent_builds = circleci.get_project_build_summary( username='******', project='tf-big', limit=50, status_filter=None, branch='master', vcs_type='github', ) commit_filter = None most_recent_store_builds = list() for build in all_recent_builds: job_name = build['workflows']['job_name'] commit = build['all_commit_details'][0]['commit']