def fetch(host : str, organization : str, slug : str, __filter__ : str, token : str) -> List[ProducerModel]: result = [] response = None if host and slug and __filter__ == 'mine' and token: response = request.get(host + '/api/v2/project/' + slug + '/pipeline/mine', headers = { 'Accept': 'application/json', 'Circle-Token': token }) elif host and slug and token: response = request.get(host + '/api/v2/project/' + slug + '/pipeline', headers = { 'Accept': 'application/json', 'Circle-Token': token }) elif host and organization and token: response = request.get(host + '/api/v2/pipeline?org-slug=' + organization, headers = { 'Accept': 'application/json', 'Circle-Token': token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'items' in data: pipeline = helper.get_first(data['items']) if pipeline and 'id' in pipeline: result.extend(fetch_workflows(host, pipeline['id'], token)) return result
def fetch(host: str, slug: str, token: str) -> List[ProducerModel]: result = [] response = None if host and slug and token: response = request.get(host + '/repos/' + slug, headers={ 'Accept': 'application/vnd.travis-ci.2.1+json', 'Authorization': 'Token ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'repo' in data and 'slug' in data['repo'] and 'active' in data[ 'repo'] and 'last_build_state' in data['repo']: result.append( normalize_data(data['repo']['slug'], data['repo']['active'], data['repo']['last_build_state'])) if 'repos' in data: for repository in data['repos']: if 'slug' in repository and 'active' in repository and 'last_build_state' in repository: result.append( normalize_data(repository['slug'], repository['active'], repository['last_build_state'])) return result
def fetch(host: str, slug: str, token: str) -> List[ProducerModel]: result = [] response = None if host and slug and token: response = request.get(host + '/rest/api/latest/result/' + normalize_slug(slug), headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'results' in data and 'result' in data['results']: for project in data['results']['result']: if 'key' in project and 'buildState' in project: result.append( normalize_data(project['key'], project['buildState'])) elif 'key' in data and 'buildState' in data: result.append(normalize_data(data['key'], data['buildState'])) return result
def fetch(host: str, slug: str, username: str, token: str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and username and token: username_token = username + ':' + token response = request.get( host + '/job/' + slug + '/lastBuild/api/json', headers={ 'Accept': 'application/json', 'Authorization': 'Basic ' + base64.b64encode( username_token.encode('utf-8')).decode('ascii') }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'result' in data and 'building' in data: result.append( normalize_data(slug, data['result'], data['building'])) return result
def fetch(host: str, slug: str, token: str) -> List[ProducerModel]: result = [] response = None if host and slug and token: token = ':' + token response = request.get( host + '/' + slug + '/_apis/build/builds?api-version=6.0', headers={ 'Accept': 'application/json', 'Authorization': 'Basic ' + base64.b64encode(token.encode('utf-8')).decode('ascii') }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'value' in data: build = helper.get_first(data['value']) if 'project' in build and 'name' in build[ 'project'] and 'status' in build: if 'result' in build: result.append( normalize_data(build['project']['name'], build['status'], build['result'])) else: result.append( normalize_data(build['project']['name'], build['status'], None)) return result
def fetch(host: str, slug: str, username: str, password: str) -> List[ProducerModel]: result = [] response = None if host and slug and username and password: username_password = username + ':' + password response = request.get( host + '/2.0/repositories/' + slug + '/pipelines/', headers={ 'Accept': 'application/json', 'Authorization': 'Basic ' + base64.b64encode( username_password.encode('utf-8')).decode('ascii') }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'values' in data: build = helper.get_first(data['values']) if build and 'repository' in build and 'full_name' in build[ 'repository'] and 'state' in build and 'result' in build[ 'state'] and 'name' in build['state']['result']: result.append( normalize_data(build['repository']['full_name'], build['state']['result']['name'])) return result
def test_get() -> None: response = request.get('https://jsonplaceholder.typicode.com/posts', { 'Content-Type': 'application/json' }) assert response.status_code == 200
def fetch(host: str, slug: str, token: str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and token: response = request.get( host + '/app/rest/buildTypes/?fields=buildType(builds($locator(running:any),build(running,status,buildType(projectName))))&locator=affectedProject:(id:' + slug + ')', headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) elif host and token: response = request.get( host + '/app/rest/buildTypes/?fields=buildType(builds($locator(running:any),build(running,status,buildType(projectName))))', headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'buildType' in data: for project in data['buildType']: if 'builds' in project and 'build' in project['builds']: build = helper.get_first(project['builds']['build']) if build and 'buildType' in build and 'projectName' in build[ 'buildType'] and 'status' in build and 'running' in build: result.append( normalize_data(build['buildType']['projectName'], build['status'], build['running'])) return result
def fetch(host: str, slug: str, token: str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and token: response = request.get(host + '/api/projects/' + slug, headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) elif host and token: response = request.get(host + '/api/projects', headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'project' in data and 'accountName' in data[ 'project'] and 'build' in data and 'status' in data['build']: result.append( normalize_data( data['project']['accountName'] + '/' + data['project']['slug'], data['build']['status'])) if 'builds' in helper.get_first(data): for project in data: build = helper.get_first(project['builds']) if project and 'accountName' in project and 'slug' in project and build and 'status' in build: result.append( normalize_data( project['accountName'] + '/' + project['slug'], build['status'])) return result
def fetch(host : str, slug : str, token : str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and token: response = request.get(host + '/api/v3/applications/' + slug, headers = { 'Accept': 'application/json', 'Bearer': token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'id' in data: result.extend(fetch_runs(host, slug, data['id'], token)) return result
def fetch(host: str, slug: str) -> List[ProducerModel]: result = [] response = None if host and slug: response = request.get(host + '/statuses/' + slug, headers={'Accept': 'application/json'}) # process response if response and response.status_code == 200: data = request.parse_json(response) if data: for build in data: if 'slug' in build and 'active' in build and 'status' in build: result.append( normalize_data(build['slug'], build['active'], build['status'])) return result
def fetch_repositories(host : str, username : str, token : str) -> List[Dict[str, Any]]: result = [] response = None if host and username and token: response = request.get(host + '/users/' + username + '/repos', headers = { 'Accept': 'application/vnd.github.v3+json', 'Authorization': 'Token ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if data: for repository in data: result.append(repository) return result
def fetch_runs(host : str, slug : str, application_id : str, token : str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and application_id and token: response = request.get(host + '/api/v3/runs?applicationId=' + application_id, headers = { 'Accept': 'application/json', 'Bearer': token }) # process response if response and response.status_code == 200: data = request.parse_json(response) build = helper.get_first(data) if build and 'status' in build and 'result' in build: result.append(normalize_data(slug, build['status'], build['result'])) return result
def fetch_projects(host : str, workspace : str, token : str) -> List[Dict[str, Any]]: result = [] response = None if host and workspace and token: response = request.get(host + '/workspaces/' + workspace + '/projects', headers = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'projects' in data: for project in data['projects']: result.append(project) return result
def fetch_workflows(host : str, pipeline_id : str, token : str) -> List[ProducerModel]: result = [] response = None if host and pipeline_id and token: response = request.get(host + '/api/v2/pipeline/' + pipeline_id + '/workflow', headers = { 'Accept': 'application/json', 'Circle-Token': token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'items' in data: for build in data['items']: if 'project_slug' in build and 'name' in build and 'status' in build: result.append(normalize_data(build['project_slug'] + '/' + build['name'], build['status'])) return result
def fetch_pipelines(host: str, workspace: str, project : str, token: str) -> List[ProducerModel]: result = [] response = None if host and workspace and project and token: response = request.get(host + '/workspaces/' + workspace + '/projects/' + project + '/pipelines/', headers= { 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'pipelines' in data: pipeline = helper.get_first(data['pipelines']) if pipeline and 'last_execution_status' in pipeline: result.append(normalize_data(workspace + '/' + project, pipeline['last_execution_status'])) return result
def fetch(host: str, slug: str, token: str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and token: response = request.get(host + '/api/v4/projects/' + slug + '/pipelines', headers={ 'Accept': 'application/json', 'Private-Token': token }) # process response if response and response.status_code == 200: data = request.parse_json(response) pipeline = helper.get_first(data) if pipeline and 'id' in pipeline: pipeline_id = str(pipeline['id']) result.extend(fetch_jobs(host, slug, pipeline_id, token)) return result
def fetch_runs(host : str, slug : str, token : str) -> List[ProducerModel]: result = [] response = None if host and slug and token: response = request.get(host + '/repos/' + slug + '/actions/runs', headers = { 'Accept': 'application/vnd.github.v3+json', 'Authorization': 'Token ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'workflow_runs' in data: build = helper.get_first(data['workflow_runs']) if build and 'repository' in build and 'full_name' in build['repository'] and 'status' in build and 'conclusion' in build: result.append(normalize_data(build['repository']['full_name'], build['status'], build['conclusion'])) return result
def fetch(host : str, slug : str, token : str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and token: slug_list = slug.split('/') response = request.get(host + '/workspaces/' + slug_list[0] + '/projects/' + slug_list[1] + '/pipelines/', headers = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'pipelines' in data: pipeline = helper.get_first(data['pipelines']) if pipeline and 'last_execution_status' in pipeline: result.append(normalize_data(slug, pipeline['last_execution_status'])) return result
def fetch_jobs(host: str, slug: str, pipeline_id: str, token: str) -> List[Dict[str, Any]]: result = [] response = None if host and slug and pipeline_id and token: response = request.get(host + '/api/v4/projects/' + slug + '/pipelines/' + pipeline_id + '/jobs', headers={ 'Accept': 'application/json', 'Private-Token': token }) # process response if response and response.status_code == 200: data = request.parse_json(response) for build in data: if 'name' in build and 'status' in build: result.append( normalize_data(slug + '/' + build['name'], build['status'])) return result
def fetch_builds(host: str, organization_id: str, slug: str, project_id: str, token: str) -> List[Dict[str, Any]]: result = [] response = None if host and organization_id and project_id and token: response = request.get(host + '/v2/organizations/' + organization_id + '/projects/' + project_id + '/builds', headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }) # process response if response and response.status_code == 200: data = request.parse_json(response) if 'builds' in data: build = helper.get_first(data['builds']) if build and 'status' in build: result.append(normalize_data(slug, build['status'])) return result
def test_get() -> None: assert request.get( 'https://api.github.com/repos/redaxmedia/chroma-feedback', None)