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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
//go:build unit
package main
import (
"testing"
)
func TestExtractPR(t *testing.T) {
testCases := []struct {
name string
mail string
want string
}{
{
name: "pr created",
want: "https://github.com/grid-x/dploy/pull/9",
mail: `This will allow the change log to directly link the PR making a bit easier to check the summary of those PR.
Ex.:

You can view, comment on, or merge this pull request online at:
https://github.com/grid-x/dploy/pull/9
-- Commit Summary --
* feat(main): allow link pr instead of message
-- File Changes --
M main.go (61)
-- Patch Links --
https://github.com/grid-x/dploy/pull/9.patch
https://github.com/grid-x/dploy/pull/9.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/grid-x/dploy/pull/9
You are receiving this because you are subscribed to this thread.
Message ID: <grid-x/dploy/pull/9@github.com>`,
},
{
name: "request review",
want: "https://github.com/grid-x/edge-connector/pull/319",
mail: `@juliusmh requested review from @grid-x/edge-connector-team on: grid-x/edge-connector#319 fix(api/manage): write system controls to response after set as a code owner.
--
Reply to this email directly or view it on GitHub:
https://github.com/grid-x/edge-connector/pull/319#event-9104760420
You are receiving this because your review was requested.
Message ID: <grid-x/edge-connector/pull/319/issue_event/9104760420@github.com>`,
},
{
name: "pr merged",
want: "https://github.com/grid-x/edge-connector/pull/319",
mail: `Merged #319 into main.
--
Reply to this email directly or view it on GitHub:
https://github.com/grid-x/edge-connector/pull/319#event-9112252051
You are receiving this because your review was requested.
Message ID: <grid-x/edge-connector/pull/319/issue_event/9112252051@github.com>`,
},
{
name: "pr pushed",
want: "https://github.com/grid-x/edge-connector/pull/313",
mail: `@juliusmh pushed 1 commit.
a0557c770be6d9c2b6070c4fd6a69c68c5e3996f feat(feature/service): accept feature names in kebab-case
--
View it on GitHub:
https://github.com/grid-x/edge-connector/pull/313/files/dfdd5081691056150ace71dfb5d11265593c561e..a0557c770be6d9c2b6070c4fd6a69c68c5e3996f
You are receiving this because you are subscribed to this thread.
Message ID: <grid-x/edge-connector/pull/313/push/13418764381@github.com>`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
prLink := extractPRLink(tc.mail)
if prLink != tc.want {
t.Error("Invalid link returned: " + prLink)
}
})
}
}
func TestExec(t *testing.T) {
testCases := []struct {
name string
app string
args []string
want string
}{
{
name: "echo",
app: "echo",
args: []string{"this", "is", "a", "phrase"},
want: "this is a phrase\n",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
out, err := execCommand(tc.app, tc.args...)
if err != nil {
t.Fatal("Failed " + err.Error())
}
if out != tc.want {
t.Error("Invalid stdout returned: " + out)
}
})
}
}
|