autogits/bots-common/request_repo.go

75 lines
1.4 KiB
Go
Raw Normal View History

2024-07-07 21:08:41 +02:00
package common
import (
"encoding/json"
"fmt"
"io"
"strings"
)
type Repository struct {
Id uint
Name string
Full_Name string
Fork bool
Parent *Repository
2024-07-09 23:22:42 +02:00
Owner *Organization
2024-07-07 21:08:41 +02:00
Clone_Url string
Ssh_Url string
Default_Branch string
Object_Format_Name string
}
type Organization struct {
Id uint
Username string
}
type User struct {
Id uint
Username string
}
type RepositoryAction struct {
Action string
2024-08-24 21:39:50 +02:00
Sender *User
Organization *Organization
Repository *Repository
2024-07-07 21:08:41 +02:00
PrjGit string
}
// TODO: sanity check values!!!!
2024-07-09 12:06:24 +02:00
func (h *RequestHandler) parseRepositoryRequest(dataReader io.Reader) *RepositoryAction {
2024-07-07 21:08:41 +02:00
if h.HasError() {
return nil
}
var data RepositoryAction
h.Error = json.NewDecoder(dataReader).Decode(&data)
if h.HasError() {
return nil
}
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")
2024-08-24 13:32:39 +02:00
h.ErrLogger.Printf("Unexpected URL for SSH repository: %s\n", data.Repository.Name)
2024-07-07 21:08:41 +02:00
return nil
}
data.PrjGit = data.Repository.Ssh_Url[:repoIdx+1] + DefaultGitPrj + ".git"
2024-08-24 13:32:39 +02:00
h.StdLogger.Printf("Request '%s' for repo: %s\n", data.Action, data.Repository.Full_Name)
2024-07-07 21:08:41 +02:00
if len(data.Action) < 1 {
h.Error = fmt.Errorf("No data, skipping")
2024-08-24 13:32:39 +02:00
h.ErrLogger.Println("Request has no data.... skipping")
2024-07-07 21:08:41 +02:00
}
h.Data = data
return &data
}