.
This commit is contained in:
@@ -46,33 +46,24 @@ func (r *RepositoryWebhookEvent) GetAction() string {
|
||||
}
|
||||
|
||||
// TODO: sanity check values!!!!
|
||||
func (h *RequestHandler) parseRepositoryRequest(dataReader io.Reader) *RepositoryWebhookEvent {
|
||||
if h.HasError() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var data RepositoryWebhookEvent
|
||||
h.Error = json.NewDecoder(dataReader).Decode(&data)
|
||||
|
||||
if h.HasError() {
|
||||
return nil
|
||||
func (h *RequestHandler) parseRepositoryRequest(dataReader io.Reader) (data *RepositoryWebhookEvent, err error) {
|
||||
data = new(RepositoryWebhookEvent)
|
||||
if err = json.NewDecoder(dataReader).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoIdx := strings.LastIndex(data.Repository.Ssh_Url, "/")
|
||||
if repoIdx == -1 || data.Repository.Ssh_Url[repoIdx+1:] != data.Repository.Name+".git" {
|
||||
h.Error = fmt.Errorf("No data, skipping")
|
||||
h.ErrLogger.Printf("Unexpected URL for SSH repository: %s\n", data.Repository.Name)
|
||||
return nil
|
||||
return nil, fmt.Errorf("Unexpected URL for SSH repository: %w", data.Repository.Name)
|
||||
}
|
||||
|
||||
data.PrjGit = data.Repository.Ssh_Url[:repoIdx+1] + DefaultGitPrj + ".git"
|
||||
|
||||
h.StdLogger.Printf("Request '%s' for repo: %s\n", data.Action, data.Repository.Full_Name)
|
||||
if len(data.Action) < 1 {
|
||||
h.Error = fmt.Errorf("No data, skipping")
|
||||
h.ErrLogger.Println("Request has no data.... skipping")
|
||||
return nil, fmt.Errorf("Request has no data.... skipping")
|
||||
}
|
||||
|
||||
h.Request.Data = &data
|
||||
return &data
|
||||
h.Request.Data = data
|
||||
return data, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user