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 16, 2024
1 parent 1647887 commit aad9cce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ Syntax:
$ oca-port <source> <target> <module_path> [options]
$ oca-port --help

To check if an addon could be migrated or to get eligible commits to port:
GITHUB_TOKEN can be passed by exposing to environment:

$ export GITHUB_TOKEN=<token>

Alternatively, you can pass the token directly using the `--github-token` option

If neither method is used, the tool will attempt to obtain the token using the `gh` client (if it's installed).

To check if an addon could be migrated or to get eligible commits to port:

$ cd <path/to/OCA/cloned_repository>
$ oca-port origin/16.0 origin/18.0 <module_path> --verbose --dry-run

Expand Down
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
8 changes: 8 additions & 0 deletions oca_port/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
@click.option("--fetch", is_flag=True, help="Fetch remote branches from upstream.")
@click.option("--no-cache", is_flag=True, help="Disable user's cache.")
@click.option("--clear-cache", is_flag=True, help="Clear the user's cache.")
@click.option(
"--github-token",
is_flag=True,
help="""Token to use when requesting GitHub API (highly recommended
to not trigger the "API rate limit exceeded" error).""",
)
def main(
addon_path: str,
source: str,
Expand All @@ -114,6 +120,7 @@ def main(
no_cache: bool,
clear_cache: bool,
dry_run: bool,
github_token: str,
):
"""Migrate ADDON from SOURCE to TARGET or list Pull Requests to port.
Expand Down Expand Up @@ -148,6 +155,7 @@ def main(
clear_cache=clear_cache,
dry_run=dry_run,
cli=True,
github_token=github_token,
)
except ForkValueError as exc:
error_msg = prepare_remote_error_msg(*exc.args)
Expand Down

0 comments on commit aad9cce

Please sign in to comment.