From 897634289d39290a50153e4961df3eaffd791c0b Mon Sep 17 00:00:00 2001 From: Elsabe Ros Date: Wed, 28 Feb 2024 13:14:41 +0200 Subject: [PATCH] Added a BodyFile param for very large comments. Removed nil checks. Handle error. Fixed file read. Null by default. Small formatting fix. --- main.go | 22 +++++++++++++++++++--- step.yml | 8 ++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 424cb97..6fb12b4 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,8 @@ import ( type Config struct { AuthToken stepconf.Secret `env:"personal_access_token,required"` - Body string `env:"body,required"` + Body string `env:"body"` + BodyFile string `env:"body_file"` RepositoryURL string `env:"repository_url,required"` IssueNumber int `env:"issue_number,required"` APIBaseURL string `env:"api_base_url,required"` @@ -38,8 +39,23 @@ func main() { } stepconf.Print(conf) + if conf.Body == "" && conf.BodyFile == "" { + log.Errorf("Body or BodyFile is required!") + os.Exit(1) + } + + rawComment := conf.Body + if conf.BodyFile != "" { + bytes, err := os.ReadFile(conf.BodyFile) + if err != nil { + log.Errorf("Error: %s\n", err) + os.Exit(1) + } + rawComment = string(bytes) + } + owner, repo := ownerAndRepo(conf.RepositoryURL) - commentBody := conf.Body + commentBody := rawComment var githubClient *github.GithubClient @@ -51,7 +67,7 @@ func main() { // if tag is set, try to find and update existing comment if conf.UpdateCommentTag != "" { - commentBody = fmt.Sprintf("%s\n\n%s", conf.Body, decoratedTag(conf.UpdateCommentTag)) + commentBody = fmt.Sprintf("%s\n\n%s", rawComment, decoratedTag(conf.UpdateCommentTag)) taggedComment, err := githubClient.GetFirstCommentWithTag(owner, repo, conf.IssueNumber, decoratedTag(conf.UpdateCommentTag)) if err == nil { // comment with the given tag found diff --git a/step.yml b/step.yml index 2d8fdba..911f31b 100644 --- a/step.yml +++ b/step.yml @@ -43,12 +43,16 @@ inputs: Add repo(Full control of private repositories) scope to the generated token, to allow to comment on GitHub Pull Request or Issue. is_required: true is_sensitive: true - - body: + - body: null opts: title: "Body" description: | Text of the message to send. - is_required: true + - body_file: null + opts: + title: "File with body contents" + description: | + Path to a file containing the message to send - repository_url: "$GIT_REPOSITORY_URL" opts: title: "Repository URL"