diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae6e9a1..710f44e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,6 +91,7 @@ jobs: run: | npx \ -p semantic-release \ + -p semantic-release-replace-plugin \ -p @semantic-release/commit-analyzer \ -p @semantic-release/release-notes-generator \ -p @semantic-release/changelog \ diff --git a/.releaserc.json b/.releaserc.json index 2f60e7a..8310b91 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -68,6 +68,11 @@ ], "@semantic-release/release-notes-generator", "@semantic-release/changelog", - "@semantic-release/git" + [ + "@semantic-release/git", + { + "assets": ["CHANGELOG.md", "README.md", "action.yml", ".github/workflows/example.yml", ".github/workflows/release.yml"] + } + ] ] } diff --git a/main.go b/main.go index 12cb578..b8674a8 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ import ( "bytes" _ "embed" "fmt" + "io" + "log" "net/http" "os" "text/template" @@ -42,6 +44,65 @@ func main() { data.CardID = uuid.NewString() data.Add = "" + getData(&data) + + webhook := githubactions.GetInput("webhook") + if webhook == "" { + githubactions.Fatalf("Missing input 'webhook'") + os.Exit(1) + } + webhook = fmt.Sprintf("%s&threadKey=notify%s&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD", webhook, data.ActionID) + + giturl := githubactions.GetInput("giturl") + if giturl == "" { + githubactions.Fatalf("Missing input 'giturl'") + os.Exit(1) + } + data.GitURL = giturl + + body := githubactions.GetInput("event_body") + data.EventBody = body + + githubactions.Infof("using URL: %s", webhook) + // fmt.Println("URL:> ", webhook) + + // var jsonStr = []byte(fmt.Sprintf(data, project, commit, branch, status, actionid)) + + jsonStr, err := card(data) + if err != nil { + githubactions.Fatalf("err %s", err.Error()) + os.Exit(1) + } + + // log.Printf("retrieved data: %s", string(jsonStr)) + + req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr)) + if err != nil { + githubactions.Fatalf("error %s", err.Error()) + os.Exit(1) + } + req.Header.Set("Content-Type", "application/json; charset=UTF-8") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + githubactions.Fatalf("error %s", err.Error()) + os.Exit(1) + } + defer func(Body io.ReadCloser) { + err := Body.Close() + if err != nil { + log.Fatalln(err) + } + }(resp.Body) + fmt.Println("response Status:", resp.Status) + if resp.StatusCode != http.StatusOK { + githubactions.Infof("json: %s", jsonStr) + githubactions.Fatalf("response: %+v\n", resp) + os.Exit(1) + } +} + +func getData(data *templateData) { prj, ok := os.LookupEnv("FORGEJO_REPOSITORY") if ok { data.Project = prj @@ -84,56 +145,6 @@ func main() { os.Exit(1) } data.ActionID = actionid - - webhook := githubactions.GetInput("webhook") - if webhook == "" { - githubactions.Fatalf("Missing input 'webhook'") - os.Exit(1) - } - webhook = fmt.Sprintf("%s&threadKey=notify%s&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD", webhook, data.ActionID) - - giturl := githubactions.GetInput("giturl") - if giturl == "" { - githubactions.Fatalf("Missing input 'giturl'") - os.Exit(1) - } - data.GitURL = giturl - - body := githubactions.GetInput("event_body") - data.EventBody = body - - githubactions.Infof("using URL: %s", webhook) - // fmt.Println("URL:> ", webhook) - - // var jsonStr = []byte(fmt.Sprintf(data, project, commit, branch, status, actionid)) - - jsonStr, err := card(data) - if err != nil { - githubactions.Fatalf("error %s", err.Error()) - os.Exit(1) - } - - // log.Printf("retrieved data: %s", string(jsonStr)) - - req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr)) - if err != nil { - githubactions.Fatalf("error %s", err.Error()) - os.Exit(1) - } - req.Header.Set("Content-Type", "application/json; charset=UTF-8") - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - githubactions.Fatalf("error %s", err.Error()) - os.Exit(1) - } - defer resp.Body.Close() - fmt.Println("response Status:", resp.Status) - if resp.StatusCode != http.StatusOK { - githubactions.Infof("json: %s", jsonStr) - githubactions.Fatalf("response: %+v\n", resp) - os.Exit(1) - } } func card(d templateData) ([]byte, error) {