From b43b6214b5631dd7653d5a6bf4a6ceb42ed20603 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 22 Jan 2025 00:21:36 +0300 Subject: [PATCH 1/2] fix(ci status): detect branch repo from remote Fixes #7735 --- commands/ci/status/status.go | 38 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/commands/ci/status/status.go b/commands/ci/status/status.go index 2bc172502..717a536e9 100644 --- a/commands/ci/status/status.go +++ b/commands/ci/status/status.go @@ -7,6 +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" @@ -45,11 +46,6 @@ 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") @@ -61,9 +57,29 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { } dbg.Debug("Current branch:", branch) } - runningPipeline, err := api.GetLastPipeline(apiClient, repo.FullName(), 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 { + return err + } + } + repoName := repo.FullName() + dbg.Debug("Repository:", repoName) + + runningPipeline, err := api.GetLastPipeline(apiClient, repoName, branch) if err != nil { - dbg.Debug("Repository:", repo.FullName()) redCheck := c.Red("✘") fmt.Fprintf(f.IO.StdOut, "%s No pipelines running or available on branch: %s\n", redCheck, branch) return err @@ -77,7 +93,7 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { writer.Start() defer writer.Stop() for isRunning { - jobs, err := api.GetPipelineJobs(apiClient, runningPipeline.ID, repo.FullName()) + jobs, err := api.GetPipelineJobs(apiClient, runningPipeline.ID, repoName) if err != nil { return err } @@ -124,7 +140,7 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { break } if (runningPipeline.Status == "pending" || runningPipeline.Status == "running") && live { - runningPipeline, err = api.GetLastPipeline(apiClient, repo.FullName(), branch) + runningPipeline, err = api.GetLastPipeline(apiClient, repoName, branch) if err != nil { return err } @@ -139,11 +155,11 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { if retry == "View logs" { isRunning = false } else { - _, err = api.RetryPipeline(apiClient, runningPipeline.ID, repo.FullName()) + _, err = api.RetryPipeline(apiClient, runningPipeline.ID, repoName) if err != nil { return err } - runningPipeline, err = api.GetLastPipeline(apiClient, repo.FullName(), branch) + runningPipeline, err = api.GetLastPipeline(apiClient, repoName, branch) if err != nil { return err } -- GitLab From afdf9a762d8f1be43060f9ea0ec1e526cbe57a3a Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Mon, 27 Jan 2025 20:39:42 +0300 Subject: [PATCH 2/2] fix: explain why pipelines not found when remote is gone - This covers narrow case when branch config specifies remote, but the remote itself is removed git remotes --- commands/ci/status/status.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/ci/status/status.go b/commands/ci/status/status.go index 717a536e9..8dd4635cd 100644 --- a/commands/ci/status/status.go +++ b/commands/ci/status/status.go @@ -72,6 +72,8 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { } 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 } } -- GitLab