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"
|
||||
)
|
||||
|
||||
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 {
|
||||
Short bool `json:"short"`
|
||||
ID string `json:"id"`
|
||||
Author string `json:"author"`
|
||||
Date string `json:"date"`
|
||||
Message string `json:"message"`
|
||||
Diffstat struct {
|
||||
} `json:"diffstat"`
|
||||
Changes struct {
|
||||
} `json:"changes"`
|
||||
Type string `json:"type"`
|
||||
Short bool `json:"short"`
|
||||
Repo string `json:"repo"`
|
||||
ID string `json:"id"`
|
||||
Author Author `json:"author"`
|
||||
Committer Committer `json:"committer"`
|
||||
Date string `json:"date"`
|
||||
ShortMessage string `json:"short_message"`
|
||||
Message string `json:"message"`
|
||||
Diffstat Diffstat `json:"diffstat"`
|
||||
}
|
||||
|
||||
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)
|
||||
return fmt.Sprintf("%s committed %s: %s (%s)",
|
||||
n.Author,
|
||||
return fmt.Sprintf("%s committed %s %s: %s (%s)",
|
||||
n.Author.User,
|
||||
n.Repo,
|
||||
n.ID,
|
||||
n.Message,
|
||||
n.ShortMessage,
|
||||
fmt.Sprintf("https://git.gameoftrees.org/gitweb/?p=%s;a=commitdiff;h=%s",
|
||||
"repo",
|
||||
n.Repo,
|
||||
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