Skip to content

Commit

Permalink
[IMP] intergrate gh tool
Browse files Browse the repository at this point in the history
  • Loading branch information
trisdoan committed Dec 11, 2024
1 parent 1647887 commit 167ddf7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion oca_port/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pathlib
from dataclasses import dataclass
import re
import subprocess

import git

Expand Down Expand Up @@ -109,7 +110,20 @@ def __post_init__(self):
self._check_branch_exists(self.source.ref, raise_exc=True)
self._check_branch_exists(self.target.ref, raise_exc=True)
# GitHub API helper
self.github = GitHub(self.github_token or os.environ.get("GITHUB_TOKEN"))
token = False
if os.environ.get("GITHUB_TOKEN"):
token = os.environ["GITHUB_TOKEN"]
else:
token = self.github_token
if not token:
try:
# get from gh
token = subprocess.check_output(
["gh", "auth", "token"], text=True
).strip()
except subprocess.SubprocessError:
pass
self.github = GitHub(token)
# Initialize storage & cache
self.storage = utils.storage.InputStorage(self.to_branch, self.addon)
self.cache = utils.cache.UserCacheFactory(self).build()
Expand Down

0 comments on commit 167ddf7

Please sign in to comment.