Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read github credentials from git credential helper #131

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions revup/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,38 @@ async def soft_reset(self, new_commit: GitCommitHash, env: Dict) -> None:

# TODO: only strictly needs to drop entries for HEAD
self.clear_cache()

async def credential(self, **kwargs: Dict[str, str]) -> str:
cred = Credential(self, description=kwargs)
await cred.fill()
return cred.password


class Credential():
git_ctx: Git
description: Dict[str, str]

def __init__(self, git: Git, description: Dict[str, str]):
self.git_ctx = git
self.description = description

def __getattr__(self, attr):
return self.description[attr]

async def _run(self, subcommand, input: Dict[str, str]) -> Dict[str, str]:
input_str = "\n".join(f"{k}={v}" for k, v in input.items())
stdout_str = await self.git_ctx.git_stdout("credential", subcommand, input_str=input_str)
stdout = {}
for line in stdout_str.splitlines():
if line == "":
break
k, v = line.split("=", 1)
stdout[k] = v
return stdout

async def fill(self):
self.description = await self._run("fill", self.description)

async def report(self, success: bool):
cmd = "approve" if success else "reject"
await self._run(cmd, self.description)
7 changes: 7 additions & 0 deletions revup/revup.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ async def github_connection(
f"the same repo as the remote {args.remote_info}."
)

if not args.github_oauth:
args.github_oauth = await git_ctx.credential(
protocol="https",
host=args.github_url,
path=f"/{fork_info.owner}/{fork_info.name}.git",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leading "/" here is incorrect btw, and fails for credential helpers that do naive string matching on URL path 😞. It should be just path=f"{fork_info.owner}/{fork_info.name}.git"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's been working for me despite this but i guess there's some subtlety about which credential helpers are being used?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

if not args.github_oauth:
raise RevupUsageException(
"No Github OAuth token configured! "
Expand Down
Loading