From 91c0d241df215ff628523403f367962cd965c28c Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 8 Mar 2025 16:29:54 +0800 Subject: [PATCH] refactor: refactor GitHub event handling in Template function - Refactor the handling of GitHub events in the Template function - Replace the message construction with a switch statement for better clarity - Simplify the logic for determining the branch in pull requests - Update the case structure for handling different build events Signed-off-by: appleboy --- plugin.go | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/plugin.go b/plugin.go index 52466ec..7326a1f 100644 --- a/plugin.go +++ b/plugin.go @@ -283,37 +283,24 @@ func (p *Plugin) DefaultTemplate(title string) EmbedObject { // Template is plugin default template for Drone CI or GitHub Action. func (p *Plugin) Template() EmbedObject { - if p.Config.GitHub { - message := fmt.Sprintf("%s/%s triggered by %s (%s)", + var description string + switch { + case p.Config.GitHub: + description = fmt.Sprintf("%s/%s triggered by %s (%s)", p.Repo.FullName, p.GitHub.Workflow, p.Repo.Namespace, p.GitHub.EventName, ) - - return EmbedObject{ - Title: message, - Color: p.Color(), - Footer: EmbedFooterObject{ - Text: DroneDesc, - IconURL: DroneIconURL, - }, - } - } - - description := "" - switch p.Build.Event { - case "push": + case p.Build.Event == "push": description = fmt.Sprintf("%s pushed to %s", p.Commit.Author, p.Commit.Branch) - case "pull_request": - branch := "" - if p.Commit.Ref != "" { - branch = p.Commit.Ref - } else { + case p.Build.Event == "pull_request": + branch := p.Commit.Ref + if branch == "" { branch = p.Commit.Branch } description = fmt.Sprintf("%s updated pull request %s", p.Commit.Author, branch) - case "tag": + case p.Build.Event == "tag": description = fmt.Sprintf("%s pushed tag %s", p.Commit.Author, p.Commit.Branch) }