mirror of
https://github.com/pinpox/gitea-matrix-bot
synced 2024-11-22 10:21:58 +01:00
cleaned up postdata struct
This commit is contained in:
parent
313c3e10de
commit
349ef28ba7
45
listener.go
45
listener.go
@ -43,13 +43,11 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
json.Unmarshal(body, &postData)
|
||||
|
||||
// fmt.Println(string(body))
|
||||
|
||||
fmt.Printf("%+v\n", postData)
|
||||
fmt.Println("=================================================")
|
||||
spew.Dump(postData)
|
||||
fmt.Println("=================================================")
|
||||
|
||||
fmt.Println(string(body))
|
||||
fmt.Println("=================================================")
|
||||
fmt.Println(generateMessage(postData, r.Header.Get("X-Gitea-Event")))
|
||||
fmt.Println("=================================================")
|
||||
@ -80,7 +78,7 @@ func generateMessage(data GiteaPostData, eventHeader string) string {
|
||||
case "issues":
|
||||
switch data.Action {
|
||||
case "assigned":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} assigned issue #{{.Issue.Number}} {{.Issue.Title}} to TODO ")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} assigned issue #{{.Issue.Number}} {{.Issue.Title}} to {{}} ")
|
||||
case "closed":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} closed issue #{{.Issue.Number}} {{.Issue.Title}}")
|
||||
case "demilestoned":
|
||||
@ -104,47 +102,40 @@ func generateMessage(data GiteaPostData, eventHeader string) string {
|
||||
}
|
||||
|
||||
case "fork":
|
||||
// switch data.Action {
|
||||
// case "created":
|
||||
templ.Parse("{{.Sender.FullName}} forked repository {{.Repository.Parent.FullName}} to {{.Repository.FullName}}")
|
||||
// case "edited":
|
||||
// templ.Parse("{{.Sender.FullName}} edited repository fork {{}}")
|
||||
// case "deleted":
|
||||
// templ.Parse("{{.Sender.FullName}} deleted repository fork {{}}")
|
||||
// }
|
||||
|
||||
case "pull_request":
|
||||
switch data.Action {
|
||||
case "assigned":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} assigned pull-request {{}} {{}} to {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} assigned pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\" to {{.PullRequest.Assignee.FullName}}")
|
||||
case "closed":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} closed pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} closed pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "demilestoned":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} removed milestone TODO from pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} removed milestone TODO from pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "edited":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} edited pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} edited pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "label_cleared":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} removed labels from pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} removed labels from pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "label_updated":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} updated labels from pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} updated labels from pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "milestoned":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} added pull-request {{}} {{}} to milestone TODO")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} added pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\" to milestone TODO")
|
||||
case "opened":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} opened pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} opened pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "reopened":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} re-opened pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} re-opened pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "synchronized":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} synchronized pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} synchronized pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "unassigned":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} removed assinee {{}} from pull-request {{}} {{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} removed assinee from pull-request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
}
|
||||
|
||||
case "issue_comment":
|
||||
switch data.Action {
|
||||
case "created":
|
||||
templ.Parse("{{.Sender.FullName}} commented issue #{{.Issue.Number}} {{.Issue.Title}}: {{.Comment.Body}}")
|
||||
templ.Parse("{{.Sender.FullName}} commented on #{{.Issue.Number}} {{.Issue.Title}}: {{.Comment.Body}}")
|
||||
case "deleted":
|
||||
templ.Parse("{{.Sender.FullName}} deleted commented on issue #{{.Issue.Number}} {{.Issue.Title}}")
|
||||
templ.Parse("{{.Sender.FullName}} deleted commented on #{{.Issue.Number}} {{.Issue.Title}}")
|
||||
}
|
||||
|
||||
case "repository":
|
||||
@ -166,11 +157,11 @@ func generateMessage(data GiteaPostData, eventHeader string) string {
|
||||
}
|
||||
|
||||
case "pull_request_approved":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} approved pull request {{}}{{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} approved pull request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "pull_request_rejected":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} rejected pull request {{}}{{}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} rejected pull request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\"")
|
||||
case "pull_request_comment":
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} commented on pull request {{}}{{}}: {{.Comment.Body}}")
|
||||
templ.Parse("{{.Repository.FullName}}: {{.Sender.FullName}} commented on pull request #{{.PullRequest.Number}} \"{{.PullRequest.Title}}\": {{.Comment.Body}}")
|
||||
default:
|
||||
|
||||
fmt.Println("Unknown action: " + eventHeader + " " + data.Action)
|
||||
|
342
postdata.go
342
postdata.go
@ -4,165 +4,199 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type GiteaPostData struct {
|
||||
Secret string `json:"secret"`
|
||||
Action string `json:"action"`
|
||||
Number int `json:"number"`
|
||||
Ref string `json:"ref"`
|
||||
Before string `json:"before"`
|
||||
After string `json:"after"`
|
||||
CompareURL string `json:"compare_url"`
|
||||
Issue struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Number int `json:"number"`
|
||||
User struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
} `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []interface{} `json:"labels"`
|
||||
Milestone interface{} `json:"milestone"`
|
||||
Assignee interface{} `json:"assignee"`
|
||||
Assignees interface{} `json:"assignees"`
|
||||
State string `json:"state"`
|
||||
Comments int `json:"comments"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ClosedAt interface{} `json:"closed_at"`
|
||||
DueDate interface{} `json:"due_date"`
|
||||
PullRequest interface{} `json:"pull_request"`
|
||||
} `json:"issue"`
|
||||
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"`
|
||||
} `json:"commits"`
|
||||
Comment struct {
|
||||
ID int `json:"id"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
PullRequestURL string `json:"pull_request_url"`
|
||||
IssueURL string `json:"issue_url"`
|
||||
User struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
} `json:"user"`
|
||||
Body string `json:"body"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
} `json:"comment"`
|
||||
Repository struct {
|
||||
ID int `json:"id"`
|
||||
Owner struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
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"`
|
||||
Parent struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Empty bool `json:"empty"`
|
||||
Fork bool `json:"fork"`
|
||||
Private bool `json:"private"`
|
||||
Archived bool `json:"archived"`
|
||||
FullName string `json:"full_name"`
|
||||
ForksCount int `json:"forks_count"`
|
||||
ID int `json:"id"`
|
||||
OpenIssuesCount int `json:"open_issues_count"`
|
||||
Size int `json:"size"`
|
||||
StarsCount int `json:"stars_count"`
|
||||
Name string `json:"name"`
|
||||
CloneURL string `json:"clone_url"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
SSHURL string `json:"ssh_url"`
|
||||
WatchersCount int `json:"watchers_count"`
|
||||
Description string `json:"description"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Website string `json:"website"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
Owner struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
} `json:"owner"`
|
||||
Permissions struct {
|
||||
Admin bool `json:"admin"`
|
||||
Push bool `json:"push"`
|
||||
Pull bool `json:"pull"`
|
||||
} `json:"permissions"`
|
||||
} `json:"parent"`
|
||||
Mirror bool `json:"mirror"`
|
||||
Size int `json:"size"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
SSHURL string `json:"ssh_url"`
|
||||
CloneURL string `json:"clone_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"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Archived bool `json:"archived"`
|
||||
type GiteaUser struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type GiteaRepository struct {
|
||||
ID int `json:"id"`
|
||||
Owner GiteaUser `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"`
|
||||
Parent struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Empty bool `json:"empty"`
|
||||
Fork bool `json:"fork"`
|
||||
Private bool `json:"private"`
|
||||
Archived bool `json:"archived"`
|
||||
FullName string `json:"full_name"`
|
||||
ForksCount int `json:"forks_count"`
|
||||
ID int `json:"id"`
|
||||
OpenIssuesCount int `json:"open_issues_count"`
|
||||
Size int `json:"size"`
|
||||
StarsCount int `json:"stars_count"`
|
||||
Name string `json:"name"`
|
||||
CloneURL string `json:"clone_url"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
SSHURL string `json:"ssh_url"`
|
||||
WatchersCount int `json:"watchers_count"`
|
||||
Description string `json:"description"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Website string `json:"website"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
Owner GiteaUser `json:"owner"`
|
||||
Permissions struct {
|
||||
Admin bool `json:"admin"`
|
||||
Push bool `json:"push"`
|
||||
Pull bool `json:"pull"`
|
||||
} `json:"permissions"`
|
||||
} `json:"repository"`
|
||||
Pusher struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
} `json:"pusher"`
|
||||
Sender struct {
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
} `json:"sender"`
|
||||
} `json:"parent"`
|
||||
Mirror bool `json:"mirror"`
|
||||
Size int `json:"size"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
SSHURL string `json:"ssh_url"`
|
||||
CloneURL string `json:"clone_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"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Archived bool `json:"archived"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Permissions struct {
|
||||
Admin bool `json:"admin"`
|
||||
Push bool `json:"push"`
|
||||
Pull bool `json:"pull"`
|
||||
} `json:"permissions"`
|
||||
}
|
||||
|
||||
type GiteaRelease struct {
|
||||
ID int `json:"id"`
|
||||
TagName string `json:"tag_name"`
|
||||
TargetCommitish string `json:"target_commitish"`
|
||||
Name string `json:"name"`
|
||||
Body string `json:"body"`
|
||||
URL string `json:"url"`
|
||||
TarballURL string `json:"tarball_url"`
|
||||
ZipballURL string `json:"zipball_url"`
|
||||
Draft bool `json:"draft"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
Author GiteaUser `json:"author"`
|
||||
Assets []interface{} `json:"assets"`
|
||||
}
|
||||
|
||||
type GiteaPullRequest struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Number int `json:"number"`
|
||||
User GiteaUser `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []interface{} `json:"labels"`
|
||||
Milestone GiteaMilestone `json:"milestone"`
|
||||
Assignee GiteaUser `json:"assignee"`
|
||||
Assignees []GiteaUser `json:"assignees"`
|
||||
State string `json:"state"`
|
||||
Comments int `json:"comments"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
DiffURL string `json:"diff_url"`
|
||||
PatchURL string `json:"patch_url"`
|
||||
Mergeable bool `json:"mergeable"`
|
||||
Merged bool `json:"merged"`
|
||||
MergedAt time.Time `json:"merged_at"`
|
||||
MergeCommitSha interface{} `json:"merge_commit_sha"`
|
||||
MergedBy interface{} `json:"merged_by"`
|
||||
Base struct {
|
||||
Label string `json:"label"`
|
||||
Ref string `json:"ref"`
|
||||
Sha string `json:"sha"`
|
||||
RepoID int `json:"repo_id"`
|
||||
Repo GiteaRepository `json:"repo"`
|
||||
} `json:"base"`
|
||||
Head struct {
|
||||
Label string `json:"label"`
|
||||
Ref string `json:"ref"`
|
||||
Sha string `json:"sha"`
|
||||
RepoID int `json:"repo_id"`
|
||||
Repo GiteaRepository `json:"repo"`
|
||||
} `json:"head"`
|
||||
MergeBase string `json:"merge_base"`
|
||||
DueDate time.Time `json:"due_date"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ClosedAt time.Time `json:"closed_at"`
|
||||
}
|
||||
|
||||
type GiteaMilestone struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
State string `json:"state"`
|
||||
OpenIssues int `json:"open_issues"`
|
||||
ClosedIssues int `json:"closed_issues"`
|
||||
ClosedAt time.Time `json:"closed_at"`
|
||||
DueOn time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
type GiteaIssue struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Number int `json:"number"`
|
||||
User GiteaUser `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []interface{} `json:"labels"`
|
||||
Milestone GiteaMilestone `json:"milestone"`
|
||||
Assignee GiteaUser `json:"assignee"`
|
||||
Assignees []GiteaUser `json:"assignees"`
|
||||
State string `json:"state"`
|
||||
Comments int `json:"comments"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ClosedAt time.Time `json:"closed_at"`
|
||||
DueDate time.Time `json:"due_date"`
|
||||
PullRequest time.Time `json:"pull_request"`
|
||||
}
|
||||
|
||||
type GiteaCommit struct {
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Author GiteaUser `json:"author"`
|
||||
Committer GiteaUser `json:"committer"`
|
||||
Verification interface{} `json:"verification"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
type GiteaComment struct {
|
||||
ID int `json:"id"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
PullRequestURL string `json:"pull_request_url"`
|
||||
IssueURL string `json:"issue_url"`
|
||||
User GiteaUser `json:"user"`
|
||||
Body string `json:"body"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
type GiteaPostData struct {
|
||||
Secret string `json:"secret"`
|
||||
Action string `json:"action"`
|
||||
Number int `json:"number"`
|
||||
Ref string `json:"ref"`
|
||||
Before string `json:"before"`
|
||||
After string `json:"after"`
|
||||
CompareURL string `json:"compare_url"`
|
||||
Release GiteaRelease `json:"release"`
|
||||
PullRequest GiteaPullRequest `json:"pull_request"`
|
||||
Issue GiteaIssue `json:"issue"`
|
||||
Commits []GiteaCommit `json:"commits"`
|
||||
Comment GiteaComment `json:"comment"`
|
||||
Repository GiteaRepository `json:"repository"`
|
||||
Pusher GiteaUser `json:"pusher"`
|
||||
Sender GiteaUser `json:"sender"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user