@@ -28,6 +28,69 @@ func htmlLinkFormatter(url, text string) string {
28
28
return fmt .Sprintf (`<a href="%s">%s</a>` , html .EscapeString (url ), html .EscapeString (text ))
29
29
}
30
30
31
+ // getPullRequestInfo gets the information for a pull request
32
+ func getPullRequestInfo (p * api.PullRequestPayload ) (title , link , by , operator , operateResult , assignees string ) {
33
+ title = fmt .Sprintf ("[PullRequest-%s #%d]: %s\n %s" , p .Repository .FullName , p .PullRequest .Index , p .Action , p .PullRequest .Title )
34
+ assignList := p .PullRequest .Assignees
35
+ assignStringList := make ([]string , len (assignList ))
36
+
37
+ for i , user := range assignList {
38
+ assignStringList [i ] = user .UserName
39
+ }
40
+ if p .Action == api .HookIssueAssigned {
41
+ operateResult = fmt .Sprintf ("%s assign this to %s" , p .Sender .UserName , assignList [len (assignList )- 1 ].UserName )
42
+ } else if p .Action == api .HookIssueUnassigned {
43
+ operateResult = fmt .Sprintf ("%s unassigned this for someone" , p .Sender .UserName )
44
+ } else if p .Action == api .HookIssueMilestoned {
45
+ operateResult = fmt .Sprintf ("%s/milestone/%d" , p .Repository .HTMLURL , p .PullRequest .Milestone .ID )
46
+ }
47
+ link = p .PullRequest .HTMLURL
48
+ by = fmt .Sprintf ("PullRequest by %s" , p .PullRequest .Poster .UserName )
49
+ if len (assignStringList ) > 0 {
50
+ assignees = fmt .Sprintf ("Assignees: %s" , strings .Join (assignStringList , ", " ))
51
+ }
52
+ operator = fmt .Sprintf ("Operator: %s" , p .Sender .UserName )
53
+ return title , link , by , operator , operateResult , assignees
54
+ }
55
+
56
+ // getIssuesInfo gets the information for an issue
57
+ func getIssuesInfo (p * api.IssuePayload ) (issueTitle , link , by , operator , operateResult , assignees string ) {
58
+ issueTitle = fmt .Sprintf ("[Issue-%s #%d]: %s\n %s" , p .Repository .FullName , p .Issue .Index , p .Action , p .Issue .Title )
59
+ assignList := p .Issue .Assignees
60
+ assignStringList := make ([]string , len (assignList ))
61
+
62
+ for i , user := range assignList {
63
+ assignStringList [i ] = user .UserName
64
+ }
65
+ if p .Action == api .HookIssueAssigned {
66
+ operateResult = fmt .Sprintf ("%s assign this to %s" , p .Sender .UserName , assignList [len (assignList )- 1 ].UserName )
67
+ } else if p .Action == api .HookIssueUnassigned {
68
+ operateResult = fmt .Sprintf ("%s unassigned this for someone" , p .Sender .UserName )
69
+ } else if p .Action == api .HookIssueMilestoned {
70
+ operateResult = fmt .Sprintf ("%s/milestone/%d" , p .Repository .HTMLURL , p .Issue .Milestone .ID )
71
+ }
72
+ link = p .Issue .HTMLURL
73
+ by = fmt .Sprintf ("Issue by %s" , p .Issue .Poster .UserName )
74
+ if len (assignStringList ) > 0 {
75
+ assignees = fmt .Sprintf ("Assignees: %s" , strings .Join (assignStringList , ", " ))
76
+ }
77
+ operator = fmt .Sprintf ("Operator: %s" , p .Sender .UserName )
78
+ return issueTitle , link , by , operator , operateResult , assignees
79
+ }
80
+
81
+ // getIssuesCommentInfo gets the information for a comment
82
+ func getIssuesCommentInfo (p * api.IssueCommentPayload ) (title , link , by , operator string ) {
83
+ title = fmt .Sprintf ("[Comment-%s #%d]: %s\n %s" , p .Repository .FullName , p .Issue .Index , p .Action , p .Issue .Title )
84
+ link = p .Issue .HTMLURL
85
+ if p .IsPull {
86
+ by = fmt .Sprintf ("PullRequest by %s" , p .Issue .Poster .UserName )
87
+ } else {
88
+ by = fmt .Sprintf ("Issue by %s" , p .Issue .Poster .UserName )
89
+ }
90
+ operator = fmt .Sprintf ("Operator: %s" , p .Sender .UserName )
91
+ return title , link , by , operator
92
+ }
93
+
31
94
func getIssuesPayloadInfo (p * api.IssuePayload , linkFormatter linkFormatter , withSender bool ) (string , string , string , int ) {
32
95
repoLink := linkFormatter (p .Repository .HTMLURL , p .Repository .FullName )
33
96
issueTitle := fmt .Sprintf ("#%d %s" , p .Index , p .Issue .Title )
0 commit comments