.
This commit is contained in:
parent
429cc2fe02
commit
f40888ea45
@ -202,3 +202,24 @@ func (e *RequestHandler) GitExec(cwd string, params ...string) ExecStream {
|
|||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type writerFunc func([]byte) (int, error)
|
||||||
|
|
||||||
|
// Implement the Write method for the custom type
|
||||||
|
func (f writerFunc) Write(p []byte) (int, error) {
|
||||||
|
return f(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *RequestHandler) GitSubmoduleCommitId(cwd, packageName string) (string, bool) {
|
||||||
|
if e.Error != nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("/usr/bin/git", "cat-file", "--batch")
|
||||||
|
cmd.Dir = filepath.Join(e.GitPath, cwd)
|
||||||
|
cmd.Stdout = writerFunc(func(p []byte) (int, error) {
|
||||||
|
return len(p), nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
transport "github.com/go-openapi/runtime/client"
|
transport "github.com/go-openapi/runtime/client"
|
||||||
@ -16,6 +15,8 @@ import (
|
|||||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const PrPattern = "PR: %s/%s#%d"
|
||||||
|
|
||||||
func (h *RequestHandler) allocateGiteaTransport() (*transport.Runtime, *apiclient.GiteaAPI) {
|
func (h *RequestHandler) allocateGiteaTransport() (*transport.Runtime, *apiclient.GiteaAPI) {
|
||||||
r := transport.New("src.opensuse.org", apiclient.DefaultBasePath, [](string){"https"})
|
r := transport.New("src.opensuse.org", apiclient.DefaultBasePath, [](string){"https"})
|
||||||
r.DefaultAuthentication = transport.BearerToken(giteaToken)
|
r.DefaultAuthentication = transport.BearerToken(giteaToken)
|
||||||
@ -200,17 +201,15 @@ func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.Pu
|
|||||||
h.Error = fmt.Errorf("cannot fetch PR list for %s / %s : %s", pr.Repository.Owner.Username, pr.Repository.Name, prs.Error())
|
h.Error = fmt.Errorf("cannot fetch PR list for %s / %s : %s", pr.Repository.Owner.Username, pr.Repository.Name, prs.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
payload_processing:
|
prLine := fmt.Sprintf(PrPattern, pr.Repository.Owner.Username, pr.Repository.Name, pr.Number)
|
||||||
|
|
||||||
|
// payload_processing:
|
||||||
for _, pr := range prs.Payload {
|
for _, pr := range prs.Payload {
|
||||||
lines := strings.Split(pr.Body, "\n")
|
lines := strings.Split(pr.Body, "\n")
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
r := regexp.MustCompile(`^PullRequest: ([^/]+)/([^/]+)#(\d+)$`)
|
if strings.TrimSpace(line) == prLine {
|
||||||
if m := r.FindSubmatch([]byte(line)); m != nil {
|
return pr
|
||||||
h.Log("match: %#v", m)
|
|
||||||
break payload_processing
|
|
||||||
} else {
|
|
||||||
h.Log("not matched: '%s'", line)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,29 @@ const (
|
|||||||
PrReview = "pr-review"
|
PrReview = "pr-review"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func processPullRequestClosed(h *common.RequestHandler) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func processPrjGitPullRequestSync(h *common.RequestHandler) error {
|
||||||
|
// req := h.Data.(*common.PullRequestAction)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func processPullRequestSync(h *common.RequestHandler) error {
|
func processPullRequestSync(h *common.RequestHandler) error {
|
||||||
req := h.Data.(*common.PullRequestAction)
|
req := h.Data.(*common.PullRequestAction)
|
||||||
|
|
||||||
// find prjgit pull request associated with this one
|
if req.Repository.Name == common.DefaultGitPrj {
|
||||||
h.GetAssociatedPrjGitPR(req)
|
return processPrjGitPullRequestSync(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// need to verify that submodule in the PR for prjgit
|
||||||
|
// is still pointing to the HEAD of the PR
|
||||||
|
prjPr := h.GetAssociatedPrjGitPR(req)
|
||||||
|
|
||||||
|
h.GitExec("", "clone", "--branch", prjPr.Head.Name, "--depth", "1", prjPr.Head.Repo.SSHURL, common.DefaultGitPrj)
|
||||||
|
commitId := h.GitSubmoduleCommitId(common.DefaultGitPrj, req.Repository.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -59,8 +77,8 @@ PullRequest: %s/%s#%d`, req.Repository.Owner.Username,
|
|||||||
fmt.Sprintf(`This is a forwarded pull request by %s
|
fmt.Sprintf(`This is a forwarded pull request by %s
|
||||||
referencing the following pull request:
|
referencing the following pull request:
|
||||||
|
|
||||||
PR: %s/%s#%d
|
`+common.PrPattern,
|
||||||
`, GitAuthor, req.Repository.Owner.Username, req.Repository.Name, req.Pull_Request.Number),
|
GitAuthor, req.Repository.Owner.Username, req.Repository.Name, req.Pull_Request.Number),
|
||||||
)
|
)
|
||||||
|
|
||||||
if h.HasError() {
|
if h.HasError() {
|
||||||
@ -80,9 +98,12 @@ func processPullRequest(h *common.RequestHandler) error {
|
|||||||
case "opened":
|
case "opened":
|
||||||
return processPullRequestOpened(h)
|
return processPullRequestOpened(h)
|
||||||
case "synchronized":
|
case "synchronized":
|
||||||
fallthrough
|
|
||||||
case "edited":
|
|
||||||
return processPullRequestSync(h)
|
return processPullRequestSync(h)
|
||||||
|
case "edited":
|
||||||
|
// not need to be handled??
|
||||||
|
return nil
|
||||||
|
case "closed":
|
||||||
|
return processPullRequestClosed(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Unhandled pull request action: %s", req.Action)
|
return fmt.Errorf("Unhandled pull request action: %s", req.Action)
|
||||||
|
Loading…
Reference in New Issue
Block a user