Skip to content

Commit

Permalink
feature(main): add pr comment (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu authored Jun 27, 2023
1 parent fd17418 commit 81f152a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ message:
> 该功能v0.0.6 支持
- `SEALOS_TYPE: "pr_comment"` # PR文本替换回复
- `SEALOS_FILENAME: "README.md"` # PR文本替换回复文件位置
- `SEALOS_COMMENT: "/xxxx"` # comment的内容
- `SEALOS_REPLACE_TAG: "TAG"` # 寻找标记,根据这个标记进行替换

- [x] issue创建comment
Expand Down
19 changes: 12 additions & 7 deletions pkg/action/action_pr_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (

// PRComment is a action to comment on PR
func PRComment() error {
fileName, err := GetEnvFromAction("filename")
if err != nil {
return err
fileName, _ := GetEnvFromAction("filename")
commentBody, _ := GetEnvFromAction("comment")
if fileName == "" && commentBody == "" {
return fmt.Errorf("filename or comment is empty")
}
replaceTag, err := GetEnvFromAction("replace_tag")
if err != nil {
Expand All @@ -43,10 +44,14 @@ func PRComment() error {
return err
}

fileContent, err := os.ReadFile(fileName)
if err != nil {
return err
if fileName != "" {
fileContent, err := os.ReadFile(fileName)
if err != nil {
return err
}
commentBody = string(fileContent)
}

owner, repo, err := getRepo("")
if err != nil {
return err
Expand All @@ -59,7 +64,7 @@ func PRComment() error {
return fmt.Errorf("Issues.ListComments returned error: %v", err)
}
hiddenReplace := fmt.Sprintf("<!-- %s -->", replaceTag)
content := string(fileContent) + "\n" + hiddenReplace
content := commentBody + "\n" + hiddenReplace

// Checks existing comments, edits if match found
for _, comment := range comments {
Expand Down

0 comments on commit 81f152a

Please sign in to comment.