got: switch to author_user for user name outupt
while here save our payload for later review
This commit is contained in:
parent
a2543d1984
commit
1e85d3230c
19
got.go
19
got.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
@ -42,6 +43,7 @@ type Notification struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Short bool `json:"short"`
|
Short bool `json:"short"`
|
||||||
Repo string `json:"repo"`
|
Repo string `json:"repo"`
|
||||||
|
AuthorUser string `json:"author_user"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Author Author `json:"author,omitempty"`
|
Author Author `json:"author,omitempty"`
|
||||||
Committer Committer `json:"committer"`
|
Committer Committer `json:"committer"`
|
||||||
@ -54,7 +56,7 @@ type Notification struct {
|
|||||||
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 (%s)",
|
return fmt.Sprintf("%s committed %s %s: %s (%s)",
|
||||||
n.Committer.User,
|
n.AuthorUser,
|
||||||
n.Repo,
|
n.Repo,
|
||||||
n.ID,
|
n.ID,
|
||||||
n.ShortMessage,
|
n.ShortMessage,
|
||||||
@ -69,6 +71,18 @@ type GotNotifications struct {
|
|||||||
Notifications []Notification `json:"notifications"`
|
Notifications []Notification `json:"notifications"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GotNotifications) Save() error {
|
||||||
|
gnJson, err := json.Marshal(g)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.WriteFile("/tmp/mcchunkie-notification.json", gnJson, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func gotListen(store *FStore, cli *gomatrix.Client) {
|
func gotListen(store *FStore, cli *gomatrix.Client) {
|
||||||
var gotPort, _ = store.Get("got_listen")
|
var gotPort, _ = store.Get("got_listen")
|
||||||
if gotPort != "" {
|
if gotPort != "" {
|
||||||
@ -100,6 +114,9 @@ func gotListen(store *FStore, cli *gomatrix.Client) {
|
|||||||
http.Error(w, fmt.Sprintf("invalid data sent to server: %s", err), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("invalid data sent to server: %s", err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = gn.Save()
|
||||||
|
|
||||||
for _, line := range gn.Notifications {
|
for _, line := range gn.Notifications {
|
||||||
log.Printf("GOT: sending '%s'\n", line.String())
|
log.Printf("GOT: sending '%s'\n", line.String())
|
||||||
err = plugins.SendUnescNotice(cli, gotRoom, line.String())
|
err = plugins.SendUnescNotice(cli, gotRoom, line.String())
|
||||||
|
@ -21,6 +21,11 @@ func TestGotNotification(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = nots.Save()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, n := range nots.Notifications {
|
for _, n := range nots.Notifications {
|
||||||
fmt.Println(n.String())
|
fmt.Println(n.String())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user