This commit is contained in:
parent
d5b203cb65
commit
c9f0fc3d86
3 changed files with 39 additions and 85 deletions
14
.github/workflows/example.yml
vendored
14
.github/workflows/example.yml
vendored
|
|
@ -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 <b>I</b> provided a body"
|
||||
|
|
|
|||
16
action.yml
16
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'
|
||||
|
|
|
|||
94
main.go
94
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("<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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue