From 098f349f64da0c0ca5985b17a0e26d7675ff6e6c Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Tue, 20 Jun 2023 19:38:04 +0800 Subject: [PATCH] Repo support (#38) * feature(main): add issue_renew action for action repo_support Signed-off-by: cuisongliu * feature(main): add issue_renew action for action repo_support Signed-off-by: cuisongliu --------- Signed-off-by: cuisongliu --- .github/workflows/test-issue-renew.yml | 1 + README.md | 2 +- pkg/action/action.go | 9 ++++++++- pkg/action/action_comment_reply.go | 2 +- pkg/action/action_issue_renew.go | 3 ++- pkg/action/action_pr_comment.go | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-issue-renew.yml b/.github/workflows/test-issue-renew.yml index fa8f452..a09d2f7 100644 --- a/.github/workflows/test-issue-renew.yml +++ b/.github/workflows/test-issue-renew.yml @@ -25,6 +25,7 @@ jobs: SEALOS_ISSUE_BODYFILE: "README.md" SEALOS_ISSUE_LABEL: "dayly-report" SEALOS_ISSUE_TYPE: "day" + SEALOS_ISSUE_REPO: "labring/gh-rebot" GH_TOKEN: "${{ secrets.GH_PAT }}" - run: | echo "output is ${{ env.SEALOS_ISSUE_NUMBER }}" diff --git a/README.md b/README.md index 49e703a..a09b4be 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ message: - `SEALOS_ISREPLY: "true"` # 是否回复,根据当前的comment的内容追加 - [x] issue自动创建 - > 该功能v0.0.7-rc3支持 + > 该功能v0.0.7支持 入参: diff --git a/pkg/action/action.go b/pkg/action/action.go index bcc1d43..5f017d3 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -61,7 +61,14 @@ func GetEnvFromAction(key string) (string, error) { return val, nil } -func getRepo() (string, string, error) { +func getRepo(r string) (string, string, error) { + if r != "" { + split := strings.Split(r, "/") + if len(split) != 2 { + return "", "", fmt.Errorf("repo format error") + } + return split[0], split[1], nil + } repo := os.Getenv("GITHUB_REPOSITORY") // 获取环境变量GITHUB_REF if repo == "" { return "", "", fmt.Errorf("not found GITHUB_REPOSITORY") diff --git a/pkg/action/action_comment_reply.go b/pkg/action/action_comment_reply.go index cdffea6..6806d7c 100644 --- a/pkg/action/action_comment_reply.go +++ b/pkg/action/action_comment_reply.go @@ -52,7 +52,7 @@ func CommentReply() error { comment = strings.Join([]string{replyBody, comment}, "\r\n\r\n") } - owner, repo, err := getRepo() + owner, repo, err := getRepo("") if err != nil { return err } diff --git a/pkg/action/action_issue_renew.go b/pkg/action/action_issue_renew.go index 37cc599..31a23c0 100644 --- a/pkg/action/action_issue_renew.go +++ b/pkg/action/action_issue_renew.go @@ -58,8 +58,9 @@ func IssueRenew() error { default: issueTitle = issueTitle + " " + utils.FormatDay(time.Now()) } + issueRepo, _ := GetEnvFromAction("issue_repo") - owner, repo, err := getRepo() + owner, repo, err := getRepo(issueRepo) if err != nil { return err } diff --git a/pkg/action/action_pr_comment.go b/pkg/action/action_pr_comment.go index 8f01036..fba4736 100644 --- a/pkg/action/action_pr_comment.go +++ b/pkg/action/action_pr_comment.go @@ -47,7 +47,7 @@ func PRComment() error { if err != nil { return err } - owner, repo, err := getRepo() + owner, repo, err := getRepo("") if err != nil { return err }