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

Minimize latest plan preview comment before comment error message #4683

Merged
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
29 changes: 7 additions & 22 deletions tool/actions-plan-preview/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,36 +141,21 @@ func main() {
doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request.")
return
}

minimizePreviousComment(ctx, ghGraphQLClient, event)

body := makeCommentBody(event, result)
doComment(failureBadgeURL + "\n" + body)
doComment(body)

log.Println("Successfully minimized last plan-preview result on pull request")
log.Println("plan-preview result has error")
os.Exit(1)
}

// Find comments we sent before
comment, err := findLatestPlanPreviewComment(ctx, ghGraphQLClient, event.Owner, event.Repo, event.PRNumber)
if err != nil {
log.Printf("Unable to find the previous comment to minimize (%v)\n", err)
}
minimizePreviousComment(ctx, ghGraphQLClient, event)

body := makeCommentBody(event, result)
doComment(body)

if comment == nil {
return
}

if bool(comment.IsMinimized) {
log.Printf("Previous plan-preview comment has already minimized. So don't minimize anything\n")
return
}

if err := minimizeComment(ctx, ghGraphQLClient, comment.ID, "OUTDATED"); err != nil {
log.Printf("warning: cannot minimize comment: %s\n", err.Error())
return
}

log.Printf("Successfully minimized last plan-preview result on pull request\n")
}

type arguments struct {
Expand Down
25 changes: 25 additions & 0 deletions tool/actions-plan-preview/planpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/shurcooL/githubv4"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -331,3 +332,27 @@ func generateTerraformShortPlanDetails(details string) (string, error) {
}
return details[start:], nil
}

func minimizePreviousComment(ctx context.Context, ghGraphQLClient *githubv4.Client, event *githubEvent) {
// Find comments we sent before
comment, err := findLatestPlanPreviewComment(ctx, ghGraphQLClient, event.Owner, event.Repo, event.PRNumber)
if err != nil {
log.Printf("Unable to find the previous comment to minimize (%v)\n", err)
}

if comment == nil {
return
}

if bool(comment.IsMinimized) {
log.Println("Previous plan-preview comment has already minimized. So don't minimize anything")
return
}

if err := minimizeComment(ctx, ghGraphQLClient, comment.ID, "OUTDATED"); err != nil {
log.Printf("warning: cannot minimize comment: %s\n", err.Error())
return
}

log.Println("Successfully minimized last plan-preview result on pull request")
}
Loading