-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhook): 添加Gitea支持,优化提示模板 (#40)
* feat(webhook): 支持Gitea,更新通知模板.
- Loading branch information
Showing
11 changed files
with
338 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package gitea | ||
|
||
import "time" | ||
|
||
type GiteaPushEvent struct { | ||
Ref string `json:"ref"` | ||
Before string `json:"before"` | ||
After string `json:"after"` | ||
CompareUrl string `json:"compare_url"` | ||
Commits []struct { | ||
Id string `json:"id"` | ||
Message string `json:"message"` | ||
Url string `json:"url"` | ||
Author struct { | ||
Name string `json:"name"` | ||
Email string `json:"email"` | ||
Username string `json:"username"` | ||
} `json:"author"` | ||
Committer struct { | ||
Name string `json:"name"` | ||
Email string `json:"email"` | ||
Username string `json:"username"` | ||
} `json:"committer"` | ||
Verification interface{} `json:"verification"` | ||
Timestamp time.Time `json:"timestamp"` | ||
Added []interface{} `json:"added"` | ||
Removed []interface{} `json:"removed"` | ||
Modified []string `json:"modified"` | ||
} `json:"commits"` | ||
TotalCommits int `json:"total_commits"` | ||
HeadCommit struct { | ||
Id string `json:"id"` | ||
Message string `json:"message"` | ||
Url string `json:"url"` | ||
Author struct { | ||
Name string `json:"name"` | ||
Email string `json:"email"` | ||
Username string `json:"username"` | ||
} `json:"author"` | ||
Committer struct { | ||
Name string `json:"name"` | ||
Email string `json:"email"` | ||
Username string `json:"username"` | ||
} `json:"committer"` | ||
Verification interface{} `json:"verification"` | ||
Timestamp time.Time `json:"timestamp"` | ||
Added []interface{} `json:"added"` | ||
Removed []interface{} `json:"removed"` | ||
Modified []string `json:"modified"` | ||
} `json:"head_commit"` | ||
Repository struct { | ||
Id int `json:"id"` | ||
Owner struct { | ||
Id int `json:"id"` | ||
Login string `json:"login"` | ||
LoginName string `json:"login_name"` | ||
FullName string `json:"full_name"` | ||
Email string `json:"email"` | ||
AvatarUrl string `json:"avatar_url"` | ||
Language string `json:"language"` | ||
IsAdmin bool `json:"is_admin"` | ||
LastLogin time.Time `json:"last_login"` | ||
Created time.Time `json:"created"` | ||
Restricted bool `json:"restricted"` | ||
Active bool `json:"active"` | ||
ProhibitLogin bool `json:"prohibit_login"` | ||
Location string `json:"location"` | ||
Website string `json:"website"` | ||
Description string `json:"description"` | ||
Visibility string `json:"visibility"` | ||
FollowersCount int `json:"followers_count"` | ||
FollowingCount int `json:"following_count"` | ||
StarredReposCount int `json:"starred_repos_count"` | ||
Username string `json:"username"` | ||
} `json:"owner"` | ||
Name string `json:"name"` | ||
FullName string `json:"full_name"` | ||
Description string `json:"description"` | ||
Empty bool `json:"empty"` | ||
Private bool `json:"private"` | ||
Fork bool `json:"fork"` | ||
Template bool `json:"template"` | ||
Parent interface{} `json:"parent"` | ||
Mirror bool `json:"mirror"` | ||
Size int `json:"size"` | ||
Language string `json:"language"` | ||
LanguagesUrl string `json:"languages_url"` | ||
HtmlUrl string `json:"html_url"` | ||
Url string `json:"url"` | ||
Link string `json:"link"` | ||
SshUrl string `json:"ssh_url"` | ||
CloneUrl string `json:"clone_url"` | ||
OriginalUrl string `json:"original_url"` | ||
Website string `json:"website"` | ||
StarsCount int `json:"stars_count"` | ||
ForksCount int `json:"forks_count"` | ||
WatchersCount int `json:"watchers_count"` | ||
OpenIssuesCount int `json:"open_issues_count"` | ||
OpenPrCounter int `json:"open_pr_counter"` | ||
ReleaseCounter int `json:"release_counter"` | ||
DefaultBranch string `json:"default_branch"` | ||
Archived bool `json:"archived"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
ArchivedAt time.Time `json:"archived_at"` | ||
Permissions struct { | ||
Admin bool `json:"admin"` | ||
Push bool `json:"push"` | ||
Pull bool `json:"pull"` | ||
} `json:"permissions"` | ||
HasIssues bool `json:"has_issues"` | ||
InternalTracker struct { | ||
EnableTimeTracker bool `json:"enable_time_tracker"` | ||
AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"` | ||
EnableIssueDependencies bool `json:"enable_issue_dependencies"` | ||
} `json:"internal_tracker"` | ||
HasWiki bool `json:"has_wiki"` | ||
HasPullRequests bool `json:"has_pull_requests"` | ||
HasProjects bool `json:"has_projects"` | ||
HasReleases bool `json:"has_releases"` | ||
HasPackages bool `json:"has_packages"` | ||
HasActions bool `json:"has_actions"` | ||
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"` | ||
AllowMergeCommits bool `json:"allow_merge_commits"` | ||
AllowRebase bool `json:"allow_rebase"` | ||
AllowRebaseExplicit bool `json:"allow_rebase_explicit"` | ||
AllowSquashMerge bool `json:"allow_squash_merge"` | ||
AllowRebaseUpdate bool `json:"allow_rebase_update"` | ||
DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"` | ||
DefaultMergeStyle string `json:"default_merge_style"` | ||
DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"` | ||
AvatarUrl string `json:"avatar_url"` | ||
Internal bool `json:"internal"` | ||
MirrorInterval string `json:"mirror_interval"` | ||
MirrorUpdated time.Time `json:"mirror_updated"` | ||
RepoTransfer interface{} `json:"repo_transfer"` | ||
} `json:"repository"` | ||
Pusher struct { | ||
Id int `json:"id"` | ||
Login string `json:"login"` | ||
LoginName string `json:"login_name"` | ||
FullName string `json:"full_name"` | ||
Email string `json:"email"` | ||
AvatarUrl string `json:"avatar_url"` | ||
Language string `json:"language"` | ||
IsAdmin bool `json:"is_admin"` | ||
LastLogin time.Time `json:"last_login"` | ||
Created time.Time `json:"created"` | ||
Restricted bool `json:"restricted"` | ||
Active bool `json:"active"` | ||
ProhibitLogin bool `json:"prohibit_login"` | ||
Location string `json:"location"` | ||
Website string `json:"website"` | ||
Description string `json:"description"` | ||
Visibility string `json:"visibility"` | ||
FollowersCount int `json:"followers_count"` | ||
FollowingCount int `json:"following_count"` | ||
StarredReposCount int `json:"starred_repos_count"` | ||
Username string `json:"username"` | ||
} `json:"pusher"` | ||
Sender struct { | ||
Id int `json:"id"` | ||
Login string `json:"login"` | ||
LoginName string `json:"login_name"` | ||
FullName string `json:"full_name"` | ||
Email string `json:"email"` | ||
AvatarUrl string `json:"avatar_url"` | ||
Language string `json:"language"` | ||
IsAdmin bool `json:"is_admin"` | ||
LastLogin time.Time `json:"last_login"` | ||
Created time.Time `json:"created"` | ||
Restricted bool `json:"restricted"` | ||
Active bool `json:"active"` | ||
ProhibitLogin bool `json:"prohibit_login"` | ||
Location string `json:"location"` | ||
Website string `json:"website"` | ||
Description string `json:"description"` | ||
Visibility string `json:"visibility"` | ||
FollowersCount int `json:"followers_count"` | ||
FollowingCount int `json:"following_count"` | ||
StarredReposCount int `json:"starred_repos_count"` | ||
Username string `json:"username"` | ||
} `json:"sender"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gitea | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
var ( | ||
name = "Gitea" | ||
) | ||
|
||
func HandleWebhook(header http.Header, msg string) (string, error) { | ||
hookType := header.Get("X-Gitea-Event") | ||
switch hookType { | ||
case "push": | ||
return giteaPushEventHandler(msg) | ||
} | ||
|
||
return fmt.Sprintf(TemplateUnsupport, name), nil | ||
|
||
} | ||
|
||
func giteaPushEventHandler(msg string) (string, error) { | ||
data := &GiteaPushEvent{} | ||
err := json.Unmarshal([]byte(msg), &data) | ||
|
||
if err != nil { | ||
return "", errors.New("解析Gitea Push事件失败") | ||
} | ||
|
||
return fmt.Sprintf(TemplatePush, | ||
name, | ||
data.Pusher.FullName, data.Pusher.Email, | ||
data.Repository.FullName, data.TotalCommits, | ||
data.CompareUrl, | ||
), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package gitea | ||
|
||
var ( | ||
TemplateUnsupport = ` | ||
🔔 来自%s的消息 | ||
⚠️ 暂不支持该类型 | ||
🙈 我们正在努力支持更多类型,敬请期待! | ||
` | ||
TemplatePush = ` | ||
🔔 来自%s的消息 | ||
👤 %s(%s) | ||
📌 向仓库 %s 推送了%d次提交 | ||
🔗 详情查看:%s | ||
📊 提交记录一目了然,快来一探究竟吧! | ||
` | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package event | ||
package github | ||
|
||
import ( | ||
"time" | ||
|
Oops, something went wrong.