335 lines
13 KiB
Go
335 lines
13 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/gotify/go-api-client/v2/auth"
|
|
"github.com/gotify/go-api-client/v2/client/message"
|
|
"github.com/gotify/go-api-client/v2/gotify"
|
|
"github.com/gotify/go-api-client/v2/models"
|
|
"github.com/sethvargo/go-githubactions"
|
|
"github.com/spf13/cast"
|
|
"io/fs"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
//doPush()
|
|
//return
|
|
|
|
ctx, err := githubactions.Context()
|
|
if err != nil {
|
|
panic(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)
|
|
|
|
dir, _ := os.Getwd()
|
|
root := filepath.Join(dir, "../")
|
|
filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
|
if d.IsDir() {
|
|
if d.Name() == ".git" {
|
|
return filepath.SkipDir
|
|
}
|
|
return nil
|
|
}
|
|
body, _ = os.ReadFile(path)
|
|
fmt.Printf("path: %s\n%s\n\n", path, string(body))
|
|
return nil
|
|
})
|
|
|
|
githubactions.SetOutput("time", time.Now().Format("2006-01-02 15:04:05"))
|
|
}
|
|
|
|
func doPush() {
|
|
|
|
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")
|
|
|
|
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 {
|
|
panic(err)
|
|
}
|
|
|
|
pushMessage(parsedURL, token, msg)
|
|
}
|
|
|
|
func pushMessage(parsedURL *url.URL, token string, msg *models.MessageExternal) {
|
|
|
|
client := gotify.NewClient(parsedURL, &http.Client{})
|
|
|
|
params := message.NewCreateMessageParams()
|
|
params.SetBody(msg)
|
|
res, err := client.Message.CreateMessage(params, auth.TokenAuth(token))
|
|
if err == nil {
|
|
// todo成功
|
|
response, _ := json.Marshal(res)
|
|
fmt.Println(string(response))
|
|
} else {
|
|
panic(err)
|
|
// todo 错误处理
|
|
}
|
|
}
|
|
|
|
type GithubEnv struct {
|
|
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"`
|
|
} `json:"event"`
|
|
EventPath string `json:"event_path"`
|
|
Workflow string `json:"workflow"`
|
|
RunId string `json:"run_id"`
|
|
RunNumber string `json:"run_number"`
|
|
Actor string `json:"actor"`
|
|
Repository string `json:"repository"`
|
|
EventName string `json:"event_name"`
|
|
Sha string `json:"sha"`
|
|
Ref string `json:"ref"`
|
|
RefName string `json:"ref_name"`
|
|
RefType string `json:"ref_type"`
|
|
HeadRef string `json:"head_ref"`
|
|
BaseRef string `json:"base_ref"`
|
|
Token string `json:"token"`
|
|
Workspace string `json:"workspace"`
|
|
Action string `json:"action"`
|
|
ActionPath string `json:"action_path"`
|
|
ActionRef string `json:"action_ref"`
|
|
ActionRepository string `json:"action_repository"`
|
|
Job string `json:"job"`
|
|
JobName string `json:"job_name"`
|
|
RepositoryOwner string `json:"repository_owner"`
|
|
RetentionDays string `json:"retention_days"`
|
|
RunnerPerflog string `json:"runner_perflog"`
|
|
RunnerTrackingId string `json:"runner_tracking_id"`
|
|
ServerUrl string `json:"server_url"`
|
|
ApiUrl string `json:"api_url"`
|
|
GraphqlUrl string `json:"graphql_url"`
|
|
}
|