69 lines
1.2 KiB
Go
69 lines
1.2 KiB
Go
package common
|
|
|
|
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
|
|
Head Head
|
|
|
|
Repo Repository
|
|
User User
|
|
}
|
|
|
|
type PullRequestAction struct {
|
|
Action string
|
|
Number int
|
|
|
|
Pull_Request PullRequest
|
|
Repository Repository
|
|
Sender User
|
|
}
|
|
|
|
func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestAction {
|
|
if h.HasError() {
|
|
return nil
|
|
}
|
|
|
|
var action PullRequestAction
|
|
h.Error = json.NewDecoder(data).Decode(&action)
|
|
|
|
if h.HasError() {
|
|
h.LogError("Got error while parsing: %v", h.Error)
|
|
return nil
|
|
}
|
|
|
|
repoIdx := strings.LastIndex(action.Repository.Ssh_Url, "/")
|
|
if repoIdx == -1 || action.Repository.Ssh_Url[repoIdx+1:] != action.Repository.Name+".git" {
|
|
h.LogError("Unexpected URL for SSH repository: '%s'", action.Repository.Name)
|
|
h.LogError("%#v", action)
|
|
return nil
|
|
}
|
|
h.PrjGit = action.Repository.Ssh_Url[:repoIdx+1] + DefaultGitPrj + ".git"
|
|
h.Data = &action
|
|
|
|
// sanity checks on request
|
|
|
|
return &action
|
|
}
|
|
|
|
func (h *RequestHandler) parsePullRequestSync(data io.Reader) *PullRequestAction {
|
|
return h.parsePullRequest(data)
|
|
}
|
|
|