diff --git a/.github/workflows/test-issue-renew.yml b/.github/workflows/test-issue-renew.yml index a09d2f7..5c1d264 100644 --- a/.github/workflows/test-issue-renew.yml +++ b/.github/workflows/test-issue-renew.yml @@ -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 }}" diff --git a/README.md b/README.md index a09b4be..7372f97 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ message: - `SEALOS_ISREPLY: "true"` # 是否回复,根据当前的comment的内容追加 - [x] issue自动创建 - > 该功能v0.0.7支持 + > 该功能v0.0.8-rc1支持 入参: @@ -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内容如果多可以写文件 返回参数: diff --git a/pkg/action/action_issue_renew.go b/pkg/action/action_issue_renew.go index 31a23c0..057f662 100644 --- a/pkg/action/action_issue_renew.go +++ b/pkg/action/action_issue_renew.go @@ -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 @@ -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 { @@ -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" @@ -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()) }