update got notification structure
This commit is contained in:
parent
c240a36b21
commit
1164c8b1a8
46
got.go
46
got.go
@ -12,26 +12,54 @@ import (
|
|||||||
"suah.dev/mcchunkie/plugins"
|
"suah.dev/mcchunkie/plugins"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Author struct {
|
||||||
|
Full string `json:"full"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Mail string `json:"mail"`
|
||||||
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
type Committer struct {
|
||||||
|
Full string `json:"full"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Mail string `json:"mail"`
|
||||||
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
type Files struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
File string `json:"file"`
|
||||||
|
Added int `json:"added"`
|
||||||
|
Removed int `json:"removed"`
|
||||||
|
}
|
||||||
|
type Total struct {
|
||||||
|
Added int `json:"added"`
|
||||||
|
Removed int `json:"removed"`
|
||||||
|
}
|
||||||
|
type Diffstat struct {
|
||||||
|
Files []Files `json:"files"`
|
||||||
|
Total Total `json:"total"`
|
||||||
|
}
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
|
Type string `json:"type"`
|
||||||
Short bool `json:"short"`
|
Short bool `json:"short"`
|
||||||
|
Repo string `json:"repo"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Author string `json:"author"`
|
Author Author `json:"author"`
|
||||||
|
Committer Committer `json:"committer"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
|
ShortMessage string `json:"short_message"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Diffstat struct {
|
Diffstat Diffstat `json:"diffstat"`
|
||||||
} `json:"diffstat"`
|
|
||||||
Changes struct {
|
|
||||||
} `json:"changes"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notification) String() string {
|
func (n *Notification) String() string {
|
||||||
// op committed got.git f9e653700..f9e653700^1 (main): fix gotd_parse_url() (https://git.gameoftrees.org/gitweb/?p=got.git;a=commitdiff;h=f9e653700)
|
// op committed got.git f9e653700..f9e653700^1 (main): fix gotd_parse_url() (https://git.gameoftrees.org/gitweb/?p=got.git;a=commitdiff;h=f9e653700)
|
||||||
return fmt.Sprintf("%s committed %s: %s (%s)",
|
return fmt.Sprintf("%s committed %s %s: %s (%s)",
|
||||||
n.Author,
|
n.Author.User,
|
||||||
|
n.Repo,
|
||||||
n.ID,
|
n.ID,
|
||||||
n.Message,
|
n.ShortMessage,
|
||||||
fmt.Sprintf("https://git.gameoftrees.org/gitweb/?p=%s;a=commitdiff;h=%s",
|
fmt.Sprintf("https://git.gameoftrees.org/gitweb/?p=%s;a=commitdiff;h=%s",
|
||||||
"repo",
|
n.Repo,
|
||||||
n.ID),
|
n.ID),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
24
got_test.go
Normal file
24
got_test.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGotNotification(t *testing.T) {
|
||||||
|
jsonStr := `{"notifications":[{"type":"commit", "short":false, "repo":"test-repo", "id":"34d7c970d4bd3a5832ecded86f2c28e83dbba2ba", "author":{ "full":"Flan Hacker <flan@openbsd.org>", "name":"Flan Hacker", "mail":"flan@openbsd.org", "user":"flan" }, "committer":{ "full":"Flan Hacker <flan@openbsd.org>", "name":"Flan Hacker", "mail":"flan@openbsd.org", "user":"flan" }, "date":"Thu Apr 18 16:47:40 2024 UTC", "short_message":"make changes", "message":"make changes\n", "diffstat":{ "files":[{ "action":"modified", "file":"alpha", "added":1, "removed":1 }], "total":{ "added":1, "removed":1 } }}]}`
|
||||||
|
|
||||||
|
nots := &GotNotifications{}
|
||||||
|
dec := json.NewDecoder(strings.NewReader(jsonStr))
|
||||||
|
err := dec.Decode(nots)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, n := range nots.Notifications {
|
||||||
|
fmt.Println(n.String())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user