From 799e420f8d00ab913d36972f4244f02cdebe7895 Mon Sep 17 00:00:00 2001 From: Tanmay Sardesai Date: Fri, 10 Oct 2025 10:57:47 -0700 Subject: [PATCH] support skiping a push if one a PR already exists helps when some pushes fail from timeouts or internet connectivity --- VERSION | 2 +- cmd/push.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index e85669f..1435d6c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.36 +0.0.37 diff --git a/cmd/push.go b/cmd/push.go index 47ac51e..18a9101 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -21,6 +21,7 @@ var pushFlagThrottle string var pushFlagBodyFile string var pushFlagLabels []string var pushFlagDraft bool +var pushFlagPlannedOnly bool // rate limits the # of git pushes. used to prevent load on CI system var pushThrottle *time.Ticker @@ -29,6 +30,7 @@ var prAssignee string var prBody string var prLabels []string var prDraft bool +var prPlannedOnly bool var pushCmd = &cobra.Command{ Use: "push", @@ -83,6 +85,12 @@ var pushCmd = &cobra.Command{ } prDraft = draft + plannedOnly, err := cmd.Flags().GetBool("planned-only") + if err != nil { + log.Fatal(err) + } + prPlannedOnly = plannedOnly + repos, err := whichRepos(cmd) if err != nil { log.Fatal(err) @@ -114,6 +122,18 @@ func pushOneRepo(r lib.Repo, ctx context.Context) error { return nil } + // Exit early if already pushed and --planned-only flag is used + if prPlannedOnly { + var pushOutput struct { + push.Output + Error string + } + if loadJSON(outputPath(r.Name, "push"), &pushOutput) == nil && pushOutput.Success { + log.Printf("%s/%s - already pushed (skipping due to --planned-only)", r.Owner, r.Name) + return nil + } + } + // Get previous step's output var planOutput plan.Output if loadJSON(outputPath(r.Name, "plan"), &planOutput) != nil || !planOutput.Success { @@ -165,4 +185,5 @@ func init() { pushCmd.Flags().StringVarP(&pushFlagBodyFile, "body-file", "b", "", "body of PR") pushCmd.Flags().StringSliceVarP(&pushFlagLabels, "labels", "l", nil, "labels to attach to PR. for example: `-l 'first label' -l 'second label'`") pushCmd.Flags().BoolVarP(&pushFlagDraft, "draft", "d", false, "push a draft pull request (only supported for github)") + pushCmd.Flags().BoolVarP(&pushFlagPlannedOnly, "planned-only", "p", false, "only push repositories that are in planned state (skip already pushed)") }