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

Commit 20adbc5

Browse files
authored
feature(main): add issue auto comment (#39)
Signed-off-by: cuisongliu <cuisongliu@qq.com>
1 parent 098f349 commit 20adbc5

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

.github/workflows/test-issue-renew.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
SEALOS_ISSUE_LABEL: "dayly-report"
2727
SEALOS_ISSUE_TYPE: "day"
2828
SEALOS_ISSUE_REPO: "labring/gh-rebot"
29+
SEALOS_COMMENT_BODY: "FFFFFFF_TEST"
2930
GH_TOKEN: "${{ secrets.GH_PAT }}"
3031
- run: |
3132
echo "output is ${{ env.SEALOS_ISSUE_NUMBER }}"

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ message:
138138
- `SEALOS_ISREPLY: "true"` # 是否回复,根据当前的comment的内容追加
139139

140140
- [x] issue自动创建
141-
> 该功能v0.0.7支持
141+
> 该功能v0.0.8-rc1支持
142142
143143
入参:
144144

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

152155
返回参数:
153156

pkg/action/action_issue_renew.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func IssueRenew() error {
6060
}
6161
issueRepo, _ := GetEnvFromAction("issue_repo")
6262

63+
comment, _ := GetEnvFromAction("comment_body")
64+
commentfile, _ := GetEnvFromAction("comment_bodyfile")
65+
if commentfile != "" {
66+
bodyBytes, _ := os.ReadFile(commentfile)
67+
comment = string(bodyBytes)
68+
}
69+
6370
owner, repo, err := getRepo(issueRepo)
6471
if err != nil {
6572
return err
@@ -75,10 +82,14 @@ func IssueRenew() error {
7582
return err
7683
}
7784
hasIssue := false
78-
issueNumber := ""
85+
issueNumber := 0
7986
defer func() {
80-
writeGithubEnv("SEALOS_ISSUE_NUMBER", issueNumber)
81-
logger.Info("add env SEALOS_ISSUE_NUMBER: %s", issueNumber)
87+
writeGithubEnv("SEALOS_ISSUE_NUMBER", strconv.Itoa(issueNumber))
88+
logger.Info("add env SEALOS_ISSUE_NUMBER: %s", strconv.Itoa(issueNumber))
89+
if comment != "" && issueNumber != 0 {
90+
githubComment := &github.IssueComment{Body: github.String(comment)}
91+
_, _, err = client.Issues.CreateComment(ctx, owner, repo, issueNumber, githubComment)
92+
}
8293
}()
8394
issueOldTitle, _ := GetEnvFromAction("issue_title")
8495
for _, issue := range issues {
@@ -87,7 +98,7 @@ func IssueRenew() error {
8798
if issue.GetTitle() == issueTitle && issue.GetState() != "closed" {
8899
logger.Info("issue already exist, issue: %s", issue.GetTitle())
89100
hasIssue = true
90-
issueNumber = strconv.Itoa(issue.GetNumber())
101+
issueNumber = issue.GetNumber()
91102
return nil
92103
} else {
93104
state := "closed"
@@ -109,7 +120,7 @@ func IssueRenew() error {
109120
},
110121
}
111122
issue, _, _ := client.Issues.Create(ctx, owner, repo, issueRequest)
112-
issueNumber = strconv.Itoa(issue.GetNumber())
123+
issueNumber = issue.GetNumber()
113124
logger.Info("create issue: %s, number: %d", issueTitle, issue.GetNumber())
114125
}
115126

0 commit comments

Comments
 (0)