update got notification structure
This commit is contained in:
parent
c240a36b21
commit
1164c8b1a8
54
got.go
54
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 {
|
||||||
Short bool `json:"short"`
|
Type string `json:"type"`
|
||||||
ID string `json:"id"`
|
Short bool `json:"short"`
|
||||||
Author string `json:"author"`
|
Repo string `json:"repo"`
|
||||||
Date string `json:"date"`
|
ID string `json:"id"`
|
||||||
Message string `json:"message"`
|
Author Author `json:"author"`
|
||||||
Diffstat struct {
|
Committer Committer `json:"committer"`
|
||||||
} `json:"diffstat"`
|
Date string `json:"date"`
|
||||||
Changes struct {
|
ShortMessage string `json:"short_message"`
|
||||||
} `json:"changes"`
|
Message string `json:"message"`
|
||||||
|
Diffstat Diffstat `json:"diffstat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
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