got: switch to auth_user.. woops
actually save the json as is, not what we parse
This commit is contained in:
parent
1e85d3230c
commit
95fea0358e
30
got.go
30
got.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -43,7 +44,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"`
|
AuthUser string `json:"auth_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"`
|
||||||
@ -56,7 +57,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.AuthorUser,
|
n.AuthUser,
|
||||||
n.Repo,
|
n.Repo,
|
||||||
n.ID,
|
n.ID,
|
||||||
n.ShortMessage,
|
n.ShortMessage,
|
||||||
@ -71,18 +72,6 @@ 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 != "" {
|
||||||
@ -107,16 +96,21 @@ func gotListen(store *FStore, cli *gomatrix.Client) {
|
|||||||
}
|
}
|
||||||
gn := GotNotifications{}
|
gn := GotNotifications{}
|
||||||
|
|
||||||
dec := json.NewDecoder(r.Body)
|
data, err := io.ReadAll(r.Body)
|
||||||
err = dec.Decode(&gn)
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("internal error: %s", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = os.WriteFile("/tmp/mcchunkie-notification.json", data, 0600)
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &gn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("GOT: invalid data sent to server: '%s'\n", err)
|
log.Printf("GOT: invalid data sent to server: '%s'\n", err)
|
||||||
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,11 +21,6 @@ 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