Skip to content

Commit

Permalink
feat(json): implement json action for the REPL (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
nobe4 authored Oct 3, 2024
1 parent 090e4b5 commit 4958a98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/nobe4/gh-not/internal/actions/debug"
"github.com/nobe4/gh-not/internal/actions/done"
"github.com/nobe4/gh-not/internal/actions/hide"
"github.com/nobe4/gh-not/internal/actions/json"
"github.com/nobe4/gh-not/internal/actions/open"
"github.com/nobe4/gh-not/internal/actions/pass"
"github.com/nobe4/gh-not/internal/actions/print"
Expand All @@ -27,6 +28,7 @@ func Map(client *gh.Client) ActionsMap {
"done": &done.Runner{Client: client},
"open": &open.Runner{Client: client},
"assign": &assign.Runner{Client: client},
"json": &json.Runner{},
}
}

Expand Down
29 changes: 29 additions & 0 deletions internal/actions/json/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Package json implements an [actions.Runner] that prints a notification in JSON.
*/
package json

import (
"encoding/json"
"fmt"
"io"

"github.com/nobe4/gh-not/internal/notifications"
)

type Runner struct{}

func (_ *Runner) Run(n *notifications.Notification, _ []string, w io.Writer) error {
if n.Meta.Hidden {
return nil
}

marshalled, err := json.MarshalIndent(n, "", " ")
if err != nil {
return err
}

fmt.Fprint(w, string(marshalled))

return nil
}

0 comments on commit 4958a98

Please sign in to comment.