89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
//"github.com/hashicorp/nomad/api"
|
|
//"code.gitea.io/sdk/gitea"
|
|
)
|
|
|
|
type GitUser struct {
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
Username string `json:username"`
|
|
}
|
|
|
|
type GiteaCommit struct {
|
|
Id string `json:"id"`
|
|
Message string `json:"message"`
|
|
Url string `json:"string"`
|
|
Author GitUser `json:"author"`
|
|
Committer GitUser `json:"committer"`
|
|
Timestamp string `json:"timestamp"`
|
|
}
|
|
|
|
type GiteaAccount struct {
|
|
Id int64 `json:"id"`
|
|
Login string `json:"login"`
|
|
FullName string `json:"full_name"`
|
|
Email string `json:"email"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
type GiteaRepository struct {
|
|
Id int64 `json:"id"`
|
|
Owner GiteaAccount `json:"owner"`
|
|
Description string `json:"description"`
|
|
Private bool `json:"private"`
|
|
Fork bool `json:"private"`
|
|
HtmlUrl string `json:"html_url"`
|
|
SshUrl string `json:"ssh_url"`
|
|
CloneUrl string `json:"clone_url"`
|
|
Website string `json:"website"`
|
|
StarsCount int64 `json:"stars_count"`
|
|
ForksCount int64 `json:"forks_count"`
|
|
WatchersCount int64 `json:"watchers_count"`
|
|
OpenIssuesCount int64 `json:"open_issues_count"`
|
|
DefaultBranch string `json:"default_branch"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
type GiteaNotification struct {
|
|
Secret string `json:"secret"`
|
|
Ref string `json:"ref"`
|
|
Before string `json:"before"`
|
|
After string `json:"after"`
|
|
CompareUrl string `json:"compare_url"`
|
|
Commits []GiteaCommit `json:"commits"`
|
|
Repository GiteaRepository `json:"repository"`
|
|
Pusher GiteaAccount `json:"pusher"`
|
|
Sender GiteaAccount `json:"sender"`
|
|
}
|
|
|
|
func hook(w http.ResponseWriter, r *http.Request) {
|
|
var notification GiteaNotification
|
|
dec := json.NewDecoder(r.Body)
|
|
if err := dec.Decode(¬ification); err != nil {
|
|
log.Fatal("Unable to unmarshal gitea notification")
|
|
return
|
|
}
|
|
fmt.Println(notification.CompareUrl)
|
|
}
|
|
|
|
func build(w http.ResponseWriter, r *http.Request) {
|
|
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println("albatros")
|
|
|
|
http.HandleFunc("/hook", hook)
|
|
http.HandleFunc("/build", build)
|
|
if err := http.ListenAndServe(":8080", nil); err != nil {
|
|
log.Fatal("Can't start HTTP server")
|
|
}
|
|
}
|