Commit 061bd0662c
Verified · cmc
Layout: unified · split
internal/control/feedline.go +7 −2
| @@ -28,9 +28,14 @@ type FeedLine struct { | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // Sentence renders the line the way the CLI shows it: "<actor> <verb> |
| 31 | // <repo><ref>", with Extra (a label list) appended when set. | |
| 31 | // <repo><ref>" for an issue or MR ("krz/gitbay#1"), "<repo> <ref>" for a | |
| 32 | // tag, job or sha, with Extra (a label list) appended when set. | |
| 32 | 33 | func (l FeedLine) Sentence() string { |
| 33 | s := fmt.Sprintf("%s %s %s%s", l.Actor, l.Verb, l.Repo, l.Ref) | |
| 34 | ref := l.Ref | |
| 35 | if ref != "" && ref[0] != '#' && ref[0] != '!' { | |
| 36 | ref = " " + ref | |
| 37 | } | |
| 38 | s := fmt.Sprintf("%s %s %s%s", l.Actor, l.Verb, l.Repo, ref) | |
| 34 | 39 | if l.Extra != "" { |
| 35 | 40 | s += " " + l.Extra |
| 36 | 41 | } |
internal/control/feedline_test.go +15
| @@ -242,4 +242,19 @@ func TestFeedLineSentence(t *testing.T) { | ||
| 242 | 242 | if got, want := l.Sentence(), "cmc opened issue krz/gitbay#1 ops, security"; got != want { |
| 243 | 243 | t.Errorf("Sentence() with Extra = %q, want %q", got, want) |
| 244 | 244 | } |
| 245 | ||
| 246 | for _, c := range []struct { | |
| 247 | l FeedLine | |
| 248 | want string | |
| 249 | }{ | |
| 250 | {FeedLine{Actor: "cmc", Verb: "released", Repo: "krz/gitbay", Ref: "v1.30.0"}, "cmc released krz/gitbay v1.30.0"}, | |
| 251 | {FeedLine{Actor: "cmc", Verb: "build success", Repo: "krz/gitbay", Ref: "test"}, "cmc build success krz/gitbay test"}, | |
| 252 | {FeedLine{Actor: "cmc", Verb: "ran 2 jobs on", Repo: "krz/gitbay", Ref: "0123456789"}, "cmc ran 2 jobs on krz/gitbay 0123456789"}, | |
| 253 | {FeedLine{Actor: "cmc", Verb: "merged", Repo: "krz/gitbay", Ref: "!3"}, "cmc merged krz/gitbay!3"}, | |
| 254 | {FeedLine{Actor: "cmc", Verb: "repository created", Repo: "krz/gitbay"}, "cmc repository created krz/gitbay"}, | |
| 255 | } { | |
| 256 | if got := c.l.Sentence(); got != c.want { | |
| 257 | t.Errorf("Sentence() = %q, want %q", got, c.want) | |
| 258 | } | |
| 259 | } | |
| 245 | 260 | } |