@@ -17,11 +17,24 @@ import (
17
17
type (
18
18
// FeishuPayload represents
19
19
FeishuPayload struct {
20
- Title string `json:"title"`
21
- Text string `json:"text"`
20
+ MsgType string `json:"msg_type"` // text / post / image / share_chat / interactive
21
+ Content struct {
22
+ Text string `json:"text"`
23
+ } `json:"content"`
22
24
}
23
25
)
24
26
27
+ func newFeishuTextPayload (text string ) * FeishuPayload {
28
+ return & FeishuPayload {
29
+ MsgType : "text" ,
30
+ Content : struct {
31
+ Text string `json:"text"`
32
+ }{
33
+ Text : text ,
34
+ },
35
+ }
36
+ }
37
+
25
38
// SetSecret sets the Feishu secret
26
39
func (f * FeishuPayload ) SetSecret (_ string ) {}
27
40
@@ -42,34 +55,25 @@ var (
42
55
func (f * FeishuPayload ) Create (p * api.CreatePayload ) (api.Payloader , error ) {
43
56
// created tag/branch
44
57
refName := git .RefEndName (p .Ref )
45
- title := fmt .Sprintf ("[%s] %s %s created" , p .Repo .FullName , p .RefType , refName )
58
+ text := fmt .Sprintf ("[%s] %s %s created" , p .Repo .FullName , p .RefType , refName )
46
59
47
- return & FeishuPayload {
48
- Text : title ,
49
- Title : title ,
50
- }, nil
60
+ return newFeishuTextPayload (text ), nil
51
61
}
52
62
53
63
// Delete implements PayloadConvertor Delete method
54
64
func (f * FeishuPayload ) Delete (p * api.DeletePayload ) (api.Payloader , error ) {
55
65
// created tag/branch
56
66
refName := git .RefEndName (p .Ref )
57
- title := fmt .Sprintf ("[%s] %s %s deleted" , p .Repo .FullName , p .RefType , refName )
67
+ text := fmt .Sprintf ("[%s] %s %s deleted" , p .Repo .FullName , p .RefType , refName )
58
68
59
- return & FeishuPayload {
60
- Text : title ,
61
- Title : title ,
62
- }, nil
69
+ return newFeishuTextPayload (text ), nil
63
70
}
64
71
65
72
// Fork implements PayloadConvertor Fork method
66
73
func (f * FeishuPayload ) Fork (p * api.ForkPayload ) (api.Payloader , error ) {
67
- title := fmt .Sprintf ("%s is forked to %s" , p .Forkee .FullName , p .Repo .FullName )
74
+ text := fmt .Sprintf ("%s is forked to %s" , p .Forkee .FullName , p .Repo .FullName )
68
75
69
- return & FeishuPayload {
70
- Text : title ,
71
- Title : title ,
72
- }, nil
76
+ return newFeishuTextPayload (text ), nil
73
77
}
74
78
75
79
// Push implements PayloadConvertor Push method
@@ -79,9 +83,7 @@ func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) {
79
83
commitDesc string
80
84
)
81
85
82
- title := fmt .Sprintf ("[%s:%s] %s" , p .Repo .FullName , branchName , commitDesc )
83
-
84
- var text string
86
+ var text = fmt .Sprintf ("[%s:%s] %s\n " , p .Repo .FullName , branchName , commitDesc )
85
87
// for each commit, generate attachment text
86
88
for i , commit := range p .Commits {
87
89
var authorName string
@@ -96,40 +98,28 @@ func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) {
96
98
}
97
99
}
98
100
99
- return & FeishuPayload {
100
- Text : text ,
101
- Title : title ,
102
- }, nil
101
+ return newFeishuTextPayload (text ), nil
103
102
}
104
103
105
104
// Issue implements PayloadConvertor Issue method
106
105
func (f * FeishuPayload ) Issue (p * api.IssuePayload ) (api.Payloader , error ) {
107
106
text , issueTitle , attachmentText , _ := getIssuesPayloadInfo (p , noneLinkFormatter , true )
108
107
109
- return & FeishuPayload {
110
- Text : text + "\r \n \r \n " + attachmentText ,
111
- Title : issueTitle ,
112
- }, nil
108
+ return newFeishuTextPayload (issueTitle + "\r \n " + text + "\r \n \r \n " + attachmentText ), nil
113
109
}
114
110
115
111
// IssueComment implements PayloadConvertor IssueComment method
116
112
func (f * FeishuPayload ) IssueComment (p * api.IssueCommentPayload ) (api.Payloader , error ) {
117
113
text , issueTitle , _ := getIssueCommentPayloadInfo (p , noneLinkFormatter , true )
118
114
119
- return & FeishuPayload {
120
- Text : text + "\r \n \r \n " + p .Comment .Body ,
121
- Title : issueTitle ,
122
- }, nil
115
+ return newFeishuTextPayload (issueTitle + "\r \n " + text + "\r \n \r \n " + p .Comment .Body ), nil
123
116
}
124
117
125
118
// PullRequest implements PayloadConvertor PullRequest method
126
119
func (f * FeishuPayload ) PullRequest (p * api.PullRequestPayload ) (api.Payloader , error ) {
127
120
text , issueTitle , attachmentText , _ := getPullRequestPayloadInfo (p , noneLinkFormatter , true )
128
121
129
- return & FeishuPayload {
130
- Text : text + "\r \n \r \n " + attachmentText ,
131
- Title : issueTitle ,
132
- }, nil
122
+ return newFeishuTextPayload (issueTitle + "\r \n " + text + "\r \n \r \n " + attachmentText ), nil
133
123
}
134
124
135
125
// Review implements PayloadConvertor Review method
@@ -147,28 +137,19 @@ func (f *FeishuPayload) Review(p *api.PullRequestPayload, event models.HookEvent
147
137
148
138
}
149
139
150
- return & FeishuPayload {
151
- Text : title + "\r \n \r \n " + text ,
152
- Title : title ,
153
- }, nil
140
+ return newFeishuTextPayload (title + "\r \n \r \n " + text ), nil
154
141
}
155
142
156
143
// Repository implements PayloadConvertor Repository method
157
144
func (f * FeishuPayload ) Repository (p * api.RepositoryPayload ) (api.Payloader , error ) {
158
- var title string
145
+ var text string
159
146
switch p .Action {
160
147
case api .HookRepoCreated :
161
- title = fmt .Sprintf ("[%s] Repository created" , p .Repository .FullName )
162
- return & FeishuPayload {
163
- Text : title ,
164
- Title : title ,
165
- }, nil
148
+ text = fmt .Sprintf ("[%s] Repository created" , p .Repository .FullName )
149
+ return newFeishuTextPayload (text ), nil
166
150
case api .HookRepoDeleted :
167
- title = fmt .Sprintf ("[%s] Repository deleted" , p .Repository .FullName )
168
- return & FeishuPayload {
169
- Title : title ,
170
- Text : title ,
171
- }, nil
151
+ text = fmt .Sprintf ("[%s] Repository deleted" , p .Repository .FullName )
152
+ return newFeishuTextPayload (text ), nil
172
153
}
173
154
174
155
return nil , nil
@@ -178,10 +159,7 @@ func (f *FeishuPayload) Repository(p *api.RepositoryPayload) (api.Payloader, err
178
159
func (f * FeishuPayload ) Release (p * api.ReleasePayload ) (api.Payloader , error ) {
179
160
text , _ := getReleasePayloadInfo (p , noneLinkFormatter , true )
180
161
181
- return & FeishuPayload {
182
- Text : text ,
183
- Title : text ,
184
- }, nil
162
+ return newFeishuTextPayload (text ), nil
185
163
}
186
164
187
165
// GetFeishuPayload converts a ding talk webhook into a FeishuPayload
0 commit comments