fix: fix iconslug handling
Some checks failed
Sample Testing / my_job (push) Failing after 1m30s

This commit is contained in:
Marcel S. Henselin 2026-04-17 14:24:34 +02:00
parent d5b203cb65
commit c9f0fc3d86
3 changed files with 39 additions and 85 deletions

94
main.go
View file

@ -28,9 +28,6 @@ type templateData struct {
SubTitle string
Author string
IconUrl string
Project string
Commit string
Branch string
Status string
ActionID string
GitURL string
@ -65,27 +62,6 @@ func main() {
}
data.Title = title
project := githubactions.GetInput("project")
if project == "" {
githubactions.Fatalf("Missing input 'project'")
os.Exit(1)
}
data.Project = project
commit := githubactions.GetInput("commit")
if commit == "" {
githubactions.Fatalf("Missing input 'commit'")
os.Exit(1)
}
data.Commit = commit
branch := githubactions.GetInput("branch")
if branch == "" {
githubactions.Fatalf("Missing input 'branch'")
os.Exit(1)
}
data.Branch = branch
status := githubactions.GetInput("status")
if status == "" {
githubactions.Fatalf("Missing input 'status'")
@ -105,7 +81,7 @@ func main() {
githubactions.Fatalf("Missing input 'webhook'")
os.Exit(1)
}
webhook = fmt.Sprintf("%s&threadKey=%s%s&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD", webhook, data.Commit, data.ActionID)
webhook = fmt.Sprintf("%s&threadKey=notify%s&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD", webhook, data.ActionID)
giturl := githubactions.GetInput("giturl")
if giturl == "" {
@ -151,19 +127,6 @@ func main() {
}
}
func bodyString(s string, d templateData) string {
var buf bytes.Buffer
t, err := template.New("message").Parse(s)
if err != nil {
return ""
}
err = t.Execute(&buf, d)
if err != nil {
return ""
}
return buf.String()
}
func card(d templateData) ([]byte, error) {
switch d.Status {
case "success":
@ -175,7 +138,6 @@ func card(d templateData) ([]byte, error) {
}
if d.IconUrl == "" {
d.IconUrl = "https://github.githubassets.com/images/modules/logos_page/Octocat.png"
d.IconUrl = fmt.Sprintf(
"https://cdn.simpleicons.org/%s/%s",
d.IconSlug,
@ -184,36 +146,34 @@ func card(d templateData) ([]byte, error) {
}
if d.EventBody == "" {
d.EventBody = bodyString("<b>Project:</b> {{ .Project }}<br><b>Commit-id:</b> <font color='#FF0000'>{{ .Commit }}</font><br><b>Branch:</b> <font color='#00FF00f'>{{ .Branch }}</font><br><b>Build Status:</b> <font color='#0000ff'>{{ .Status }}</font>", d)
// d.EventBody = "<b>Project:</b> {{ .Project }}<br><b>Commit-id:</b> <font color=\"#FF0000\">{{ .Commit }}</font><br><b>Branch:</b> <font color=\"#00FF00f\">{{ .Branch }}</font><br><b>Build Status:</b> <font color=\"#0000ff\">{{ .Status }}</font>"
}
bdy := ""
prj, ok := os.LookupEnv("FORGEJO_REPOSITORY")
if ok {
bdy += fmt.Sprintf("<b>Project:</b> %s<br>", prj)
}
if d.Status == "success" {
d.Add = `
{
"decoratedText": {
"startIcon": {
"materialIcon": {
"name": "check_circle"
}
},
"text": "<b style=\"color: green;\">SUCCESS</b>"
}
},`
}
sha, ok := os.LookupEnv("FORGEJO_SHA")
if ok {
bdy += fmt.Sprintf("<b>Commit-id:</b> <font color='#FF0000'> %.*s</font><br>", 8, sha)
}
if d.Status == "failure" {
d.Add = `
{
"decoratedText": {
"startIcon": {
"materialIcon": {
"name": "stop_circle"
}
},
"text": "<b style=\"color: red;\">FAILURE</b>"
}
},`
ref, ok := os.LookupEnv("FORGEJO_REF")
if ok {
bdy += fmt.Sprintf("<b>Branch:</b> <font color='#00FF00f'>%s</font><br>", ref)
}
if d.Status == "" {
stat, ok := os.LookupEnv("JOB_STATUS")
if ok {
d.Status = stat
}
}
if d.Status != "" {
bdy += fmt.Sprintf("<b>Build Status:</b> <font color='#0000ff'>%s</font>", d.Status)
}
d.EventBody = bdy
}
tmpl, err := template.New("message").Parse(message)