Skip to content

Commit

Permalink
Improvements and bugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
celestix committed Aug 6, 2022
1 parent a327aaa commit 8e8e927
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
7 changes: 7 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"`
Expand Down
72 changes: 39 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ const PUSH_TEMPL = `
<b>Ref</b>: <code>%s</code>
<b>Changes</b>: <a href="%s">click here</a>
<b>Pusher's Name</b>: %s
<b>Pusher's Email</b>: %s
`
<b>Pusher's Email</b>: %s`

const ISSUE_TEMPL = `
<b><u><a href="github.com/gigauserbot">THE GIGA PROJECT</a></u></b>
Expand Down Expand Up @@ -133,22 +132,53 @@ 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{
{{Text: "Repository", Url: event.Repository.Url}},
},
},
)
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 += "\n<b>Commits<b>:"
for _, c := range event.Commits {
text += fmt.Sprintf(`\n • <a href="%s">%s<a>`, 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(
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

1 comment on commit 8e8e927

@celestix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Please sign in to comment.