From bf9e14d2c9f161d9f3f6b8250b4b6b83fb001326 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Fri, 24 Jun 2022 16:36:16 +0530 Subject: [PATCH] ci: retest only one pr at a time & rebase if necessary This commit improves retest action by rebasing the pr if it behind devel branch and adding retests to only one pr at a time. refer: https://docs.github.com/en/graphql/reference/enums#mergestatestatus Signed-off-by: Rakshith R --- actions/retest/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/actions/retest/main.go b/actions/retest/main.go index f019f333f..075cea7e3 100644 --- a/actions/retest/main.go +++ b/actions/retest/main.go @@ -147,6 +147,19 @@ func main() { log.Printf("found context %s with status %s\n", r.GetContext(), r.GetState()) if contains([]string{"failed", "failure"}, r.GetState()) { log.Printf("found failed test %s\n", r.GetContext()) + failedTestFound = true + // rebase the pr if it is behind the devel branch. + if *re.MergeableState == "BEHIND" { + comment := &github.IssueComment{ + Body: github.String("@mergifyio rebase"), + } + _, _, err := c.client.Issues.CreateComment(context.TODO(), c.owner, c.repo, prNumber, comment) + if err != nil { + log.Printf("failed to create comment %v\n", err) + } + break + } + // check if retest limit is reached msg := fmt.Sprintf("/retest %s", r.GetContext()) ok, err := c.checkRetestLimitReached(prNumber, msg) @@ -175,7 +188,6 @@ func main() { log.Printf("failed to create comment %v\n", err) continue } - failedTestFound = true } } @@ -188,8 +200,10 @@ func main() { _, _, err = c.client.Issues.CreateComment(context.TODO(), c.owner, c.repo, prNumber, comment) if err != nil { log.Printf("failed to create comment %q: %v\n", msg, err) - continue } + // exit after adding retests to a pr once to avoid retesting multiple prs + // at the same time. + break } } }