got: switch to auth_user.. woops

actually save the json as is, not what we parse
This commit is contained in:
Aaron Bieber 2024-04-30 10:12:35 -06:00
parent 1e85d3230c
commit 95fea0358e
No known key found for this signature in database
2 changed files with 12 additions and 23 deletions

30
got.go
View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
@ -43,7 +44,7 @@ type Notification struct {
Type string `json:"type"`
Short bool `json:"short"`
Repo string `json:"repo"`
AuthorUser string `json:"author_user"`
AuthUser string `json:"auth_user"`
ID string `json:"id"`
Author Author `json:"author,omitempty"`
Committer Committer `json:"committer"`
@ -56,7 +57,7 @@ type Notification struct {
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 (%s)",
n.AuthorUser,
n.AuthUser,
n.Repo,
n.ID,
n.ShortMessage,
@ -71,18 +72,6 @@ type GotNotifications struct {
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) {
var gotPort, _ = store.Get("got_listen")
if gotPort != "" {
@ -107,16 +96,21 @@ func gotListen(store *FStore, cli *gomatrix.Client) {
}
gn := GotNotifications{}
dec := json.NewDecoder(r.Body)
err = dec.Decode(&gn)
data, err := io.ReadAll(r.Body)
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 {
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)
return
}
_ = gn.Save()
for _, line := range gn.Notifications {
log.Printf("GOT: sending '%s'\n", line.String())
err = plugins.SendUnescNotice(cli, gotRoom, line.String())

View File

@ -21,11 +21,6 @@ func TestGotNotification(t *testing.T) {
t.Fatal(err)
}
err = nots.Save()
if err != nil {
t.Fatal(err)
}
for _, n := range nots.Notifications {
fmt.Println(n.String())
}