ci: prevent panic in retest action on nil strings

In case a PullRequest does not have a MergeableState set, it will be
`nil`. Dereferencing the pointer will cause a Go panic, and the action
won't work as intended.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2022-06-27 10:14:58 +02:00 committed by mergify[bot]
parent bf9e14d2c9
commit 34ff13984a

View File

@ -116,7 +116,7 @@ func main() {
log.Fatalf("failed to list pull requests %v\n", err) log.Fatalf("failed to list pull requests %v\n", err)
} }
for _, re := range req { for _, re := range req {
if *re.State == "open" { if (re.State != nil) && (*re.State == "open") {
prNumber := re.GetNumber() prNumber := re.GetNumber()
log.Printf("PR with ID %d with Title %q is open\n", prNumber, re.GetTitle()) log.Printf("PR with ID %d with Title %q is open\n", prNumber, re.GetTitle())
for _, l := range re.Labels { for _, l := range re.Labels {
@ -149,7 +149,7 @@ func main() {
log.Printf("found failed test %s\n", r.GetContext()) log.Printf("found failed test %s\n", r.GetContext())
failedTestFound = true failedTestFound = true
// rebase the pr if it is behind the devel branch. // rebase the pr if it is behind the devel branch.
if *re.MergeableState == "BEHIND" { if (re.MergeableState != nil) && (*re.MergeableState == "BEHIND") {
comment := &github.IssueComment{ comment := &github.IssueComment{
Body: github.String("@mergifyio rebase"), Body: github.String("@mergifyio rebase"),
} }