Remove Interact Dependency Of Task Module (#280)
remove interact dependency in task module accept nil callback format code Reviewed-on: https://gitea.com/gitea/tea/pulls/280 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-Authored-By: 6543 <6543@obermui.de> Co-Committed-By: 6543 <6543@obermui.de>
This commit is contained in:
parent
5cb3e1ded5
commit
c98441b13c
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
|
@ -35,5 +36,5 @@ func runPullsCheckout(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return task.PullCheckout(login, owner, repo, idx)
|
||||
return task.PullCheckout(login, owner, repo, idx, interact.PromptPassword)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
|
@ -41,5 +42,5 @@ func runPullsClean(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return task.PullClean(login, owner, repo, idx, ctx.Bool("ignore-sha"))
|
||||
return task.PullClean(login, owner, repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
type pwCallback = func(ctx string) (string, error)
|
||||
type pwCallback = func(string) (string, error)
|
||||
|
||||
// GetAuthForURL returns the appropriate AuthMethod to be used in Push() / Pull()
|
||||
// operations depending on the protocol, and prompts the user for credentials if
|
||||
|
@ -32,10 +32,10 @@ func GetAuthForURL(remoteURL *url.URL, authToken, keyFile string, passwordCallba
|
|||
// try to select right key via ssh-agent. if it fails, try to read a key manually
|
||||
user := remoteURL.User.Username()
|
||||
auth, err = gogit_ssh.DefaultAuthBuilder(user)
|
||||
if err != nil {
|
||||
signer, err := readSSHPrivKey(keyFile, passwordCallback)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err != nil && passwordCallback != nil {
|
||||
signer, err2 := readSSHPrivKey(keyFile, passwordCallback)
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
}
|
||||
auth = &gogit_ssh.PublicKeys{User: user, Signer: signer}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func GetAuthForURL(remoteURL *url.URL, authToken, keyFile string, passwordCallba
|
|||
return nil, fmt.Errorf("don't know how to handle url scheme %v", remoteURL.Scheme)
|
||||
}
|
||||
|
||||
return auth, nil
|
||||
return
|
||||
}
|
||||
|
||||
func readSSHPrivKey(keyFile string, passwordCallback pwCallback) (sig ssh.Signer, err error) {
|
||||
|
|
|
@ -10,12 +10,12 @@ import (
|
|||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
local_git "code.gitea.io/tea/modules/git"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
)
|
||||
|
||||
// PullCheckout checkout current workdir to the head branch of specified pull request
|
||||
func PullCheckout(login *config.Login, repoOwner, repoName string, index int64) error {
|
||||
func PullCheckout(login *config.Login, repoOwner, repoName string, index int64, callback func(string) (string, error)) error {
|
||||
client := login.Client()
|
||||
|
||||
localRepo, err := local_git.RepoForWorkdir()
|
||||
|
@ -60,7 +60,7 @@ func PullCheckout(login *config.Login, repoOwner, repoName string, index int64)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auth, err := local_git.GetAuthForURL(url, login.Token, login.SSHKey, interact.PromptPassword)
|
||||
auth, err := local_git.GetAuthForURL(url, login.Token, login.SSHKey, callback)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,14 +9,13 @@ import (
|
|||
|
||||
"code.gitea.io/tea/modules/config"
|
||||
local_git "code.gitea.io/tea/modules/git"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
git_config "github.com/go-git/go-git/v5/config"
|
||||
)
|
||||
|
||||
// PullClean deletes local & remote feature-branches for a closed pull
|
||||
func PullClean(login *config.Login, repoOwner, repoName string, index int64, ignoreSHA bool) error {
|
||||
func PullClean(login *config.Login, repoOwner, repoName string, index int64, ignoreSHA bool, callback func(string) (string, error)) error {
|
||||
client := login.Client()
|
||||
|
||||
repo, _, err := client.GetRepo(repoOwner, repoName)
|
||||
|
@ -79,7 +78,7 @@ call me again with the --ignore-sha flag`, pr.Head.Ref)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auth, err := local_git.GetAuthForURL(url, login.Token, login.SSHKey, interact.PromptPassword)
|
||||
auth, err := local_git.GetAuthForURL(url, login.Token, login.SSHKey, callback)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue