From 8e8e92760d50b4b3899c3b1eff1798ee533d68c7 Mon Sep 17 00:00:00 2001
From: Anony <73958752+anonyindian@users.noreply.github.com>
Date: Sat, 6 Aug 2022 08:43:05 +0000
Subject: [PATCH] Improvements and bugs fix
---
events.go | 7 ++++++
main.go | 72 ++++++++++++++++++++++++++++++-------------------------
2 files changed, 46 insertions(+), 33 deletions(-)
diff --git a/events.go b/events.go
index e7fe4c8..9c89bc2 100644
--- a/events.go
+++ b/events.go
@@ -10,6 +10,8 @@ type Event struct {
Action string `json:"action,omitempty"`
// The commit comment resource.
Comment Comment `json:"comment,omitempty"`
+ // Commits
+ Commits []Commit `json:"commits,omitempty"`
// The discussion resource.
Discussion Discussion `json:"discussion,omitempty"`
// The issue the comment belongs to.
@@ -24,6 +26,11 @@ type Event struct {
Compare string `json:"compare,omitempty"`
}
+type Commit struct {
+ Message string `json:"message"`
+ Url string `json:"url"`
+}
+
type Pusher struct {
Name string `json:"name"`
Email string `json:"email,omitempty"`
diff --git a/main.go b/main.go
index 5b13c5b..b63eb80 100644
--- a/main.go
+++ b/main.go
@@ -74,8 +74,7 @@ const PUSH_TEMPL = `
Ref: %s
Changes: click here
Pusher's Name: %s
-Pusher's Email: %s
-`
+Pusher's Email: %s`
const ISSUE_TEMPL = `
THE GIGA PROJECT
@@ -133,15 +132,23 @@ func handleUpdate(b *gotgbot.Bot, event *Event) {
return
}
switch {
- case event.Ref != "":
+ case event.Comment.Url != "":
+ var ctype string
+ if event.Issue.Number != 0 {
+ ctype = "Issue Comment"
+ } else if event.Discussion.Number != 0 {
+ ctype = "Discussion Comment"
+ } else {
+ ctype = "Commit Comment"
+ }
send(b,
fmt.Sprintf(
- PUSH_TEMPL,
+ COMNT_TEMPL,
event.Repository.Name,
- event.Ref,
- event.Compare,
- event.Pusher.Name,
- event.Pusher.Email,
+ ctype,
+ event.Comment.Url,
+ event.Action,
+ event.Sender.Name,
),
&gotgbot.InlineKeyboardMarkup{
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
@@ -149,6 +156,29 @@ func handleUpdate(b *gotgbot.Bot, event *Event) {
},
},
)
+ case event.Ref != "":
+ text := fmt.Sprintf(
+ PUSH_TEMPL,
+ event.Repository.Name,
+ event.Ref,
+ event.Compare,
+ event.Pusher.Name,
+ event.Pusher.Email,
+ )
+ if len(event.Commits) > 0 {
+ text += "\nCommits:"
+ for _, c := range event.Commits {
+ text += fmt.Sprintf(`\n • %s`, c.Url, c.Message)
+ }
+ }
+ send(b,
+ text,
+ &gotgbot.InlineKeyboardMarkup{
+ InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
+ {{Text: "Repository", Url: event.Repository.Url}},
+ },
+ },
+ )
case event.Issue.Number != 0:
send(b,
fmt.Sprintf(
@@ -157,7 +187,7 @@ func handleUpdate(b *gotgbot.Bot, event *Event) {
event.Action,
event.Issue.Url,
event.Issue.Title,
- event.Issue.User.Name,
+ event.Sender.Name,
),
&gotgbot.InlineKeyboardMarkup{
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
@@ -189,30 +219,6 @@ func handleUpdate(b *gotgbot.Bot, event *Event) {
event.Action,
event.Discussion.Url,
event.Discussion.Title,
- event.Discussion.User.Name,
- ),
- &gotgbot.InlineKeyboardMarkup{
- InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
- {{Text: "Repository", Url: event.Repository.Url}},
- },
- },
- )
- case event.Comment.Url != "":
- var ctype string
- if event.Issue.Number != 0 {
- ctype = "Issue Comment"
- } else if event.Discussion.Number != 0 {
- ctype = "Discussion Comment"
- } else {
- ctype = "Commit Comment"
- }
- send(b,
- fmt.Sprintf(
- DISC_TEMPL,
- event.Repository.Name,
- ctype,
- event.Comment.Url,
- event.Action,
event.Sender.Name,
),
&gotgbot.InlineKeyboardMarkup{