def post(self, url_path): last_row = UploadURL.all().order("-created_at").get() if last_row: if last_row.url_path == url_path: try: payload = json.loads(self.request.get("payload")) logging.info(payload) except json.JSONDecodeError: self.error(400) self.response.out.write("Incorrect request format\n") user_repo = payload["repository"]["full_name"] # Download complete pull request with information about mergeability pull_request = github_get_pull_request(user_repo, payload["number"]) num = payload["number"] # Get the old entity or create a new one: p = PullRequest.all() p.filter("num =", int(num)) p = p.get() if p is None: p = PullRequest(num=num) # Update all data that we can from GitHub: p.url = pull_request["html_url"] p.state = pull_request["state"] p.title = pull_request["title"] p.body = pull_request["body"] p.mergeable = pull_request["mergeable"] if pull_request["head"]["repo"]: p.repo = pull_request["head"]["repo"]["url"] p.branch = pull_request["head"]["ref"] p.author_name = pull_request["user"].get("name", "") p.author_email = pull_request["user"].get("email", "") created_at = pull_request["created_at"] created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ") p.created_at = created_at u = User.all() u.filter("login ="******"user"]["login"]) u = u.get() if u is None: u = User(login=pull_request["user"]["login"]) u.id = pull_request["user"]["id"] u.avatar_url = pull_request["user"]['avatar_url'] u.url = pull_request["user"]["url"] u.put() p.author = u p.put() else: self.error(404) self.response.out.write("Requesting URL doesn't exist\n") else: self.error(500) self.response.out.write("URL for posting data not defined yet\n")
def post(self): user_repo = polled_user + "/" + polled_repo payload = github_get_pull_request_all_v3(user_repo) # checkout mergeability for pos in xrange(len(payload)): pull = github_get_pull_request(user_repo, payload[pos]["number"]) payload[pos]["mergeable"] = pull["mergeable"] # Process each pull request from payload for pull in payload: p = PullRequest.all() num = pull["number"] p.filter("num =", num) p = p.get() if p is None: p = PullRequest(num=num) p.url = pull["html_url"] p.state = pull["state"] p.title = pull["title"] p.body = pull["body"] p.mergeable = pull["mergeable"] if pull["head"]["repo"]: p.repo = pull["head"]["repo"]["url"] p.branch = pull["head"]["ref"] created_at = pull["created_at"] created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ") p.created_at = created_at # Collect public information about user u = User.all() login = pull["user"]["login"] u.filter("login ="******"user"]["id"] u.avatar_url = pull["user"]["avatar_url"] u.url = pull["user"]["url"] u.put() p.author = u p.put()
def save(self, requester, repo, assigner=None): commit_msg = self.cleaned_data["commit_msg"] from_head = self.cleaned_data["from_head"] to_head = self.cleaned_data["to_head"] commit_hexsha = self.cleaned_data["commit"] comment = self.cleaned_data["comment"] pull = PullRequest() pull.commit_msg = commit_msg pull.from_head = from_head pull.to_head = to_head pull.create_commit_hexsha = commit_hexsha pull.requester = requester pull.repo = repo if assigner: pull.assigner = assigner if comment: pull.comment = comment pull.save() return pull
def txn(): assert _type == "pullrequest" _num = int(self.request.get("num")) pull = github_get_pull_request("sympy/sympy", _num) p = PullRequest.all() p.filter("num =", int(_num)) p = p.get() if p is None: p = PullRequest(num=_num) p.url = pull['html_url'] p.state = pull["state"] p.title = pull["title"] p.body = pull["body"] p.mergeable = pull["mergeable"] if pull['head']['repo']: p.repo = pull['head']['repo']['url'] p.branch = pull['head']['ref'] p.author_name = pull["user"].get("name", "") p.author_email = pull["user"].get("email", "") created_at = pull["created_at"] created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ") p.created_at = created_at p.put()
def save(self, requester, repo, assigner = None): commit_msg = self.cleaned_data["commit_msg"] from_head = self.cleaned_data["from_head"] to_head = self.cleaned_data["to_head"] commit_hexsha = self.cleaned_data["commit"] comment = self.cleaned_data["comment"] pull = PullRequest() pull.commit_msg = commit_msg pull.from_head = from_head pull.to_head = to_head pull.create_commit_hexsha = commit_hexsha pull.requester = requester pull.repo = repo if assigner: pull.assigner = assigner if comment: pull.comment = comment pull.save() return pull