From 4fd621dc8bbe59af98f73ced911208eb9c25333e Mon Sep 17 00:00:00 2001 From: Filip Aleksic Date: Tue, 18 Feb 2025 13:51:51 +0100 Subject: [PATCH 1/2] fix(ci-status): default branch and repo fixes --- commands/ci/status/status.go | 38 +++++++----------------------------- docs/source/ci/status.md | 2 +- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/commands/ci/status/status.go b/commands/ci/status/status.go index 69084c9b5..bb03af612 100644 --- a/commands/ci/status/status.go +++ b/commands/ci/status/status.go @@ -7,9 +7,7 @@ import ( "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/ci/ciutils" "gitlab.com/gitlab-org/cli/commands/cmdutils" - "gitlab.com/gitlab-org/cli/internal/glrepo" "gitlab.com/gitlab-org/cli/pkg/dbg" - "gitlab.com/gitlab-org/cli/pkg/git" "gitlab.com/gitlab-org/cli/pkg/utils" "github.com/AlecAivazis/survey/v2" @@ -38,7 +36,6 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { Long: ``, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - var err error c := f.IO.Color() apiClient, err := f.HttpClient() @@ -46,39 +43,18 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { return err } + repo, err := f.BaseRepo() + if err != nil { + return err + } + branch, _ := cmd.Flags().GetString("branch") live, _ := cmd.Flags().GetBool("live") compact, _ := cmd.Flags().GetBool("compact") - if branch == "" { - branch, err = git.CurrentBranch() - if err != nil { - return err - } - dbg.Debug("Current branch:", branch) - } - - var repo glrepo.Interface - branchConfig := git.ReadBranchConfig(branch) - if branchConfig.RemoteName == "" { - repo, err = f.BaseRepo() - if err != nil { - return err - } - } else { - remotes, err := f.Remotes() - if err != nil { - return err - } - repo, err = remotes.FindByName(branchConfig.RemoteName) - if err != nil { - redCheck := c.Red("x") - fmt.Fprintf(f.IO.StdOut, "%s Remote '%s' for branch '%s' is gone.\n", redCheck, branchConfig.RemoteName, branch) - return err - } - } repoName := repo.FullName() dbg.Debug("Repository:", repoName) + dbg.Debug("Current branch:", branch) runningPipeline, err := api.GetLatestPipeline(apiClient, repoName, branch) if err != nil { @@ -187,7 +163,7 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { pipelineStatusCmd.Flags().BoolP("live", "l", false, "Show status in real time until the pipeline ends.") pipelineStatusCmd.Flags().BoolP("compact", "c", false, "Show status in compact format.") - pipelineStatusCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch. Default: current branch.") + pipelineStatusCmd.Flags().StringP("branch", "b", "main", "Check pipeline status for a branch.") return pipelineStatusCmd } diff --git a/docs/source/ci/status.md b/docs/source/ci/status.md index ee4515267..5c6e958f6 100644 --- a/docs/source/ci/status.md +++ b/docs/source/ci/status.md @@ -42,7 +42,7 @@ glab ci status ## Options ```plaintext - -b, --branch string Check pipeline status for a branch. Default: current branch. + -b, --branch string Check pipeline status for a branch. (default "main") -c, --compact Show status in compact format. -l, --live Show status in real time until the pipeline ends. ``` -- GitLab From f4c4781693a194664201f44a5330b42f9f0cf4da Mon Sep 17 00:00:00 2001 From: Filip Aleksic Date: Tue, 18 Feb 2025 14:40:23 +0100 Subject: [PATCH 2/2] Revert auto-branch-detection --- commands/ci/status/status.go | 32 +++++++++++++++++++++++++++++++- docs/source/ci/status.md | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/commands/ci/status/status.go b/commands/ci/status/status.go index bb03af612..58b243e4f 100644 --- a/commands/ci/status/status.go +++ b/commands/ci/status/status.go @@ -8,6 +8,7 @@ import ( "gitlab.com/gitlab-org/cli/commands/ci/ciutils" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/pkg/dbg" + "gitlab.com/gitlab-org/cli/pkg/git" "gitlab.com/gitlab-org/cli/pkg/utils" "github.com/AlecAivazis/survey/v2" @@ -54,6 +55,35 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { repoName := repo.FullName() dbg.Debug("Repository:", repoName) + + if branch == "" { + branch, err = git.CurrentBranch() + if err != nil { + // if there isn't a branch via --branch, and we are not in a git repository set the branch to main + branch = "main" + } + dbg.Debug("Current branch:", branch) + } + + branchConfig := git.ReadBranchConfig(branch) + if branchConfig.RemoteName == "" { + repo, err = f.BaseRepo() + if err != nil { + return err + } + } else { + remotes, err := f.Remotes() + if err != nil { + return err + } + repo, err = remotes.FindByName(branchConfig.RemoteName) + if err != nil { + redCheck := c.Red("x") + fmt.Fprintf(f.IO.StdOut, "%s Remote '%s' for branch '%s' is gone.\n", redCheck, branchConfig.RemoteName, branch) + return err + } + } + dbg.Debug("Current branch:", branch) runningPipeline, err := api.GetLatestPipeline(apiClient, repoName, branch) @@ -163,7 +193,7 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { pipelineStatusCmd.Flags().BoolP("live", "l", false, "Show status in real time until the pipeline ends.") pipelineStatusCmd.Flags().BoolP("compact", "c", false, "Show status in compact format.") - pipelineStatusCmd.Flags().StringP("branch", "b", "main", "Check pipeline status for a branch.") + pipelineStatusCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch.") return pipelineStatusCmd } diff --git a/docs/source/ci/status.md b/docs/source/ci/status.md index 5c6e958f6..d38614e6a 100644 --- a/docs/source/ci/status.md +++ b/docs/source/ci/status.md @@ -42,7 +42,7 @@ glab ci status ## Options ```plaintext - -b, --branch string Check pipeline status for a branch. (default "main") + -b, --branch string Check pipeline status for a branch. -c, --compact Show status in compact format. -l, --live Show status in real time until the pipeline ends. ``` -- GitLab