Open
Description
On the Git CLI, I can use git push -o <option>
for example git push -o merge_request.create
to supply string options with push
that are then processed on the server by i.e. the post-receive
hook to perform additional actions, like create a pull request automatically after the push etc. See GitLab's options as an example.
My failed attempt to recreate this with git2go
:
package main
import (
git "github.com/libgit2/git2go/v34"
log "github.com/sirupsen/logrus"
)
func main() {
repo, err := git.OpenRepository("/home/ml/Projects/demo")
if err != nil {
log.Fatal(err)
}
remote, err := repo.Remotes.Lookup("origin")
if err != nil {
remote, err = repo.Remotes.Create("origin", repo.Path())
if err != nil {
log.Fatal(err)
}
}
// ref
ref, err := repo.Head()
if err != nil {
log.Fatal(err)
}
// Get the name
branch := ref.Branch()
branchName, err := branch.Name()
if err != nil {
log.Fatal(err)
}
if err := remote.Push([]string{"refs/heads/" + branchName}, &git.PushOptions{
RemoteCallbacks: git.RemoteCallbacks{
CredentialsCallback: func(url string, username_from_url string, allowed_types git.CredentialType) (*git.Credential, error) {
return git.NewCredentialUserpassPlaintext("username", "pass")
},
},
Headers: []string{"merge_request.create:true"},
}); err != nil {
log.Fatal(err)
}
}
Is there a way to do this?
Metadata
Metadata
Assignees
Labels
No labels