54 lines
1,005 B
Python
54 lines
1,005 B
Python
|
import click
|
||
|
import pydantic
|
||
|
|
||
|
import frg.forgejo.browser as forgejo_browser
|
||
|
|
||
|
from frg.context import get_git_context, GitContext
|
||
|
from frg.configuration import get_configuration, Config
|
||
|
|
||
|
|
||
|
class CliContext(pydantic.BaseModel):
|
||
|
config: Config
|
||
|
git: GitContext
|
||
|
|
||
|
|
||
|
@click.group()
|
||
|
@click.pass_context
|
||
|
def cli(ctx):
|
||
|
config = get_configuration()
|
||
|
git_context = get_git_context(domain_aliases=config.domain_aliases)
|
||
|
ctx.obj = CliContext(git=git_context, config=config)
|
||
|
|
||
|
|
||
|
@cli.command()
|
||
|
@click.pass_obj
|
||
|
def pr(ctx):
|
||
|
forgejo_browser.create_pull_request_via_web(
|
||
|
head=ctx.git.current_branch,
|
||
|
host=ctx.git.host,
|
||
|
repo=ctx.git.repo_name,
|
||
|
owner=ctx.git.repo_author,
|
||
|
)
|
||
|
|
||
|
|
||
|
@cli.group()
|
||
|
@click.pass_obj
|
||
|
def repo(ctx):
|
||
|
pass
|
||
|
|
||
|
|
||
|
@repo.command()
|
||
|
@click.pass_obj
|
||
|
def view(ctx):
|
||
|
forgejo_browser.view_repository_via_web(
|
||
|
host=ctx.git.host, repo=ctx.git.repo_name, owner=ctx.git.repo_author
|
||
|
)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
cli()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|