diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index f1cbb04..a1cb447 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -20,13 +20,10 @@ jobs: with: author: ${{ forgejo.actor }} giturl: ${{ forgejo.server_url }} - project: ${{ forgejo.repository }} - commit: ${{ steps.slug.outputs.sha8 }} - branch: ${{ forgejo.ref }} - status: ${{ job.status }} - actionid: ${{ forgejo.run_id }} + # status: ${{ job.status }} + actionid: ${{ forgejo.run_number }} webhook: "${{ secrets.WEBHOOK_URL }}" - event_body: "" + # event_body: "" # optional - name: Second Chat Message as ThreadResponse if: ${{ always() }} @@ -34,10 +31,7 @@ jobs: with: author: ${{ forgejo.actor }} giturl: ${{ forgejo.server_url }} - project: ${{ forgejo.repository }} - commit: ${{ steps.slug.outputs.sha8 }} - branch: ${{ forgejo.ref }} status: ${{ job.status }} - actionid: ${{ forgejo.run_id }} + actionid: ${{ forgejo.run_number }} webhook: "${{ secrets.WEBHOOK_URL }}" event_body: "this time I provided a body" diff --git a/action.yml b/action.yml index 685401d..9fd03e3 100644 --- a/action.yml +++ b/action.yml @@ -5,17 +5,14 @@ branding: icon: 'at-sign' color: 'green' inputs: - project: - description: 'Github Project Name' + autor: + description: 'Git Action Author' required: true - commit: - description: 'Github Commit ID' - required: true - branch: - description: 'Github Branch' + giturl: + description: 'Git Server URL' required: true status: - description: 'Github Action Build Status' + description: 'Git Action Build Status' required: true actionid: description: 'Current Running Action ID' @@ -23,6 +20,9 @@ inputs: webhook: description: 'Google Chat Webhook URL' required: true + event_body: + description: 'Google Chat Event Body' + required: true runs: using: 'docker' diff --git a/main.go b/main.go index d0f6c29..1a6bc87 100644 --- a/main.go +++ b/main.go @@ -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("Project: {{ .Project }}
Commit-id: {{ .Commit }}
Branch: {{ .Branch }}
Build Status: {{ .Status }}", d) - // d.EventBody = "Project: {{ .Project }}
Commit-id: {{ .Commit }}
Branch: {{ .Branch }}
Build Status: {{ .Status }}" - } + bdy := "" + prj, ok := os.LookupEnv("FORGEJO_REPOSITORY") + if ok { + bdy += fmt.Sprintf("Project: %s
", prj) + } - if d.Status == "success" { - d.Add = ` -{ - "decoratedText": { - "startIcon": { - "materialIcon": { - "name": "check_circle" - } - }, - "text": "SUCCESS" - } -},` - } + sha, ok := os.LookupEnv("FORGEJO_SHA") + if ok { + bdy += fmt.Sprintf("Commit-id: %.*s
", 8, sha) + } - if d.Status == "failure" { - d.Add = ` -{ - "decoratedText": { - "startIcon": { - "materialIcon": { - "name": "stop_circle" - } - }, - "text": "FAILURE" - } -},` + ref, ok := os.LookupEnv("FORGEJO_REF") + if ok { + bdy += fmt.Sprintf("Branch: %s
", ref) + } + + if d.Status == "" { + stat, ok := os.LookupEnv("JOB_STATUS") + if ok { + d.Status = stat + } + } + + if d.Status != "" { + bdy += fmt.Sprintf("Build Status: %s", d.Status) + } + + d.EventBody = bdy } tmpl, err := template.New("message").Parse(message)