Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when comamnd is /retest, start action #8

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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