Updated agit doc for git-repo#27014
Conversation
Added basic reference instructions to unblock `git-repo` users who don't use Gerrit but use Gitea.
|
|
||
| 1. Create a file in `$GITEA_CUSTOM/public/` called `ssh_info` | ||
| 2. Populate it with `{"type":"agit","version":2}` | ||
| 3. Add a rewrite rule for your reverse proxy which rewrites the request path equaling `/ssh_info` to `/assets/ssh_info` |
There was a problem hiding this comment.
Don't we already provide a mechanism to put files into root, like /robots.txt? Or maybe that path is already occupied, not familiar with /ssh_info.
There was a problem hiding this comment.
The only one I could find was /assets/<file>, and repo/git-repo expect it to be at the root of the host 🤷🏼♀️
There was a problem hiding this comment.
The quite old "assets" handler logic is: if local file exists, then use it, otherwise, pass it to other handles.
However, the logic has been changed long time ago, the local file doesn't have higher priority than other handlers.
For example: if you have a file in {Custom}/public/my-name and an org my-name
- For quite old logic (very long time ago): the local file
{Custom}/public/my-nameis served- Users could serve any custom files without reverse proxy tweaks.
- For current logic (has been changed long time ago): the org
my-nameis severed.
TBH, the quite old logic looks good to me, while I guess some nice features were changed unintentionally by many round iterations.
There was a problem hiding this comment.
There is special handling for robots.txt to remain under the root path. Maybe we could include the ssh_info in the binary directly? It would require reserving the "ssh_info" username, but I think that would be acceptable as a "breaking" change.
There was a problem hiding this comment.
I would prefer to take the "quite old logic" back, then end users could still have the ability to serve any file in the web root.
There was a problem hiding this comment.
Hmm, gitea has defined /ssh_info router, but the type has been defined as gitea (example: https://try.gitea.io/ssh_info), That's because I'm not sure agit flow has been fully implement. looks need more work. and I hasn't checking whether gitea can be used with git-repo tool also.
There was a problem hiding this comment.
whether gitea can be used with
git-repotool also.
I'm working through why it hasn't been working as intended, and this is what I've found so far. If the router has implemented /ssh_info but it's wrong, then we should fix it. It's ultimately something from Gerrit:
|
Please send the patch to v1.21(main branch) first |
Is there a clear conclusion? Before doing future changes, I guess it should clarify the details first? There are 2 problems:
|
|
@mxplusb maybe you need this plugin, ref: https://github.com/alibaba/git-repo-go/blob/master/helper/proto-external.go package main
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"os"
"strings"
"github.com/alibaba/git-repo-go/cap"
"github.com/alibaba/git-repo-go/config"
"github.com/alibaba/git-repo-go/encode"
"github.com/alibaba/git-repo-go/helper"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "git-repo-helper-proto-gitea",
Usage: "gitea protocol helper for git repo",
Action: cmdMain,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "upload",
Usage: "for upload hook",
},
&cli.BoolFlag{
Name: "download",
Usage: "for download hook",
},
&cli.Int64Flag{
Name: "version",
Usage: "hook version",
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func getGitPushCommand(o *config.UploadOptions) (*helper.GitPushCommand, error) {
var (
gitPushCmd = helper.GitPushCommand{}
)
cmds := []string{"git", "push"}
if o.RemoteURL == "" {
return nil, errors.New("empty review url for helper")
}
gitURL := config.ParseGitURL(o.RemoteURL)
if gitURL == nil || (gitURL.Proto != "ssh" && gitURL.Proto != "http" && gitURL.Proto != "https") {
return nil, fmt.Errorf("bad review URL: %s", o.RemoteURL)
}
if !cap.GitCanPushOptions() {
log.Fatalln("cannot send push options, for your git version is too low")
}
for _, pushOption := range o.PushOptions {
cmds = append(cmds, "-o", pushOption)
}
refSpec := ""
localBranch := strings.TrimPrefix(o.LocalBranch, config.RefsHeads)
destBranch := strings.TrimPrefix(o.DestBranch, config.RefsHeads)
if localBranch == "" {
refSpec = "HEAD"
} else {
refSpec = config.RefsHeads + localBranch
}
if !o.CodeReview.Empty() {
log.Fatalln("gitea not support for-review now")
} else {
refSpec += fmt.Sprintf(":refs/for/%s/%s",
destBranch,
localBranch)
}
if o.Title != "" {
cmds = append(cmds, "-o", "title="+encode.B64Encode(o.Title))
}
if o.Description != "" {
cmds = append(cmds, "-o", "description="+encode.B64Encode(o.Description))
}
// TODO:
// if o.Issue != "" {
// cmds = append(cmds, "-o", "issue="+encode.B64Encode(o.Issue))
// }
// if o.People != nil && len(o.People) > 0 && len(o.People[0]) > 0 {
// reviewers := strings.Join(o.People[0], ",")
// cmds = append(cmds, "-o", "reviewers="+encode.B64Encode(reviewers))
// }
// if o.People != nil && len(o.People) > 1 && len(o.People[1]) > 0 {
// cc := strings.Join(o.People[1], ",")
// cmds = append(cmds, "-o", "cc="+encode.B64Encode(cc))
// }
// if o.NoEmails {
// cmds = append(cmds, "-o", "notify=no")
// }
// if o.Private {
// cmds = append(cmds, "-o", "private=yes")
// }
// if o.WIP {
// cmds = append(cmds, "-o", "wip=yes")
// }
// if o.OldOid != "" {
// cmds = append(cmds, "-o", "old-oid="+o.OldOid)
// }
if o.RemoteName != "" {
cmds = append(cmds, o.RemoteName)
} else {
cmds = append(cmds, o.RemoteURL)
}
cmds = append(cmds, refSpec)
gitPushCmd.Cmd = cmds[0]
gitPushCmd.Args = cmds[1:]
return &gitPushCmd, nil
}
func cmdUpload() error {
log.Printf("cmdUpload ...\n")
input, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
cfg := config.UploadOptions{}
err = json.Unmarshal(input, &cfg)
if err != nil {
log.Printf("Error: cmdUpload: %v\n", err)
return err
}
log.Printf("Debug: cmdUpload: %#v\n", cfg)
result, err := getGitPushCommand(&cfg)
if err != nil {
return err
}
resultBytes, err := json.Marshal(result)
if err != nil {
return err
}
_, err = os.Stdout.Write(resultBytes)
return err
}
func cmdDownload() error {
scan := bufio.NewScanner(os.Stdin)
if !scan.Scan() {
return errors.New("no input data")
}
parts := strings.SplitN(scan.Text(), " ", 3)
if len(parts) != 2 {
return errors.New("no enough params")
}
log.Println("cmdDownload: ", parts[0], parts[1])
fmt.Printf("refs/pull/%s/head\n", parts[0])
return nil
}
var logFp *os.File
type emptyWriter struct{}
func (e *emptyWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
func initLogFile() error {
debugFile := os.Getenv("GIT_REPO_GITEA_DEBUG")
if len(debugFile) == 0 {
log.SetOutput(&emptyWriter{})
return nil
}
var err error
logFp, err = os.OpenFile(debugFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
if err == nil {
log.SetOutput(logFp)
}
return err
}
func cmdMain(ctx *cli.Context) error {
if err := initLogFile(); err != nil {
return err
}
defer func() {
if logFp != nil {
logFp.Close()
}
}()
if ctx.Bool("upload") {
return cmdUpload()
}
if ctx.Bool("download") {
return cmdDownload()
}
return nil
} |
Added basic reference instructions to unblock
git-repousers who don't use Gerrit but use Gitea.