Skip to content

Commit

Permalink
vim plugin: simplified github api call.
Browse files Browse the repository at this point in the history
  • Loading branch information
reinhardt committed Dec 21, 2022
1 parent b513353 commit 522eda7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions plugin/octodon.vim
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def OctodonClock():

# expand ticket reference
from octodon.github import Github
from github3api import GitHubAPI
ticket_match = Github.ticket_pattern.search(line)
if ticket_match:
config = get_config()
Expand All @@ -142,15 +143,16 @@ def OctodonClock():
cmd = config.get("github", "token_command")
token = subprocess.check_output(cmd.split(" ")).strip().decode("utf-8")
config.set("github", "token", token)
github = Github(
config.get("github", "token"),
config.get("github", "organization"),
int(config.get("github", "project_num")),
)
issue_id = ticket_match[1]
issue = github.get_issue(issue_id)
githubapi = GitHubAPI(bearer_token=config.get("github", "token"))

org, repo, number = ticket_match.groups()[1:4]
try:
issue = githubapi.get(f"/repos/{org}/{repo}/issues/{number}")
except:
issue = None
if issue:
summary = issue.get_title()
issue_id = ticket_match[1]
summary = issue.get("title", "")
issue_text = f"{summary} {issue_id}"
if issue_text not in line:
line = line.replace(issue_id, issue_text)
Expand Down

0 comments on commit 522eda7

Please sign in to comment.