package main import ( "encoding/json" "fmt" "io" "os" "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 Repository User } type PullRequestAction struct { Action string Number int PullRequest Repository Sender User } func (h *RequestHandler) parsePullRequest(data io.ReadCloser) *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) return nil } h.PrjGit = action.Repository.Ssh_Url[:repoIdx+1] + DefaultGitPrj + ".git" h.data = &action // sanity checks on request return &action } func (h *RequestHandler) processCreatePullRequestAction() { action := h.Request.data.(PullRequestAction) action.PullRequest } func (h *RequestHandler) processUpdatePullRequestAction() { // 1. update gitprj // 2. re-request reviews, if needed } func (h *RequestHandler) processPullRequestAction() { if h.HasError() { return } action := h.Request.data.(PullRequestAction) switch action.Action { case "opened": h.processCreatePullRequestAction() default: h.Error = fmt.Errorf("Invalid PR action type: %s", action.Action) h.LogError("%#v", h.Error) return } }