Compare commits
15 Commits
1be5eb5235
...
latest
| Author | SHA1 | Date | |
|---|---|---|---|
| 3df77f624a | |||
| cf91676e99 | |||
| 73c11089e4 | |||
| 33e72ccf48 | |||
| 244b5da60d | |||
| bd5614c4e6 | |||
| cafd7dd5bb | |||
| 0e8b02a9b1 | |||
| a9ce145256 | |||
| 7d26f57ed4 | |||
| 78da95269c | |||
| 3ac378c589 | |||
| add713ec38 | |||
| 01f4eecb0b | |||
| b41d0c6f26 |
7
.github/workflows/update.yml
vendored
7
.github/workflows/update.yml
vendored
@@ -12,8 +12,11 @@ jobs:
|
||||
id: use-go-action
|
||||
uses: https://git.aweoo.com/action/gotify@latest
|
||||
with:
|
||||
username: foo
|
||||
- name: Print Output
|
||||
url: ${{ secrets.url }}
|
||||
token: ${{ secrets.token }}
|
||||
title: GotifyAction版本更新
|
||||
msgText: ${{ vars.msgText }}
|
||||
- name: 打印上一步的输出
|
||||
run: echo 'output time is ${{ steps.use-go-action.outputs.time }}'
|
||||
- name: 错误处理
|
||||
if: ${{ failure() }}
|
||||
|
||||
@@ -10,3 +10,4 @@ tasks:
|
||||
- git push origin --tags
|
||||
- git push
|
||||
|
||||
|
||||
|
||||
23
action.yaml
23
action.yaml
@@ -1,12 +1,29 @@
|
||||
name: 'Gotify通知'
|
||||
description: '发送Gotify通知'
|
||||
inputs:
|
||||
username:
|
||||
description: 'The username to print'
|
||||
url:
|
||||
description: '地址 不需要/message'
|
||||
required: true
|
||||
token:
|
||||
description: "token"
|
||||
required: true
|
||||
title:
|
||||
description: "标题"
|
||||
required: true
|
||||
msgText:
|
||||
description: "消息内容"
|
||||
contentType:
|
||||
description: "消息格式"
|
||||
default: "text/markdown"
|
||||
priority:
|
||||
description: "优先级"
|
||||
clickUrl:
|
||||
description: "点击跳转地址"
|
||||
bigImageUrl:
|
||||
description: "大图地址"
|
||||
outputs:
|
||||
time:
|
||||
description: 'The time when the action was called'
|
||||
description: '结束时间(无用)'
|
||||
runs:
|
||||
using: 'go'
|
||||
main: 'main.go'
|
||||
|
||||
32
go.mod
32
go.mod
@@ -2,4 +2,34 @@ module git.aweoo.com/action/gotify
|
||||
|
||||
go 1.23.3
|
||||
|
||||
require github.com/sethvargo/go-githubactions v1.3.0 // indirect
|
||||
require (
|
||||
github.com/duke-git/lancet/v2 v2.3.4
|
||||
github.com/golang-cz/devslog v0.0.11
|
||||
github.com/gotify/go-api-client/v2 v2.0.4
|
||||
github.com/imroc/req/v3 v3.49.0
|
||||
github.com/sethvargo/go-githubactions v1.3.0
|
||||
github.com/spf13/cast v1.7.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/cloudflare/circl v1.5.0 // indirect
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.22.0 // indirect
|
||||
github.com/quic-go/qpack v0.5.1 // indirect
|
||||
github.com/quic-go/quic-go v0.48.2 // indirect
|
||||
github.com/refraction-networking/utls v1.6.7 // indirect
|
||||
go.uber.org/mock v0.5.0 // indirect
|
||||
golang.org/x/crypto v0.31.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
|
||||
golang.org/x/mod v0.22.0 // indirect
|
||||
golang.org/x/net v0.32.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/tools v0.28.0 // indirect
|
||||
)
|
||||
|
||||
106
go.sum
106
go.sum
@@ -1,2 +1,108 @@
|
||||
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
|
||||
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/duke-git/lancet/v2 v2.3.4 h1:8XGI7P9w+/GqmEBEXYaH/XuNiM0f4/90Ioti0IvYJls=
|
||||
github.com/duke-git/lancet/v2 v2.3.4/go.mod h1:zGa2R4xswg6EG9I6WnyubDbFO/+A/RROxIbXcwryTsc=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI=
|
||||
github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik=
|
||||
github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
|
||||
github.com/go-openapi/errors v0.17.2/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
|
||||
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
||||
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||
github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
||||
github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA=
|
||||
github.com/go-openapi/runtime v0.17.2/go.mod h1:QO936ZXeisByFmZEO1IS1Dqhtf4QV1sYYFtIq6Ld86Q=
|
||||
github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
|
||||
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
||||
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
||||
github.com/go-openapi/validate v0.17.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
|
||||
github.com/golang-cz/devslog v0.0.11 h1:v4Yb9o0ZpuZ/D8ZrtVw1f9q5XrjnkxwHF1XmWwO8IHg=
|
||||
github.com/golang-cz/devslog v0.0.11/go.mod h1:bSe5bm0A7Nyfqtijf1OMNgVJHlWEuVSXnkuASiE1vV8=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
|
||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gotify/go-api-client/v2 v2.0.4 h1:0w8skCr8aLBDKaQDg31LKKHUGF7rt7zdRpR+6cqIAlE=
|
||||
github.com/gotify/go-api-client/v2 v2.0.4/go.mod h1:VKiah/UK20bXsr0JObE1eBVLW44zbBouzjuri9iwjFU=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/imroc/req/v3 v3.49.0 h1:5Rac2qvz7Dq0E3PeBo/c2szV3hagPQIGLoHtfBmYhu4=
|
||||
github.com/imroc/req/v3 v3.49.0/go.mod h1:XZf4t94DNJzcA0UOBlA68hmSrWsAyvN407ADdH4mzCA=
|
||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg=
|
||||
github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
|
||||
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
|
||||
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
||||
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
|
||||
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
|
||||
github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM=
|
||||
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/sethvargo/go-githubactions v1.3.0 h1:Kg633LIUV2IrJsqy2MfveiED/Ouo+H2P0itWS0eLh8A=
|
||||
github.com/sethvargo/go-githubactions v1.3.0/go.mod h1:7/4WeHgYfSz9U5vwuToCK9KPnELVHAhGtRwLREOQV80=
|
||||
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
|
||||
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
|
||||
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
|
||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e h1:4qufH0hlUYs6AO6XmZC3GqfDPGSXHVXUFR6OND+iJX4=
|
||||
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
|
||||
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
|
||||
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
|
||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
|
||||
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
352
main.go
352
main.go
@@ -2,26 +2,352 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/strutil"
|
||||
"github.com/golang-cz/devslog"
|
||||
"github.com/gotify/go-api-client/v2/models"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/sethvargo/go-githubactions"
|
||||
"github.com/spf13/cast"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
logger *slog.Logger
|
||||
)
|
||||
|
||||
func init() {
|
||||
slogOpts := &slog.HandlerOptions{
|
||||
AddSource: false,
|
||||
Level: slog.LevelDebug,
|
||||
}
|
||||
|
||||
opts := &devslog.Options{
|
||||
HandlerOptions: slogOpts,
|
||||
MaxSlicePrintSize: 5,
|
||||
SortKeys: true,
|
||||
TimeFormat: "[15:04:05]",
|
||||
StringerFormatter: true,
|
||||
}
|
||||
logger = slog.New(devslog.NewHandler(os.Stdout, opts))
|
||||
|
||||
//slog.SetDefault(logger)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
ctx, err := githubactions.Context()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := doPush(); err != nil {
|
||||
logger.Error("推送失败", slog.Any("err", err))
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
body, err := json.Marshal(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("context: %s\n", string(body))
|
||||
|
||||
username := githubactions.GetInput("username")
|
||||
fmt.Printf("username is %s\n", username)
|
||||
logger.Info("推送成功")
|
||||
|
||||
githubactions.SetOutput("time", time.Now().Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
func doPush() error {
|
||||
|
||||
ctx, err := githubactions.Context()
|
||||
if err != nil {
|
||||
logger.Error("获取上下文失败", slog.Any("err", err))
|
||||
return err
|
||||
}
|
||||
|
||||
priority := githubactions.GetInput("priority")
|
||||
title := githubactions.GetInput("title")
|
||||
token := githubactions.GetInput("token")
|
||||
contentType := githubactions.GetInput("contentType")
|
||||
clickUrl := githubactions.GetInput("clickUrl")
|
||||
bigImageUrl := githubactions.GetInput("bigImageUrl")
|
||||
msgText := githubactions.GetInput("msgText")
|
||||
stringURL := githubactions.GetInput("url")
|
||||
|
||||
msgText += "\n\n" + getExtraMsg(ctx)
|
||||
|
||||
msg := &models.MessageExternal{
|
||||
Message: msgText,
|
||||
Title: title,
|
||||
Priority: cast.ToInt(priority),
|
||||
}
|
||||
|
||||
msg.Extras = map[string]interface{}{}
|
||||
|
||||
if contentType != "" {
|
||||
msg.Extras["client::display"] = map[string]interface{}{
|
||||
"contentType": contentType,
|
||||
}
|
||||
}
|
||||
|
||||
clientNotification := map[string]interface{}{}
|
||||
if clickUrl != "" {
|
||||
clientNotification["click"] = map[string]string{"url": clickUrl}
|
||||
}
|
||||
if bigImageUrl != "" {
|
||||
clientNotification["bigImageUrl"] = bigImageUrl
|
||||
}
|
||||
if len(clientNotification) > 0 {
|
||||
msg.Extras["client::notification"] = clientNotification
|
||||
}
|
||||
|
||||
parsedURL, err := url.Parse(stringURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return pushMessage(parsedURL, token, msg)
|
||||
}
|
||||
|
||||
func pushMessage(parsedURL *url.URL, token string, msg *models.MessageExternal) error {
|
||||
|
||||
res, err := req.R().
|
||||
SetBodyJsonMarshal(msg).
|
||||
SetQueryParam("token", token).
|
||||
Post(parsedURL.String() + "/message")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var body string
|
||||
if body, err = res.ToString(); err != nil {
|
||||
slog.Error("解析结果失败", slog.Any("err", err))
|
||||
return err
|
||||
}
|
||||
slog.Info("推送结果", slog.String("result", body))
|
||||
|
||||
if res.GetStatusCode() != http.StatusOK {
|
||||
return errors.New(body)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
//client := gotify.NewClient(parsedURL, &http.Client{})
|
||||
//
|
||||
//params := message.NewCreateMessageParams()
|
||||
//params.SetBody(msg)
|
||||
//res, err := client.Message.CreateMessage(params, auth.TokenAuth(token))
|
||||
//if err == nil {
|
||||
// logger.Info("推送结果", slog.Any("result", res))
|
||||
// return nil
|
||||
//} else {
|
||||
// return err
|
||||
//}
|
||||
}
|
||||
|
||||
func getExtraMsg(ctx *githubactions.GitHubContext) (result string) {
|
||||
body, err := os.ReadFile(ctx.EventPath)
|
||||
if err != nil {
|
||||
logger.Error("读取文件失败", slog.Any("err", err), slog.String("path", ctx.EventPath))
|
||||
return
|
||||
}
|
||||
event := new(Event)
|
||||
if err = json.Unmarshal(body, &event); err != nil {
|
||||
logger.Error("解析json失败", slog.Any("err", err), slog.String("path", ctx.EventPath), slog.String("body", string(body)))
|
||||
return
|
||||
}
|
||||
|
||||
result = "**更新内容:**\n%s\n\n[查看更新](%s)\t[查看Action](%s)"
|
||||
|
||||
var commits []string
|
||||
for _, v := range event.Commits {
|
||||
commits = append(commits, fmt.Sprintf("- %s [%s](%s)", v.Message, strutil.Substring(v.Id, 0, 6), v.Url))
|
||||
}
|
||||
|
||||
action := fmt.Sprintf("%s/%s/actions/runs/%d", ctx.ServerURL, ctx.Repository, ctx.RunNumber)
|
||||
result = fmt.Sprintf(result, strings.Join(commits, "\n"), event.CompareUrl, action)
|
||||
return
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
After string `json:"after"`
|
||||
Before string `json:"before"`
|
||||
Commits []struct {
|
||||
Added []interface{} `json:"added"`
|
||||
Author struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
} `json:"author"`
|
||||
Committer struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
} `json:"committer"`
|
||||
Id string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Modified []string `json:"modified"`
|
||||
Removed []interface{} `json:"removed"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Url string `json:"url"`
|
||||
Verification interface{} `json:"verification"`
|
||||
} `json:"commits"`
|
||||
CompareUrl string `json:"compare_url"`
|
||||
HeadCommit struct {
|
||||
Added []interface{} `json:"added"`
|
||||
Author struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
} `json:"author"`
|
||||
Committer struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
} `json:"committer"`
|
||||
Id string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Modified []string `json:"modified"`
|
||||
Removed []interface{} `json:"removed"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Url string `json:"url"`
|
||||
Verification interface{} `json:"verification"`
|
||||
} `json:"head_commit"`
|
||||
Pusher struct {
|
||||
Active bool `json:"active"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
Created time.Time `json:"created"`
|
||||
Description string `json:"description"`
|
||||
Email string `json:"email"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
FollowingCount int `json:"following_count"`
|
||||
FullName string `json:"full_name"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Id int `json:"id"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
Language string `json:"language"`
|
||||
LastLogin time.Time `json:"last_login"`
|
||||
Location string `json:"location"`
|
||||
Login string `json:"login"`
|
||||
LoginName string `json:"login_name"`
|
||||
ProhibitLogin bool `json:"prohibit_login"`
|
||||
Restricted bool `json:"restricted"`
|
||||
SourceId int `json:"source_id"`
|
||||
StarredReposCount int `json:"starred_repos_count"`
|
||||
Username string `json:"username"`
|
||||
Visibility string `json:"visibility"`
|
||||
Website string `json:"website"`
|
||||
} `json:"pusher"`
|
||||
Ref string `json:"ref"`
|
||||
Repository struct {
|
||||
AllowFastForwardOnlyMerge bool `json:"allow_fast_forward_only_merge"`
|
||||
AllowMergeCommits bool `json:"allow_merge_commits"`
|
||||
AllowRebase bool `json:"allow_rebase"`
|
||||
AllowRebaseExplicit bool `json:"allow_rebase_explicit"`
|
||||
AllowRebaseUpdate bool `json:"allow_rebase_update"`
|
||||
AllowSquashMerge bool `json:"allow_squash_merge"`
|
||||
Archived bool `json:"archived"`
|
||||
ArchivedAt time.Time `json:"archived_at"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
CloneUrl string `json:"clone_url"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
|
||||
DefaultMergeStyle string `json:"default_merge_style"`
|
||||
Description string `json:"description"`
|
||||
Empty bool `json:"empty"`
|
||||
Fork bool `json:"fork"`
|
||||
ForksCount int `json:"forks_count"`
|
||||
FullName string `json:"full_name"`
|
||||
HasActions bool `json:"has_actions"`
|
||||
HasIssues bool `json:"has_issues"`
|
||||
HasPackages bool `json:"has_packages"`
|
||||
HasProjects bool `json:"has_projects"`
|
||||
HasPullRequests bool `json:"has_pull_requests"`
|
||||
HasReleases bool `json:"has_releases"`
|
||||
HasWiki bool `json:"has_wiki"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Id int `json:"id"`
|
||||
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
|
||||
Internal bool `json:"internal"`
|
||||
InternalTracker struct {
|
||||
AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"`
|
||||
EnableIssueDependencies bool `json:"enable_issue_dependencies"`
|
||||
EnableTimeTracker bool `json:"enable_time_tracker"`
|
||||
} `json:"internal_tracker"`
|
||||
Language string `json:"language"`
|
||||
LanguagesUrl string `json:"languages_url"`
|
||||
Link string `json:"link"`
|
||||
Mirror bool `json:"mirror"`
|
||||
MirrorInterval string `json:"mirror_interval"`
|
||||
MirrorUpdated time.Time `json:"mirror_updated"`
|
||||
Name string `json:"name"`
|
||||
ObjectFormatName string `json:"object_format_name"`
|
||||
OpenIssuesCount int `json:"open_issues_count"`
|
||||
OpenPrCounter int `json:"open_pr_counter"`
|
||||
OriginalUrl string `json:"original_url"`
|
||||
Owner struct {
|
||||
Active bool `json:"active"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
Created time.Time `json:"created"`
|
||||
Description string `json:"description"`
|
||||
Email string `json:"email"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
FollowingCount int `json:"following_count"`
|
||||
FullName string `json:"full_name"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Id int `json:"id"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
Language string `json:"language"`
|
||||
LastLogin time.Time `json:"last_login"`
|
||||
Location string `json:"location"`
|
||||
Login string `json:"login"`
|
||||
LoginName string `json:"login_name"`
|
||||
ProhibitLogin bool `json:"prohibit_login"`
|
||||
Restricted bool `json:"restricted"`
|
||||
SourceId int `json:"source_id"`
|
||||
StarredReposCount int `json:"starred_repos_count"`
|
||||
Username string `json:"username"`
|
||||
Visibility string `json:"visibility"`
|
||||
Website string `json:"website"`
|
||||
} `json:"owner"`
|
||||
Parent interface{} `json:"parent"`
|
||||
Permissions struct {
|
||||
Admin bool `json:"admin"`
|
||||
Pull bool `json:"pull"`
|
||||
Push bool `json:"push"`
|
||||
} `json:"permissions"`
|
||||
Private bool `json:"private"`
|
||||
ProjectsMode string `json:"projects_mode"`
|
||||
ReleaseCounter int `json:"release_counter"`
|
||||
RepoTransfer interface{} `json:"repo_transfer"`
|
||||
Size int `json:"size"`
|
||||
SshUrl string `json:"ssh_url"`
|
||||
StarsCount int `json:"stars_count"`
|
||||
Template bool `json:"template"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Url string `json:"url"`
|
||||
WatchersCount int `json:"watchers_count"`
|
||||
Website string `json:"website"`
|
||||
} `json:"repository"`
|
||||
Sender struct {
|
||||
Active bool `json:"active"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
Created time.Time `json:"created"`
|
||||
Description string `json:"description"`
|
||||
Email string `json:"email"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
FollowingCount int `json:"following_count"`
|
||||
FullName string `json:"full_name"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Id int `json:"id"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
Language string `json:"language"`
|
||||
LastLogin time.Time `json:"last_login"`
|
||||
Location string `json:"location"`
|
||||
Login string `json:"login"`
|
||||
LoginName string `json:"login_name"`
|
||||
ProhibitLogin bool `json:"prohibit_login"`
|
||||
Restricted bool `json:"restricted"`
|
||||
SourceId int `json:"source_id"`
|
||||
StarredReposCount int `json:"starred_repos_count"`
|
||||
Username string `json:"username"`
|
||||
Visibility string `json:"visibility"`
|
||||
Website string `json:"website"`
|
||||
} `json:"sender"`
|
||||
TotalCommits int `json:"total_commits"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user