def projectreleasestatus(token, projectname): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] data = json.loads(tokenValidator[1].to_json()) org_name = data["github_creds"]["org_name"] milestone_url = "https://api.github.com/repos/{}/{}/milestones?sort=due_on" milestone_url = milestone_url.format(org_name, projectname) github_creds = githubCredBuilder(data) resp = requests.get(milestone_url, headers=github_creds) if resp.status_code != 200: return { "statusCode": 301, "reason": resp.json(), "message": "Milestone Request Failed" } resp = resp.json() if len(resp) < 1: return {"statusCode": 301, "message": "No Milestone Found"} milestone = resp[0] issues_url = "https://api.github.com/repos/{}/{}/issues?state=all&labels=urgent&milestone={}" issues_url = issues_url.format(org_name, projectname, milestone["number"]) resp = requests.get(issues_url, headers=github_creds) if resp.status_code != 200: return { "statusCode": 301, "reason": resp.json(), "message": "Milestone Request Failed" } milestone["urgent_issues"] = resp.json() return {"statusCode": 200, "milestone": milestone}
def createIntegrations(token, data): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] if data.get("trello", False): trello = TrelloCredentials( trelloAPIkey=data["trello"]["apikey"], trelloAPISecret=data["trello"]["apisecret"], board=data["trello"]["board"] ) tokenValidator[1].update(set__trello_creds=trello) if data.get("github", False): github = GithubCredentials( git_username=data["github"]["username"], git_personal_token=data["github"]["personal_token"], org_name=data["github"]["orgname"] ) tokenValidator[1].update(set__github_creds=github) if data.get("confluence", False): pass if data.get("travis", False): tokenValidator[1].update(set__travis_creds=data["travis"]["apikey"]) return { "statusCode":200, "messages": "Integrations Created/Updated Successfully" }
def buildResult(token, projectname): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] data = json.loads(tokenValidator[1].to_json()) org_name = data["github_creds"]["org_name"] travis_endpoint = "https://api.travis-ci.org/repos/{}/{}/builds" travis_endpoint = travis_endpoint.format(org_name, projectname) resp = requests.get(travis_endpoint) if resp.status_code != 200: return { "statusCode": 301, "message": "Build Status Failed to Fetch. Please chek to see if your repo is private or not?" } resp = resp.json() if len(resp) < 1: return { "statusCode": 301, "message": "Jarvis Failed to Find a Build for this project. Have you setup travis ci correctly for this repository?" } message_builder = "Total Number of builds run for this project are {}. " message_builder = message_builder.format(len(resp)) message_builder += "Total build time of all completed builds was {} {}. " a, b = timebuilder(sum([i["duration"] for i in resp])) message_builder = message_builder.format(a, b) first_item = resp[0] message_builder += "The latest build was started at {}. " message_builder = message_builder.format( parse(first_item["started_at"]).strftime("%I:%M %p %d %B, %Y")) if first_item["state"] == "finished": message_builder += "It finished {} {} ago with status as" a, b = timebuilder((datetime.now(timezone.utc) - parse(first_item["finished_at"])).seconds) message_builder = message_builder.format(a, b) badge_url = "https://api.travis-ci.org/{}/{}.svg?branch={}" resp = requests.get( badge_url.format(org_name, projectname, first_item["branch"])) if resp.text.find("passing") != -1: message_builder += " build passed. " elif resp.text.find("failing") != -1: message_builder += " build failed. " else: message_builder += " build invalid. " message_builder += "This build was triggered in response to {} with commit message {} on branch {}." message_builder = message_builder.format( first_item["event_type"], first_item["message"].lower()[:100], first_item["branch"]) return {'statusCode': 200, 'message': message_builder}
def listIntegrations(token): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] data = json.loads(tokenValidator[1].to_json()) data = { "trello_creds": data["trello_creds"], "travis_creds": data["travis_creds"], "github_creds": data["github_creds"], "confluence_url": data["confluence_url"], "email": data["email"], "zoom": generate_jwt() } return {"statusCode": 200, "data": data}
def listgitrepos(token): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] data = json.loads(tokenValidator[1].to_json()) org_name = data["github_creds"]["org_name"] url = "https://api.github.com/orgs/{}/repos".format(org_name) resp = requests.get(url, headers=githubCredBuilder(data)) if resp.status_code != 200: return { "statusCode": 301, "reason": resp.json(), "message": "Repository Request Failed" } else: data = resp.json() reponames = [] for i in data: reponames.append({"name": i["name"]}) data = {"statusCode": 200, "data": reponames} return data
def featureDevelopmentSummary(token, projectname, issuename): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] data = json.loads(tokenValidator[1].to_json()) org_name = data["github_creds"]["org_name"] github_creds = githubCredBuilder(data) issues_url = "https://api.github.com/repos/{}/{}/issues?state=all" issues_url = issues_url.format(org_name, projectname) resp = requests.get(issues_url, headers=github_creds) if resp.status_code != 200: return { "statusCode": 301, "reason": resp.json(), "issues_url": issues_url, "message": "Issues Request Failed" } for i in resp.json(): if i["title"].lower() == issuename.lower(): issueNumber = i["number"] issueData = i timeline_url = "https://api.github.com/repos/{}/{}/issues/{}/timeline" timeline_url = timeline_url.format(org_name, projectname, issueNumber) github_creds["Accept"] = "application/vnd.github.mockingbird-preview" timelineresp = requests.get(timeline_url, headers=github_creds) if timelineresp.status_code != 200: return { "statusCode": 301, "reason": timelineresp.json(), "timeline_url": timeline_url, "message": "Could not get feature timeline" } timelineresp = timelineresp.json() metadata_str = "This feature request was first added by {} on {} and was last updated {} {} ago. The current feature description is: {} The client has added {} extra comments on it." a, b = timebuilder( ( datetime.now(timezone.utc) - parse(issueData["updated_at"]) ).seconds ) metadata_str = metadata_str.format( issueData["user"]["login"], parse(issueData["created_at"]).strftime("%I:%M %p %d %B, %Y"), a, b, issueData["body"], issueData["comments"] ) if issueData["comments"] != 0: comments_url = "https://api.github.com/repos/{}/{}/issues/{}/comments" comments_url = comments_url.format(org_name, projectname, issueNumber) resp = requests.get(comments_url, headers={"Authorization": github_creds["Authorization"]}) if resp.status_code == 200 and len(resp.json()) >= 1: comment_data = "The most recent comment by the customer is: " + resp.json()[-1]["body"][: 150] metadata_str += comment_data restr_timeline = [] for i in timelineresp: if i["event"] in ["closed", "labeled", "milestoned", "closed", "reopened", "referenced", "assigned", "commented"]: i["created_at"] = parse(i["created_at"]).strftime("%I:%M %p %d %B, %Y") i["actor"] = i["actor"]["login"] restr_timeline.append(i) changehistory_str = "Now we will begin with the detailed change history of the feature timeline. " changehistory_str = "" for i in restr_timeline: if i == restr_timeline[0]: content = "Firstly, " elif i == restr_timeline[-1]: content = "Lastly, " else: content = "Then, " if i["event"] == "labeled": content += "a label {} was added on the feature request by {} on {}. ".format(i["label"]["name"], i["actor"], i["created_at"]) elif i["event"] == "milestoned": content += "this feature request {} was added by {} on {}. ".format(i["milestone"]["title"], i["actor"], i["created_at"]) elif i["event"] == "closed": content += "this feature request was closed by {} on {}. ".format(i["actor"], i["created_at"]) elif i["event"] == "reopened": content += "this feature request was reopened by {} on {}. ".format(i["actor"], i["created_at"]) elif i["event"] == "assigned": content += "this feature request was assigned to {} by {} on {}. ".format(i["assignee"]["login"], i["actor"], i["created_at"]) elif i["event"] == "referenced": content += "this feature request was referenced by {} via commit id {} on {}. ".format(i["actor"], i["commit_id"], i["created_at"]) elif i["event"] == "commented": content += "this feature request was commented on by {} at {}. He said that {}".format(i["actor"], i["created_at"], i["body"]) changehistory_str += content return { "statusCode": 200, "change_history": changehistory_str, "metadata_string": metadata_str }
def helpwithinstallation(token, projectname, needDocker=False, OS="ubuntu"): tokenValidator = validateToken(token) if not tokenValidator[0]: return tokenValidator[1] data = json.loads(tokenValidator[1].to_json()) org_name = data["github_creds"]["org_name"] url = "https://raw.githubusercontent.com/{}/{}/master/README.md".format( org_name, projectname ) resp = requests.get(url) if resp.status_code != 200: return { "statusCode": 200, "message": "I am extremely sorry but no installation instructions were found on your repository. You are on your own for this one." } resp = resp.text soup = BeautifulSoup( markdown2.markdown(resp), "html.parser" ) instrSet = {} for i in soup.find_all("code"): instructions = i.get_text() print(instructions, type(instructions)) if instructions[0:4] == "bash": if instructions.find("apt") != -1: instrSet["ubuntu"] = instructions[5:].strip().split("\n") elif instructions.find("yum"): instrSet["redhat"] = instructions[5:].strip().split("\n") elif instructions[0:6] == "shell": instrSet["windows"] = instructions[7:].strip().split("\n") else: instrSet["macos"] = instructions[7:].strip().split("\n") if instrSet == {}: return { "statusCode": 200, "message": "I am extremely sorry but no installation instructions were found on your repository. You are on your own for this one." } if not needDocker: return { "statusCode": 200, "instructions": instrSet.get( OS, "Sorry this software doesn't install on your OS" ) } dockerFile = """ # Pull base image. FROM ubuntu:18.04 # Install. RUN \ sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \ apt-get update && \ apt-get -y upgrade && \ apt-get install -y build-essential && \ apt-get install -y software-properties-common && \ apt-get install -y byobu curl git htop man unzip vim wget && \ rm -rf /var/lib/apt/lists/* && \ {} # Add files. ADD root/.bashrc /root/.bashrc ADD root/.gitconfig /root/.gitconfig ADD root/.scripts /root/.scripts # Set environment variables. ENV HOME /root # Define working directory. WORKDIR /root # Define default command. CMD ["bash"] """.format("&&\\\n".join(i for i in instrSet["ubuntu"])) return mailInstallationInstructions(dockerFile,data["email"])