Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
feature(main): add issue auto comment (#39)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu authored Jun 20, 2023
1 parent 098f349 commit 20adbc5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-issue-renew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
SEALOS_ISSUE_LABEL: "dayly-report"
SEALOS_ISSUE_TYPE: "day"
SEALOS_ISSUE_REPO: "labring/gh-rebot"
SEALOS_COMMENT_BODY: "FFFFFFF_TEST"
GH_TOKEN: "${{ secrets.GH_PAT }}"
- run: |
echo "output is ${{ env.SEALOS_ISSUE_NUMBER }}"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ message:
- `SEALOS_ISREPLY: "true"` # 是否回复,根据当前的comment的内容追加

- [x] issue自动创建
> 该功能v0.0.7支持
> 该功能v0.0.8-rc1支持

入参:

Expand All @@ -148,6 +148,9 @@ message:
- `SEALOS_ISSUE_BODYFILE: "README.md"` # issue内容如果多可以写文件
- `SEALOS_ISSUE_LABEL: "dayly-report"` # 新增issue的label
- `SEALOS_ISSUE_TYPE: "day"` # day和week , 会在titles上自动加上日期
- `SEALOS_ISSUE_REPO`: "sealos/sealos" # issue创建的仓库
- `SEALOS_COMMENT_BODY`: "xxxx" # issue创建后的comment内容
- `SEALOS_COMMENT_BODYFILE`: "xxxx" # issue创建后的comment内容如果多可以写文件

返回参数:

Expand Down
21 changes: 16 additions & 5 deletions pkg/action/action_issue_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func IssueRenew() error {
}
issueRepo, _ := GetEnvFromAction("issue_repo")

comment, _ := GetEnvFromAction("comment_body")
commentfile, _ := GetEnvFromAction("comment_bodyfile")
if commentfile != "" {
bodyBytes, _ := os.ReadFile(commentfile)
comment = string(bodyBytes)
}

owner, repo, err := getRepo(issueRepo)
if err != nil {
return err
Expand All @@ -75,10 +82,14 @@ func IssueRenew() error {
return err
}
hasIssue := false
issueNumber := ""
issueNumber := 0
defer func() {
writeGithubEnv("SEALOS_ISSUE_NUMBER", issueNumber)
logger.Info("add env SEALOS_ISSUE_NUMBER: %s", issueNumber)
writeGithubEnv("SEALOS_ISSUE_NUMBER", strconv.Itoa(issueNumber))
logger.Info("add env SEALOS_ISSUE_NUMBER: %s", strconv.Itoa(issueNumber))
if comment != "" && issueNumber != 0 {
githubComment := &github.IssueComment{Body: github.String(comment)}
_, _, err = client.Issues.CreateComment(ctx, owner, repo, issueNumber, githubComment)
}
}()
issueOldTitle, _ := GetEnvFromAction("issue_title")
for _, issue := range issues {
Expand All @@ -87,7 +98,7 @@ func IssueRenew() error {
if issue.GetTitle() == issueTitle && issue.GetState() != "closed" {
logger.Info("issue already exist, issue: %s", issue.GetTitle())
hasIssue = true
issueNumber = strconv.Itoa(issue.GetNumber())
issueNumber = issue.GetNumber()
return nil
} else {
state := "closed"
Expand All @@ -109,7 +120,7 @@ func IssueRenew() error {
},
}
issue, _, _ := client.Issues.Create(ctx, owner, repo, issueRequest)
issueNumber = strconv.Itoa(issue.GetNumber())
issueNumber = issue.GetNumber()
logger.Info("create issue: %s, number: %d", issueTitle, issue.GetNumber())
}

Expand Down

0 comments on commit 20adbc5

Please sign in to comment.