This commit is contained in:
2024-07-11 16:45:49 +02:00
parent 429cc2fe02
commit f40888ea45
3 changed files with 55 additions and 14 deletions

View File

@@ -6,7 +6,6 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"strings"
transport "github.com/go-openapi/runtime/client"
@@ -16,6 +15,8 @@ import (
"src.opensuse.org/autogits/common/gitea-generated/models"
)
const PrPattern = "PR: %s/%s#%d"
func (h *RequestHandler) allocateGiteaTransport() (*transport.Runtime, *apiclient.GiteaAPI) {
r := transport.New("src.opensuse.org", apiclient.DefaultBasePath, [](string){"https"})
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())
}
payload_processing:
prLine := fmt.Sprintf(PrPattern, pr.Repository.Owner.Username, pr.Repository.Name, pr.Number)
// payload_processing:
for _, pr := range prs.Payload {
lines := strings.Split(pr.Body, "\n")
for _, line := range lines {
r := regexp.MustCompile(`^PullRequest: ([^/]+)/([^/]+)#(\d+)$`)
if m := r.FindSubmatch([]byte(line)); m != nil {
h.Log("match: %#v", m)
break payload_processing
} else {
h.Log("not matched: '%s'", line)
if strings.TrimSpace(line) == prLine {
return pr
}
}
}