Closed plyr4 closed 3 months ago
I'm okay with the baby steps approach. Add in the CLI pkg and let the user figure out how to get the token in there for now. Maybe someone will come along and add netrc support in CLI/cli#288 or Vela or this plugin can provision an envvar secret or build the gh-compatible config at runtime.
I think it might be possible to write a simple netrc -> gh hosts.yaml converter.
machine git.mycompany.com login myusername password gho_0000000000000000000
git.mycompany.com:
user: myusername
oauth_token: gho_0000000000000000000
git_protocol: https
users:
myusername:
oauth_token: gho_0000000000000000000
https://pkg.go.dev/golang.org/x/tools/cmd/auth/netrcauth provides a netrc impl, could spit out the YAML without much fuss.
Could include it as a separate tool or a subcommand of vela-git, invocable like:
steps:
- name: Convert netrc to gh yaml
image: target/vela-git:latest
commands:
# subcommand
- vela-git convert-netrc-to-gh-hosts
# helper script
- convert-netrc-to-gh-hosts
- name: Do stuff with gh
image: target/vela-git:latest
commands:
# subcommand
- gh pr list
A S.O. question on handling the netrc parsing:
I polished up something for myself: https://github.com/colindean/hejmo/commit/0062264618a45ec9cd31f072830e38481777a9f3
Description
it would be sweet if users could automatically interact with git using
gh
the official cli.we can add it to the plugin, meaning, throw in a
gh
installation into the Dockerfile and call it good https://github.com/go-vela/vela-git/blob/main/Dockerfile#L19but i dont think
gh
supports using the netrc forgh auth login
so it likely wont work "out of the box" for users unless they provide a PAThttps://github.com/cli/cli/issues/288 https://github.com/cli/cli/issues/3623
so... if we figure out auth, or move Vela away from netrc then this will be easier. or we can just install
gh
and let users figure that out on their own, but i dont think thats the best user experience. personally, i would expect it to "just work".