def getSlackUsers(): if slack_mappings: return slack_mappings response = ApiManager.get(SLACK_USER_LIST + CommonUtils.SLACK_TOKEN, headers={}) users = json.loads(response["content"]) for item in users["members"]: slack_mappings[item["name"]] = item["profile"].get("email","*****@*****.**") print slack_mappings
def getGithubUsers(): if git_mappings: return git_mappings users = [] page = 1 while True: member_api = "%s%s" % (API_GITHUB_MEMBERS_LIST.format(org=CommonUtils.organisation), page) response = ApiManager.get(member_api, headers={"Authorization": "token " + CommonUtils.GIT_TOKEN}) if not response: break users += json.loads(response["content"]) page += 1 for item in users: user_name = item["login"] ApiManager.get(API_GITHUB_USERS + "/" + user_name) git_mappings[item["login"]] = item["login"] return git_mappings
def __init__(self, pr): self.GITHUB_TOKEN = pr.config.githubToken self.pr_api_link = pr.link self.headers = {"Authorization": "token " + self.GITHUB_TOKEN} self.pr = pr url = API_GITHUB_REPO_MEMBER.format(org=self.pr.config.organisation, repo=self.pr.repo) response = ApiManager.get(url=url, headers=self.headers) if response["status_code"] != 200: raise Exception(response["content"], "Please check the provided Github Token, " "either user doesn't have permission to" " the organisation or the repository")
def fetch_email(self): headers = { "Content-Type": "application/json", "Authorization": self.jira_token } for user in self.tagged_users: if 'accountid:' in user: account_id = user.replace('accountid:', '') url = API_JIRA_USERS_ACCOUNTID.format( account_id=account_id, jira_domain=self.jira_domain) else: url = API_JIRA_USERS.format(user_key=user, jira_domain=self.jira_domain) response = ApiManager.get(url=url, headers=headers) if response["status_code"] != 200: raise Exception(response["content"], "Please check the provided Jira Token, ") response = json.loads(response['content']) self.jira_dict[user] = response.get('emailAddress') return self.jira_dict
def get_comments(self): comments_end_point = API_GITHUB_ISSUES.format(org=self.pr.config.organisation, repo=self.pr.repo) \ + "/" + str(self.pr.number) + "/" + EP_COMMENTS return ApiManager.get(comments_end_point, self.headers)
def get_files_requests(self): url = self.pr_api_link + "/files" files = ApiManager.get(url, headers=self.headers) return files["response"].json()