def _create_issue(self): # create issue on the server uri = "repos/%s/issues" % self.repo url = github.url(uri) data = utils.clean_data(copy.deepcopy(self.data), ["state"]) if not data or len(data.keys()) == 0: utils.log("New issues require title/body") return data, status = github.request(url, "post", data) if not status: utils.log(data) return # update attributes as needed for object self.number = str(data["number"]) self.data["user"] = data["user"]["login"] self.url = data["html_url"] self.issue_uri = "repos/%s/issues/%s" % (self.repo, self.number) self.comments.number = self.number # clean up hash del i_hash["%s/%s" % (self.repo, "new")] i_hash["%s/%s" % (self.repo, self.number)] = self # delete the old buffer that we don't need any more vim.command("silent new") vim.command("bdelete %s" % self.buffer_name)
def test_github_post_request(self): defaults = { "title": "Title", } url = github.url("repos/jonmorehouse/issues/issues", self.params) data, status = github.request(url, "post", defaults)
def _get_data(self): self.data = copy.deepcopy(self.defaults) # get issue from github api if not new if not self.number == "new": data, status = github.request(github.url(self.issue_uri)) if not status: utils.log(data) return # issue was successfully requested for key in self.defaults.keys() + ["assignee", "user"]: # github will return None if key in ("assignee", "user") and data.get(key): self.data[key] = data[key]["login"] elif key == "labels": self.data[key] = [str(label["name"]) for label in data[key]] elif key == "milestone" and data.get("milestone"): self.data[key] = data[key]["title"] elif data.get(key): self.data[key] = data[key] # grab the browse url self.url = data["html_url"]
def _get_issues(self, **kwargs): self.issues = [] #(number, title, @username, url) uri = "repos/%s/issues" % self.repo # prepare kwargs for getting the correct issues kwargs = utils.clean_data(copy.deepcopy(kwargs), ("repo"), (("label", "labels"),)) url = github.url(uri, kwargs) data, status = github.request(url, "get") # this generates the visible list for issues that we will be handling for ih in data: # ih = issue_hash issue = (ih["number"], ih["title"], ih["user"]["login"], ih["state"], ih["url"], [l.get("name") for l in ih["labels"]]) self.issues.append(issue)
def _get_comments(self): if self.number == "new": return # make the request as needed url = github.url(self.uri) data, status = github.request(url, "get") if not status: return for comment in data: self._cache_comment(comment)
def setUp(self): self.endpoint = "repos/jonmorehouse/issues/issues" self.params = {"state": "all"} self.url = github.url(self.endpoint, self.params)
def test_github_paging_request(self): url = github.url("repos/jaxbot/github-issues.vim/issues", self.params) data, status = github.request(url) self.assertTrue(data) self.assertTrue(status)
def test_github_url(self): # test a path path = github.url(self.endpoint, self.params) self.assertTrue(len(path) > 0)
def _save_issue(self): # get ready for the patch operation url = github.url(self.issue_uri) data = utils.clean_data(copy.deepcopy(self.data), ["number", "user", "labels"]) data, status = github.request(url, "patch", data)
def _create_comment(self, body): url = github.url(self.uri) data, status = github.request(url, "post", {"body": body}) self._cache_comment(data)
def _delete_comment(self, cid): url = github.url(self.comments[cid]["url"]) del self.comments[cid] data, status = github.request(url, "delete")