def get(self, path, options={}): headers = { 'Authorization': self._token_header(), 'User-Agent': self.user_agent, } response = self._requests_retry_session().get(path, headers=headers) try: response.raise_for_status() except requests.exceptions.HTTPError as e: utils.print_error('Received a {} error requesting: {}'.format(response.status_code, path)) utils.print_error(response.content) raise e return response.json()
def get(self, path, options={}): headers = { 'Authorization': self._token_header(), 'User-Agent': self.user_agent, } response = self._requests_retry_session().get(path, headers=headers) try: response.raise_for_status() except requests.exceptions.HTTPError as e: utils.print_error('Received a {} error requesting: {}'.format( response.status_code, path)) utils.print_error(response.content) raise e return response.json()
def branch(self): # First, percy env var. if os.getenv('PERCY_BRANCH'): return os.getenv('PERCY_BRANCH') # Second, from the CI environment. if self._real_env and hasattr(self._real_env, 'branch'): return self._real_env.branch # Third, from the local git repo. raw_branch_output = self._raw_branch_output() if raw_branch_output: return raw_branch_output # Fourth, fallback to 'master'. utils.print_error('[percy] Warning: unknown git repo, setting PERCY_BRANCH to "master".') return 'master'
def post(self, path, data, options={}): headers = { 'Content-Type': 'application/vnd.api+json', 'Authorization': self._token_header(), 'User-Agent': self.user_agent, } response = self._requests_retry_session().post(path, json=data, headers=headers) try: response.raise_for_status() except requests.exceptions.HTTPError as e: utils.print_error('Received a {} error posting to: {}.'.format(response.status_code, path)) utils.print_error(response.content) raise e return response.json()
def branch(self): # First, percy env var. if os.getenv('PERCY_BRANCH'): return os.getenv('PERCY_BRANCH') # Second, from the CI environment. if self._real_env and hasattr(self._real_env, 'branch'): return self._real_env.branch # Third, from the local git repo. raw_branch_output = self._raw_branch_output() if raw_branch_output: return raw_branch_output # Fourth, fallback to NONE. utils.print_error( '[percy] Warning: unknown git repo, branch not detected.') return None
def __init__(self, loader=None, config=None, client=None): self.loader = loader self.config = config or percy.Config() self.client = client or percy.Client(config=self.config) self._current_build = None self._is_enabled = os.getenv('PERCY_ENABLE', '1') == '1' # Sanity check environment and auth setup. If in CI and Percy is disabled, print an error. if self._is_enabled: try: self.client.config.access_token except errors.AuthError: if self.client.environment.current_ci: utils.print_error('[percy] Warning: Percy is disabled, no PERCY_TOKEN set.') self._is_enabled = False
def post(self, path, data, options={}): headers = { 'Content-Type': 'application/vnd.api+json', 'Authorization': self._token_header(), 'User-Agent': self.user_agent, } response = self._requests_retry_session().post(path, json=data, headers=headers) try: response.raise_for_status() except requests.exceptions.HTTPError as e: utils.print_error('Received a {} error posting to: {}.'.format( response.status_code, path)) utils.print_error(response.content) raise e return response.json()