-
Notifications
You must be signed in to change notification settings - Fork 5
/
fortune.go
40 lines (32 loc) · 911 Bytes
/
fortune.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package dreck
import (
"context"
"fmt"
"os/exec"
"regexp"
"github.com/google/go-github/v28/github"
)
var r = regexp.MustCompile("^")
// Fortune points to the fortune executable. This is the path on Debian.
var Fortune = "/usr/games/fortune"
func runFortune() (string, error) {
cmd := exec.Command(Fortune)
buf, err := cmd.Output()
if err != nil {
return "", err
}
if len(buf) == 0 {
return "", fmt.Errorf("no output returned")
}
buf = r.ReplaceAll(buf, []byte("> "))
return "Cookie:\n\n" + string(buf), nil
}
func (d Dreck) fortune(ctx context.Context, client *github.Client, req IssueCommentOuter, _ *Action) (*github.Response, error) {
body, err := runFortune()
if err != nil {
return nil, err
}
comment := githubIssueComment(body)
_, resp, err := client.Issues.CreateComment(ctx, req.Repository.Owner.Login, req.Repository.Name, req.Issue.Number, comment)
return resp, err
}