Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down