Skip to content

Commit 21b7d30

Browse files
authored
Merge pull request #245 from Bwko/lint/update&slack
Lint models/update.go, release.go & webhook_slack.go
2 parents e9c6053 + 33a2ac3 commit 21b7d30

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

models/update.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/modules/log"
1616
)
1717

18+
// UpdateTask defines an UpdateTask
1819
type UpdateTask struct {
1920
ID int64 `xorm:"pk autoincr"`
2021
UUID string `xorm:"index"`
@@ -23,6 +24,7 @@ type UpdateTask struct {
2324
NewCommitID string
2425
}
2526

27+
// AddUpdateTask adds an UpdateTask
2628
func AddUpdateTask(task *UpdateTask) error {
2729
_, err := x.Insert(task)
2830
return err
@@ -42,6 +44,7 @@ func GetUpdateTaskByUUID(uuid string) (*UpdateTask, error) {
4244
return task, nil
4345
}
4446

47+
// DeleteUpdateTaskByUUID deletes an UpdateTask from the database
4548
func DeleteUpdateTaskByUUID(uuid string) error {
4649
_, err := x.Delete(&UpdateTask{UUID: uuid})
4750
return err
@@ -60,6 +63,7 @@ func CommitToPushCommit(commit *git.Commit) *PushCommit {
6063
}
6164
}
6265

66+
// ListToPushCommits transforms a list.List to PushCommits type.
6367
func ListToPushCommits(l *list.List) *PushCommits {
6468
commits := make([]*PushCommit, 0)
6569
var actEmail string
@@ -73,6 +77,7 @@ func ListToPushCommits(l *list.List) *PushCommits {
7377
return &PushCommits{l.Len(), commits, "", nil}
7478
}
7579

80+
// PushUpdateOptions defines the push update options
7681
type PushUpdateOptions struct {
7782
PusherID int64
7883
PusherName string

models/webhook_slack.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import (
1616
"code.gitea.io/gitea/modules/setting"
1717
)
1818

19+
// SlackMeta contains the slack metdata
1920
type SlackMeta struct {
2021
Channel string `json:"channel"`
2122
Username string `json:"username"`
2223
IconURL string `json:"icon_url"`
2324
Color string `json:"color"`
2425
}
2526

27+
// SlackPayload contains the information about the slack channel
2628
type SlackPayload struct {
2729
Channel string `json:"channel"`
2830
Text string `json:"text"`
@@ -33,15 +35,18 @@ type SlackPayload struct {
3335
Attachments []SlackAttachment `json:"attachments"`
3436
}
3537

38+
// SlackAttachment contains the slack message
3639
type SlackAttachment struct {
3740
Fallback string `json:"fallback"`
3841
Color string `json:"color"`
3942
Title string `json:"title"`
4043
Text string `json:"text"`
4144
}
4245

46+
// SetSecret sets the slack secret
4347
func (p *SlackPayload) SetSecret(_ string) {}
4448

49+
// JSONPayload Marshals the SlackPayload to json
4550
func (p *SlackPayload) JSONPayload() ([]byte, error) {
4651
data, err := json.MarshalIndent(p, "", " ")
4752
if err != nil {
@@ -50,6 +55,7 @@ func (p *SlackPayload) JSONPayload() ([]byte, error) {
5055
return data, nil
5156
}
5257

58+
// SlackTextFormatter replaces &, <, > with HTML characters
5359
// see: https://api.slack.com/docs/formatting
5460
func SlackTextFormatter(s string) string {
5561
// replace & < >
@@ -59,6 +65,7 @@ func SlackTextFormatter(s string) string {
5965
return s
6066
}
6167

68+
// SlackShortTextFormatter replaces &, <, > with HTML characters
6269
func SlackShortTextFormatter(s string) string {
6370
s = strings.Split(s, "\n")[0]
6471
// replace & < >
@@ -68,6 +75,7 @@ func SlackShortTextFormatter(s string) string {
6875
return s
6976
}
7077

78+
// SlackLinkFormatter creates a link compatablie with slack
7179
func SlackLinkFormatter(url string, text string) string {
7280
return fmt.Sprintf("<%s|%s>", url, SlackTextFormatter(text))
7381
}
@@ -181,6 +189,7 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S
181189
}, nil
182190
}
183191

192+
// GetSlackPayload converts a slack webhook into a SlackPayload
184193
func GetSlackPayload(p api.Payloader, event HookEventType, meta string) (*SlackPayload, error) {
185194
s := new(SlackPayload)
186195

0 commit comments

Comments
 (0)