package common /* * This file is part of Autogits. * * Copyright © 2024 SUSE LLC * * Autogits is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 2 of the License, or (at your option) any later * version. * * Autogits is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * Foobar. If not, see . */ import ( "encoding/json" "fmt" "io" ) type Head struct { Ref string Repo *Repository Sha string } type IssueLabelDetail struct { Id int Name string Exclusive bool Is_archived bool Color string Description string Url string } type PullRequest struct { Id int Url string Number int State string Base Head Head Head Labels []IssueLabelDetail Requested_reviewers []*User User User } type PullRequestWebhookEvent struct { Action string Number int Pull_Request *PullRequest Repository *Repository Requested_reviewer *User Sender User } func (p *PullRequestWebhookEvent) GetAction() string { return p.Action } func (h *RequestHandler) parsePullRequest(data io.Reader) (action *PullRequestWebhookEvent, err error) { action = new(PullRequestWebhookEvent) err = json.NewDecoder(data).Decode(&action) if err != nil { return nil, fmt.Errorf("Got error while parsing json: %w", err) } h.Request = &Request{ Data: action, Type: RequestType_PR, } return } func (h *RequestHandler) parsePullRequestSync(data io.Reader) (*PullRequestWebhookEvent, error) { return h.parsePullRequest(data) }