autogits/bots-common/request_pr.go

67 lines
1.2 KiB
Go
Raw Normal View History

2024-07-09 12:06:24 +02:00
package common
2024-07-07 21:08:41 +02:00
import (
"encoding/json"
"io"
"strings"
)
type Head struct {
Ref string
Repo Repository
Sha string
}
type PullRequest struct {
Id int
Url string
Number int
State string
Base Head
Labels []string
2024-07-10 10:14:56 +02:00
Head Head
2024-07-07 21:08:41 +02:00
2024-07-10 10:14:56 +02:00
User User
2024-07-07 21:08:41 +02:00
}
type PullRequestAction struct {
Action string
Number int
2024-07-10 00:03:28 +02:00
Pull_Request PullRequest
2024-07-10 10:14:56 +02:00
Repository Repository
Sender User
2024-07-07 21:08:41 +02:00
}
2024-07-10 10:14:56 +02:00
func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestAction {
2024-07-07 21:08:41 +02:00
if h.HasError() {
return nil
}
var action PullRequestAction
h.Error = json.NewDecoder(data).Decode(&action)
if h.HasError() {
2024-08-24 13:32:39 +02:00
h.ErrLogger.Printf("Got error while parsing: %v\n", h.Error)
2024-07-07 21:08:41 +02:00
return nil
}
repoIdx := strings.LastIndex(action.Repository.Ssh_Url, "/")
if repoIdx == -1 || action.Repository.Ssh_Url[repoIdx+1:] != action.Repository.Name+".git" {
2024-08-24 13:32:39 +02:00
h.ErrLogger.Printf("Unexpected URL for SSH repository: '%s'\n", action.Repository.Name)
h.ErrLogger.Printf("%#v\n", action)
2024-07-07 21:08:41 +02:00
return nil
}
h.PrjGit = action.Repository.Ssh_Url[:repoIdx+1] + DefaultGitPrj + ".git"
2024-07-09 12:06:24 +02:00
h.Data = &action
2024-07-07 21:08:41 +02:00
// sanity checks on request
return &action
}
2024-07-10 17:20:23 +02:00
func (h *RequestHandler) parsePullRequestSync(data io.Reader) *PullRequestAction {
return h.parsePullRequest(data)
}