def issueTransition(self, **args): issue_key = args["issue key"] transition_type = args["transition type"] transition = {"to do": "11", "in progress": "21", "done": "31"} transition_id = transition[transition_type.lower()] url = "/rest/api/2/issue/" + issue_key + "/transitions" api = self.base_url + url headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps({ "transition": { "id": transition_id } # "fields" : {"assignee": {"name" : assignee_name}} }) response = requests.request("POST", api, data=payload, headers=headers, auth=self.auth) if response.status_code != 204: self.output = "Error making issue transition" else: self.output = "Issue is transit to {type}".format( type=args["transition type"]) self.mail_body = { "Status": "Issue transition success", "Issue key": issue_key, "Transition level": args["transition type"] } send_mail.sendMail(self.mail_body) return self.output
def getSpecificProjectDetails(self, **args): project_key = args["project key"] url = '/rest/api/2/project/' + project_key api = self.base_url + url headers = {"Accept": "application/json"} response = requests.request("GET", api, auth=self.auth, headers=headers) if response.status_code != 200: self.output = "Project not found in the workshape or don't have required permissions" else: response = json.loads(response.text) to_do, in_progress, done = self.getAllIssues(**args) # to_do = [] # in_progress = [] # done = [] # self.getAllIssues(**args) self.output = "Project {name} is headed by {lead_name}. Various stories in the project with their status are \n Stories in to do : {to_do} \n Stories in progress : {in_progress} \n Stories done : {done}".format( name=response["name"], lead_name=response["lead"]["displayName"], to_do=to_do, in_progress=in_progress, done=done) # print(self.output) self.mail_body = { "Project name": response["name"], "Project ID": response["id"], "Project key": response["key"], "Project lead name": response["lead"]["displayName"], "Project lead ID": response["lead"]["accountId"] } send_mail.sendMail(self.mail_body) return self.output
def getIssue(self, **args): issue_key = args["issue key"] url = "/rest/api/3/issue/" + issue_key api = self.base_url + url headers = {"Accept": "application/json"} response = requests.request("GET", api, auth=self.auth, headers=headers) if response.status_code != 200: self.output = "Error getting issue details" else: response = json.loads(response.text) self.output = "Issue is created by {creator} and reported by {reporter} in project {project} and has the summary {summary}. Its priority is {priority}".format( creator=response["fields"]["creator"]["displayName"], reporter=response["fields"]["reporter"]["displayName"], project=response["fields"]["project"]["name"], summary=response["fields"]["summary"], priority=response["fields"]["priority"]["name"]) self.mail_body = { "Issue key": issue_key, "creator": response["fields"]["creator"]["displayName"], "reporter": response["fields"]["reporter"]["displayName"], "project": response["fields"]["project"]["name"], "summary": response["fields"]["summary"], "priority": response["fields"]["priority"]["name"], } send_mail.sendMail(self.mail_body) return self.output
def assignIssue(self, **args): issue_key = args["issue key"] # accountId = self.all_users[args["assignee name"]]["accountId"] accountId = '5c8ff4c490e2362d44935496' url = "/rest/api/2/issue/" + issue_key + "/assignee" api = self.base_url + url headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps({"accountId": accountId}) response = requests.request("PUT", api, data=payload, auth=self.auth, headers=headers) if response.status_code != 204: self.output = "Error assigning the issue" else: self.output = "Issue assigned successfully to {person}".format( person=args["assignee name"]) self.mail_body = { "Status": "Issue assign successfully", "Issue key": issue_key, "Assignee": accountId } send_mail.sendMail(self.mail_body) return self.output
def getSpecificProjectDetails(self, **args): print("I am getting calling in here") project_key = args["project key"] url = '/rest/api/2/project/' + project_key api = self.base_url + url headers = {"Accept": "application/json"} response = requests.request("GET", api, auth=self.auth, headers=headers) if response.status_code != 200: self.output = "Project not found in the workshape or dont have required permissions" else: response = json.loads(response.text) self.output = "Project {name} is found. Its lead name is {lead_name}".format( name=response["name"], lead_name=response["lead"]["displayName"]) print("I am here also") print(self.output) self.mail_body = { "Project name": response["name"], "Project ID": response["id"], "Project key": response["key"], "Project lead name": response["lead"]["displayName"], "Project lead ID": response["lead"]["accountId"] } send_mail.sendMail(self.mail_body) return self.output
def createIssue(self, **args): # for epic, epic name is needed # for subtask, there should be a parent id # issue types: 10000(epic), 10001(story), 10002(task), 10003(subtask), 10004(bug) summary = args["summary"] # project_id = self.all_projects[args["project key"]]["projectId"] project_id = args["project id"] issue_type = args["issue type"] if issue_type.lower() == "epic": issue_id = "10000" elif issue_type.lower() == "story": issue_id = "10001" elif issue_type.lower() == "task": issue_id = "10002" elif issue_type.lower() == "subtask": issue_id = "10003" elif issue_type.lower() == "bug": issue_id = "10004" url = "/rest/api/2/issue" api = self.base_url + url headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps({ "fields": { "summary": summary, # "parent" : {"id" : "10017"}, "project": { "id": project_id }, "issuetype": { "id": issue_id }, # "description": description, # "reporter" : {"id": reporter}, # "assignee" : {"name": "Tarun Agarwal"}, # "priority" : {"id": "2"} } }) response = requests.request("POST", api, auth=self.auth, headers=headers, data=payload) if response.status_code != 201: self.output = "Error in issue creation" else: response = json.loads(response.text) self.output = "Issue created successfully with id {id} and key {key}".format( id=response["id"], key=response["key"]) self.mail_body = { "Issue id": response["id"], "Issue key": response["key"] } send_mail.sendMail(self.mail_body) return self.output
def createNewRepo(self, **args): reponame = args["repo name"] try: self.git.get_user().create_repo(reponame) self.output = "Successfully created." self.mail_body = {"Repo name": reponame} send_mail.sendMail(self.mail_body) except: self.output = "Error in creating repository." # speak.say(self.output) return self.output
def createNewIssue(self, **args): reponame = args["repo name"] title = args["title"] try: repo = self.git.get_user().get_repo(reponame) repo.create_issue(title=title) self.output = "Successfully created the issue." self.mail_body = {"Repo name": reponame, "title": title} send_mail.sendMail(self.mail_body) except: self.output = "Error in creating the issue." # speak.say(self.output) return self.output
def getLatestCommitDateOfUser(self, **args): try: author = self.git.get_user().login commits = self.git.search_commits(query='author:' + author + ' sort:author-date-desc') data = commits.get_page(0) cdate = str(data[0].commit.committer.date) self.output = "The latest commit date is " + cdate self.mail_body = {"Latest Commit date": cdate} send_mail.sendMail(self.mail_body) except: self.output = "Error in getting the details" # speak.say(self.output) return self.output
def closeIssueByNumber(self, **args): reponame = args["repo name"] issue_number = int(args["issue number"]) repo = self.git.get_user().get_repo(reponame) open_issue = repo.get_issue(number=issue_number) open_issue.edit(state='closed') self.output = "The issue is closed" self.mail_body = { "Repo name": reponame, "Issue number": issue_number, "issue state": "closed" } send_mail.sendMail(self.mail_body) # speak.say(self.output) return self.output
def issueTransition(self, **args): issue_key = args["issue key"] transition_type = args["transition type"] transition = {"to do": "11", "in progress": "21", "done": "31"} transition_id = transition[transition_type.lower()] url = "/rest/api/2/issue/" + issue_key + "/transitions" api = self.base_url + url headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps({ "transition": { "id": transition_id } # "fields" : {"assignee": {"name" : assignee_name}} }) response = requests.request("POST", api, data=payload, headers=headers, auth=self.auth) if response.status_code != 204: self.output = "Error making issue transition" else: self.output = "Issue is transit to {type}".format( type=args["transition type"]) self.mail_body = { "Status": "Issue transition success", "Issue key": issue_key, "Transition level": args["transition type"] } send_mail.sendMail(self.mail_body) return self.output # jira = Jira() # jira.getSpecificProjectDetails("10000") # jira.createNewProject("TAR4", "tarunipm4", "software", "com.pyxis.greenhopper.jira:gh-simplified-scrum-classic", "5c8ff4c490e2362d44935496", "UNASSIGNED") # jira.getCreateIssueMetadata() # jira.createIssue("This is my task", "10006", "10002") # jira.getIssue("TAR3-2") # jira.deleteIssue("TAR3-4") # jira.assignIssue("TAR3-5", "5c8ff4c490e2362d44935496") # jira.deleteProject("TAR4") # jira.getTransitions("10017") # jira.issueTransition("TAR3-2", "11")
def closeAllOpenIssues(self, **args): reponame = args["repo name"] try: repo = self.git.get_user().get_repo(reponame) open_issues = repo.get_issues(state='open') for issue in open_issues: issue.edit(state='closed') self.output = "All the issues are closed" self.mail_body = { "Repo name": reponame, "issue state": "All issues are closed" } send_mail.sendMail(self.mail_body) except: self.output = "Error in closing the issues." # speak.say(self.output) return self.output
def listOfOpenIssues(self, **args): reponame = args["repo name"] try: repo = self.git.get_user().get_repo(reponame) open_issues = repo.get_issues(state='open') openiss=list() for issue in open_issues: openiss.append(issue) if openiss: self.output = "The open issues are: "+" ".join(map(str, openiss)) self.mail_body.update({'Issues':openiss}) send_mail.sendMail(self.mail_body) else: self.output = "No issues found" except: self.output="Error in getting the information" # speak.say(self.output) return self.output
def getLabelsOfRepo(self, **args): reponame = args["repo name"] try: repo = self.git.get_user().get_repo(reponame) labels = repo.get_labels() lab = list() for label in labels: lab.append(label.name) if lab: self.output = "The labels are: " + " ".join(map(str, lab)) self.mail_body.update({'Issues': lab}) send_mail.sendMail(self.mail_body) else: self.output = "No labels found" except: self.output = "Error in geeting the information" # speak.say(self.output) return self.output
def getIssueByNumber(self, **args): reponame = args["repo name"] issue_number = int(args["issue number"]) try: repo = self.git.get_user().get_repo(reponame) iss = repo.get_issue(number=issue_number) # print(iss.title) self.output = "The issue is " + iss.title self.mail_body = { "Repo name": reponame, "Issue number": issue_number, "issue": iss.title } send_mail.sendMail(self.mail_body) except: self.output = "Error in getting the issue." # speak.say(self.output) return self.output
def deleteFileFromRepo(self, **args): reponame = args["repo name"] filename = args["file name"] try: repo = self.git.get_user().get_repo(reponame) contents = repo.get_contents(filename) repo.delete_file(contents.path, "removed "+filename, contents.sha) self.output="Successfully deleted the file." self.mail_body={ "Repo name":reponame, "File Name":filename, "Commit Message":"removed the file" } send_mail.sendMail(self.mail_body) except: self.output="Error in deleting the file" # speak.say(self.output) return self.output
def deleteProject(self, **args): project_key = args["project key"] url = "/rest/api/2/project/" + project_key api = self.base_url + url headers = {"Accept": "application/json"} response = requests.request("DELETE", api, auth=self.auth, headers=headers) if response.status_code != 204: self.output = "Project cant be deleted" else: self.output = "Project successfully deleted" self.mail_body = { "Status": "Delete project success", "Project key": project_key } send_mail.sendMail(self.mail_body) return self.output
def deleteIssue(self, **args): issue_key = args["issue key"] url = "/rest/api/2/issue/" + issue_key api = self.base_url + url headers = {"Accept": "application/json"} response = requests.request("DELETE", api, auth=self.auth, headers=headers) if response.status_code != 204: self.output = "Error deleting the issue" else: self.output = "Issue deleted successfully" self.mail_body = { "Status": "Issue delete success", "Issue key": issue_key } send_mail.sendMail(self.mail_body) return self.output
def searchRepoWithGoodFirstIssue(self, **args): try: repositories = self.git.search_repositories(query='good-first-issues:>3') gfissue=list() for i, repo in enumerate(repositories): # print(repo.name) gfissue.append(repo.name) if gfissue: self.output = "The repositories with good first issue are: "+" ".join(map(str, gfissue)) self.mail_body.update({'Issues':gfissue}) else: self.output = "No issues found" if i==10: #10 repo only break send_mail.sendMail(self.mail_body) except: self.output="Error in getting the information" # speak.say(self.output) return self.output
def getAllContentsOfRepo(self, **args): reponame = args["repo name"] try: repo = self.git.get_user().get_repo(reponame) contents = repo.get_contents("") cont=list() for content_file in contents: # print(content_file.path) cont.append(content_file.path) if cont: self.output = "The contents of the repo are: "+" ".join(map(str, cont)) self.mail_body.update({'Issues':cont}) send_mail.sendMail(self.mail_body) else: self.output = "No labels found" except: self.output="Error in geeting the information" # speak.say(self.output) return self.output
def createIssueWithLabel(self, **args): reponame = args["repo name"] title = args["title"] labels = args["label"] try: repo = self.git.get_user().get_repo(reponame) label = repo.get_label(labels) repo.create_issue(title=title, body=body, labels=[label]) self.output = "Successfully created the issue." self.mail_body = { "Repo name": reponame, "title": title, "body": body, "labels": labels } send_mail.sendMail(self.mail_body) except: self.output = "Error in creating issue." # speak.say(self.output) return self.output
def createNewFileInRepo(self, **args): reponame = args["repo name"] filename = args["file name"] description = "This is the default description given by IPM" commit = "Added a file {0} by IPM".format(filename) try: repo = self.git.get_user().get_repo(reponame) #to avoid passing username, use get_user() repo.create_file(filename, commit, description) self.output="Successfully created the file." self.mail_body={ "Repo name":reponame, "File Name":filename, "Commit Message":commit, "Description":description } send_mail.sendMail(self.mail_body) except: self.output="Error in creating the file" # speak.say(self.output) return self.output
def searchRepoByLanguage(self, **args): lan = args["language"] try: foundRepos = list() for repo in self.git.get_user().get_repos(): if repo.language == lan: # print(repo.name) foundRepos.append(repo.name) if foundRepos: self.output = "The repositories in language " + lan + " are: " + " ".join(map(str, foundRepos)) self.mail_body.update({'Repo name':foundRepos}) # print(self.mail_body) # print(self.output) send_mail.sendMail(self.mail_body) else: self.output = "No such repository found." except: self.output ="Error in getting the information" # speak.say(self.output) return self.output