Skip to content

Commit

Permalink
fix: when comamnd is /retest, start action
Browse files Browse the repository at this point in the history
Signed-off-by: yuluo-yx <[email protected]>
  • Loading branch information
yuluo-yx committed Apr 26, 2024
1 parent e941a94 commit 83ecd09
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
3 changes: 0 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ inputs:
description: >-
URL to fetch PR information
required: true
args:
description: >-
Args passed to command (not currently used)

runs:
using: 'docker'
Expand Down
51 changes: 43 additions & 8 deletions retest/retest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ var (
githubClient = github.NewClient()
)

const (
Retest = "/retest"
)

func InitRetestCommands() *Runtime {

commentInput, _ := core.GetInput("comment-id")
comment, _ := strconv.Atoi(commentInput)
CommentId, _ := strconv.Atoi(commentInput)
pr, _ := core.GetInput("pr-url")
nwo := os.Getenv("GITHUB_REPOSITORY")
debug := os.Getenv("CI_DEBUG") != "" && os.Getenv("CI_DEBUG") != "false"
Expand All @@ -35,12 +39,12 @@ func InitRetestCommands() *Runtime {
}

return &Runtime{
Pr: pr,
Comment: comment,
Repo: repo,
Nwo: nwo,
Owner: owner,
Debug: debug,
Pr: pr,
CommentId: int64(CommentId),
Repo: repo,
Nwo: nwo,
Owner: owner,
Debug: debug,
}

}
Expand Down Expand Up @@ -80,13 +84,37 @@ func getPR(rt *Runtime) *PullRequest {

}

func getPRCommentContent(rt *Runtime) bool {

comment, response, err := githubClient.PullRequests.GetComment(
context.Background(),
rt.Owner,
rt.Repo,
rt.CommentId,
)

if response.StatusCode != 200 && response.StatusCode != 201 && err != nil {

log.Fatal("failed to get comment, error: ", err)
return false
}

fmt.Printf("comment content: %v\n", comment.GetBody())
if comment.GetBody() == Retest {

return true
}

return false
}

func addReaction(rt *Runtime, content string) bool {

_, response, err := githubClient.Reactions.CreateIssueCommentReaction(
context.Background(),
rt.Owner,
rt.Repo,
int64(rt.Comment),
rt.CommentId,
content,
)

Expand Down Expand Up @@ -172,6 +200,13 @@ func rerunJobs(rt *Runtime, failedJobs []*GHRetest) (result *GHRetestResult) {
func retest() {

rt := InitRetestCommands()

if !getPRCommentContent(rt) {

log.Println("no retest command found")
return
}

pr := getPR(rt)
failedJosList := getFailedJos(rt, pr)

Expand Down
12 changes: 6 additions & 6 deletions retest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ type GHRetest struct {
}

type Runtime struct {
Comment int
Debug bool
Pr string
Nwo string
Owner string
Repo string
CommentId int64
Debug bool
Pr string
Nwo string
Owner string
Repo string
}

type GHRetestResult struct {
Expand Down

0 comments on commit 83ecd09

Please sign in to comment.