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:
|
with:
|
||||||
author: ${{ forgejo.actor }}
|
author: ${{ forgejo.actor }}
|
||||||
giturl: ${{ forgejo.server_url }}
|
giturl: ${{ forgejo.server_url }}
|
||||||
project: ${{ forgejo.repository }}
|
# status: ${{ job.status }}
|
||||||
commit: ${{ steps.slug.outputs.sha8 }}
|
actionid: ${{ forgejo.run_number }}
|
||||||
branch: ${{ forgejo.ref }}
|
|
||||||
status: ${{ job.status }}
|
|
||||||
actionid: ${{ forgejo.run_id }}
|
|
||||||
webhook: "${{ secrets.WEBHOOK_URL }}"
|
webhook: "${{ secrets.WEBHOOK_URL }}"
|
||||||
event_body: ""
|
# event_body: "" # optional
|
||||||
|
|
||||||
- name: Second Chat Message as ThreadResponse
|
- name: Second Chat Message as ThreadResponse
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
|
|
@ -34,10 +31,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
author: ${{ forgejo.actor }}
|
author: ${{ forgejo.actor }}
|
||||||
giturl: ${{ forgejo.server_url }}
|
giturl: ${{ forgejo.server_url }}
|
||||||
project: ${{ forgejo.repository }}
|
|
||||||
commit: ${{ steps.slug.outputs.sha8 }}
|
|
||||||
branch: ${{ forgejo.ref }}
|
|
||||||
status: ${{ job.status }}
|
status: ${{ job.status }}
|
||||||
actionid: ${{ forgejo.run_id }}
|
actionid: ${{ forgejo.run_number }}
|
||||||
webhook: "${{ secrets.WEBHOOK_URL }}"
|
webhook: "${{ secrets.WEBHOOK_URL }}"
|
||||||
event_body: "this time <b>I</b> provided a body"
|
event_body: "this time <b>I</b> provided a body"
|
||||||
|
|
|
||||||
16
action.yml
16
action.yml
|
|
@ -5,17 +5,14 @@ branding:
|
||||||
icon: 'at-sign'
|
icon: 'at-sign'
|
||||||
color: 'green'
|
color: 'green'
|
||||||
inputs:
|
inputs:
|
||||||
project:
|
autor:
|
||||||
description: 'Github Project Name'
|
description: 'Git Action Author'
|
||||||
required: true
|
required: true
|
||||||
commit:
|
giturl:
|
||||||
description: 'Github Commit ID'
|
description: 'Git Server URL'
|
||||||
required: true
|
|
||||||
branch:
|
|
||||||
description: 'Github Branch'
|
|
||||||
required: true
|
required: true
|
||||||
status:
|
status:
|
||||||
description: 'Github Action Build Status'
|
description: 'Git Action Build Status'
|
||||||
required: true
|
required: true
|
||||||
actionid:
|
actionid:
|
||||||
description: 'Current Running Action ID'
|
description: 'Current Running Action ID'
|
||||||
|
|
@ -23,6 +20,9 @@ inputs:
|
||||||
webhook:
|
webhook:
|
||||||
description: 'Google Chat Webhook URL'
|
description: 'Google Chat Webhook URL'
|
||||||
required: true
|
required: true
|
||||||
|
event_body:
|
||||||
|
description: 'Google Chat Event Body'
|
||||||
|
required: true
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
|
|
|
||||||
94
main.go
94
main.go
|
|
@ -28,9 +28,6 @@ type templateData struct {
|
||||||
SubTitle string
|
SubTitle string
|
||||||
Author string
|
Author string
|
||||||
IconUrl string
|
IconUrl string
|
||||||
Project string
|
|
||||||
Commit string
|
|
||||||
Branch string
|
|
||||||
Status string
|
Status string
|
||||||
ActionID string
|
ActionID string
|
||||||
GitURL string
|
GitURL string
|
||||||
|
|
@ -65,27 +62,6 @@ func main() {
|
||||||
}
|
}
|
||||||
data.Title = title
|
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")
|
status := githubactions.GetInput("status")
|
||||||
if status == "" {
|
if status == "" {
|
||||||
githubactions.Fatalf("Missing input 'status'")
|
githubactions.Fatalf("Missing input 'status'")
|
||||||
|
|
@ -105,7 +81,7 @@ func main() {
|
||||||
githubactions.Fatalf("Missing input 'webhook'")
|
githubactions.Fatalf("Missing input 'webhook'")
|
||||||
os.Exit(1)
|
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")
|
giturl := githubactions.GetInput("giturl")
|
||||||
if 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) {
|
func card(d templateData) ([]byte, error) {
|
||||||
switch d.Status {
|
switch d.Status {
|
||||||
case "success":
|
case "success":
|
||||||
|
|
@ -175,7 +138,6 @@ func card(d templateData) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.IconUrl == "" {
|
if d.IconUrl == "" {
|
||||||
d.IconUrl = "https://github.githubassets.com/images/modules/logos_page/Octocat.png"
|
|
||||||
d.IconUrl = fmt.Sprintf(
|
d.IconUrl = fmt.Sprintf(
|
||||||
"https://cdn.simpleicons.org/%s/%s",
|
"https://cdn.simpleicons.org/%s/%s",
|
||||||
d.IconSlug,
|
d.IconSlug,
|
||||||
|
|
@ -184,36 +146,34 @@ func card(d templateData) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.EventBody == "" {
|
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)
|
bdy := ""
|
||||||
// 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>"
|
prj, ok := os.LookupEnv("FORGEJO_REPOSITORY")
|
||||||
}
|
if ok {
|
||||||
|
bdy += fmt.Sprintf("<b>Project:</b> %s<br>", prj)
|
||||||
|
}
|
||||||
|
|
||||||
if d.Status == "success" {
|
sha, ok := os.LookupEnv("FORGEJO_SHA")
|
||||||
d.Add = `
|
if ok {
|
||||||
{
|
bdy += fmt.Sprintf("<b>Commit-id:</b> <font color='#FF0000'> %.*s</font><br>", 8, sha)
|
||||||
"decoratedText": {
|
}
|
||||||
"startIcon": {
|
|
||||||
"materialIcon": {
|
|
||||||
"name": "check_circle"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"text": "<b style=\"color: green;\">SUCCESS</b>"
|
|
||||||
}
|
|
||||||
},`
|
|
||||||
}
|
|
||||||
|
|
||||||
if d.Status == "failure" {
|
ref, ok := os.LookupEnv("FORGEJO_REF")
|
||||||
d.Add = `
|
if ok {
|
||||||
{
|
bdy += fmt.Sprintf("<b>Branch:</b> <font color='#00FF00f'>%s</font><br>", ref)
|
||||||
"decoratedText": {
|
}
|
||||||
"startIcon": {
|
|
||||||
"materialIcon": {
|
if d.Status == "" {
|
||||||
"name": "stop_circle"
|
stat, ok := os.LookupEnv("JOB_STATUS")
|
||||||
}
|
if ok {
|
||||||
},
|
d.Status = stat
|
||||||
"text": "<b style=\"color: red;\">FAILURE</b>"
|
}
|
||||||
}
|
}
|
||||||
},`
|
|
||||||
|
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)
|
tmpl, err := template.New("message").Parse(message)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue