Skip to content

Commit

Permalink
feat: stop supporting phabricator
Browse files Browse the repository at this point in the history
  • Loading branch information
linjiX committed Jan 18, 2024
1 parent 7922043 commit dfbdb77
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 212 deletions.
44 changes: 4 additions & 40 deletions hit/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,23 @@
"""Implementation of hit auth."""

from configparser import ConfigParser
from typing import Tuple

import click
from github import Github
from github.GithubException import BadCredentialsException

from hit.conduit import Conduit, ConduitError
from hit.utility import config_filepath, fatal_and_kill


def _implement_auth(phabricator: bool) -> None:
def _implement_auth() -> None:
config_parser = ConfigParser()
config_file = config_filepath()
config_parser.read(config_file)

if phabricator:
phabricator_url, phabricator_token = _auth_for_phabriactor()
github_token = _auth_for_github()

config_parser.add_section("phabricator")
config_parser["phabricator"]["url"] = phabricator_url
config_parser["phabricator"]["token"] = phabricator_token
else:
github_token = _auth_for_github()

config_parser.add_section("github")
config_parser["github"]["token"] = github_token
config_parser.add_section("github")
config_parser["github"]["token"] = github_token

with open(config_file, "w", encoding="utf-8") as fp:
config_parser.write(fp)
Expand Down Expand Up @@ -61,30 +52,3 @@ def _auth_for_github() -> str:
click.echo(f"\n> Github auth as {welcome_message}.\n")

return github_token # type: ignore[no-any-return]


def _auth_for_phabriactor() -> Tuple[str, str]:
click.echo("=" * 80)
click.secho("Phabricator Auth:", fg="green")

url = click.prompt("\nInput the Phabricator URL")
if not url.endswith("/"):
url += "/"

conduit_url = click.style(f"{url}conduit/login/", underline=True)

click.echo(f"\n> Visit {conduit_url} to generate your API Token.")
token = click.prompt("\nPaste your Phabricator API Token here")

conduit = Conduit(url, token)
try:
phabricator_user = click.style(conduit.get_user(), bold=True)
except ConduitError as error:
if error.code != "ERR-INVALID-AUTH":
raise

fatal_and_kill("Invalid Phabricator Token!")

click.echo(f"\n> Phabricator auth as {phabricator_user}.")

return url, token
12 changes: 3 additions & 9 deletions hit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ def hit() -> None:


@hit.command()
@click.option("-p", "--phabricator", is_flag=True, help="Auth for Phabricator.")
def auth(phabricator: bool) -> None:
"""Get Github Auth for hit CLI.\f
Arguments:
phabricator: Whether auth with Phabricator.
""" # noqa: D415, D301
def auth() -> None:
"""Get Github Auth for hit CLI.\f""" # noqa: D415, D301
from hit.auth import _implement_auth

_implement_auth(phabricator)
_implement_auth()


@hit.command()
Expand Down
131 changes: 0 additions & 131 deletions hit/conduit.py

This file was deleted.

33 changes: 1 addition & 32 deletions hit/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
"""Implementation of hit push."""

import sys
from configparser import SectionProxy
from subprocess import PIPE, CalledProcessError, run
from typing import Optional, Tuple
from typing import Tuple

import click
from github import Github, GithubException, PullRequest, Repository

from hit.conduit import Conduit
from hit.utility import (
ENV,
clean_commit_message,
Expand Down Expand Up @@ -45,14 +43,9 @@ def _implement_push(force: bool) -> None:

pulls_count = pulls.totalCount
if pulls_count == 0:
task = _extract_phab_task(branch) if config.has_section("phabricator") else None

_git_push(branch, force)
pull_request = _create_pull_request(repo, f"{origin_name.split('/', 1)[0]}:{branch}")

if task:
_link_phab_task(config["phabricator"], task, pull_request.html_url)

click.secho("\n> Pull Requset Created:", fg="green")
elif pulls_count == 1:
_git_push(branch, force)
Expand All @@ -73,30 +66,6 @@ def _implement_push(force: bool) -> None:
sys.exit(1)


def _extract_phab_task(branch: str) -> Optional[int]:
if not branch.startswith("T"):
return None

index = branch.find("_")
task = branch[1:index] if index != -1 else branch[1:]

try:
return int(task)
except ValueError:
return None


def _link_phab_task(config: SectionProxy, task: int, html_url: str) -> None:
url = config["url"]
token = config["token"]

conduit = Conduit(url, token)
conduit.append_to_description(task, html_url)

click.secho("\n> Phabricator Task Linked:", fg="green")
click.secho(f"{url}T{task}", underline=True)


def _git_push(branch: str, force: bool) -> None:
click.secho("> Pushing:", bold=True)

Expand Down

0 comments on commit dfbdb77

Please sign in to comment.