-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
173e401
commit af26300
Showing
5 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License.AGPL.txt in the project root for license information. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"os" | ||
"time" | ||
|
||
"github.com/bufbuild/connect-go" | ||
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1" | ||
"github.com/gitpod-io/local-app/pkg/common" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// stopWorkspaceCommand stops to a given workspace | ||
var getWorkspaceCommand = &cobra.Command{ | ||
Use: "get <workspace-id>", | ||
Short: "Retrieves metadata of a given workspace", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
workspaceID := "" | ||
if len(args) < 1 { | ||
workspaceID = common.SelectWorkspace(cmd.Context(), nil) | ||
} else { | ||
workspaceID = args[0] | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second) | ||
defer cancel() | ||
|
||
gitpod, err := common.GetGitpodClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
slog.Debug("Attempting to retrieve workspace info...") | ||
ws, err := gitpod.Workspaces.GetWorkspace(ctx, connect.NewRequest(&v1.GetWorkspaceRequest{WorkspaceId: workspaceID})) | ||
|
||
wsInfo := ws.Msg.GetResult() | ||
repository := getWorkspaceRepo(wsInfo) | ||
phase := TranslatePhase(wsInfo.Status.Instance.Status.Phase.String()) | ||
|
||
data := &infoData{ | ||
WorkspaceId: wsInfo.WorkspaceId, | ||
WorkspaceUrl: wsInfo.Status.Instance.Status.Url, | ||
Repository: repository, | ||
Branch: wsInfo.Status.Instance.Status.GitStatus.Branch, | ||
WorkspacePhase: phase, | ||
// todo: LastActive, Created, WorkspaceClass (API implementation pending), RepoUrl (API implementation also pending) | ||
} | ||
|
||
outputInfo(data) | ||
|
||
return err | ||
}, | ||
} | ||
|
||
type infoData struct { | ||
WorkspaceId string `json:"workspace_id"` | ||
WorkspaceUrl string `json:"workspace_url"` | ||
Branch string `json:"branch"` | ||
Repository string `json:"repository"` | ||
WorkspacePhase string `json:"workspace_phase"` | ||
} | ||
|
||
func outputInfo(info *infoData) { | ||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetColWidth(50) | ||
table.SetBorder(false) | ||
table.SetColumnSeparator(":") | ||
table.Append([]string{"ID", info.WorkspaceId}) | ||
table.Append([]string{"URL", info.WorkspaceUrl}) | ||
// Class | ||
table.Append([]string{"Status", info.WorkspacePhase}) | ||
// Repo URL | ||
table.Append([]string{"Repo", info.Repository}) | ||
table.Append([]string{"Branch", info.Branch}) | ||
// Created (date) | ||
// Last Active (duration) | ||
table.Render() | ||
} | ||
|
||
func init() { | ||
wsCmd.AddCommand(getWorkspaceCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters