Skip to content

Commit

Permalink
Merge pull request #203 from OpsLevel/db/remove-old-IsID-from-common-…
Browse files Browse the repository at this point in the history
…helpers

drop func IsID() from common, exists in opslevel-go
  • Loading branch information
davidbloss authored Nov 13, 2023
2 parents bc596a0 + cf94806 commit 28e1f54
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Removed-20231113-105847.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Removed
body: drop func IsID() from common, exists in opslevel-go
time: 2023-11-13T10:58:47.667172-06:00
14 changes: 7 additions & 7 deletions src/cmd/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var getGroupCommand = &cobra.Command{
key := args[0]
var group *opslevel.Group
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
group, err = getClientGQL().GetGroup(opslevel.ID(key))
} else {
group, err = getClientGQL().GetGroupWithAlias(key)
Expand All @@ -57,7 +57,7 @@ var getGroupMembersCommand = &cobra.Command{
key := args[0]
var group *opslevel.Group
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
group, err = getClientGQL().GetGroup(opslevel.ID(key))
} else {
group, err = getClientGQL().GetGroupWithAlias(key)
Expand Down Expand Up @@ -91,7 +91,7 @@ var getGroupDescendantRepositoriesCommand = &cobra.Command{
key := args[0]
var group *opslevel.Group
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
group, err = getClientGQL().GetGroup(opslevel.ID(key))
} else {
group, err = getClientGQL().GetGroupWithAlias(key)
Expand Down Expand Up @@ -125,7 +125,7 @@ var getGroupDescendantServicesCommand = &cobra.Command{
key := args[0]
var group *opslevel.Group
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
group, err = getClientGQL().GetGroup(opslevel.ID(key))
} else {
group, err = getClientGQL().GetGroupWithAlias(key)
Expand Down Expand Up @@ -159,7 +159,7 @@ var getGroupDescendantSubgroupsCommand = &cobra.Command{
key := args[0]
var group *opslevel.Group
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
group, err = getClientGQL().GetGroup(opslevel.ID(key))
} else {
group, err = getClientGQL().GetGroupWithAlias(key)
Expand Down Expand Up @@ -193,7 +193,7 @@ var getGroupDescendantTeamsCommand = &cobra.Command{
key := args[0]
var group *opslevel.Group
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
group, err = getClientGQL().GetGroup(opslevel.ID(key))
} else {
group, err = getClientGQL().GetGroupWithAlias(key)
Expand Down Expand Up @@ -258,7 +258,7 @@ var deleteGroupCmd = &cobra.Command{
ArgAliases: []string{"ID", "ALIAS"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
if common.IsID(key) {
if opslevel.IsID(key) {
err := getClientGQL().DeleteGroup(key)
cobra.CheckErr(err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var getRepositoryCmd = &cobra.Command{
key := args[0]
var repository *opslevel.Repository
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
repository, err = getClientGQL().GetRepository(opslevel.ID(key))
cobra.CheckErr(err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var getServiceCmd = &cobra.Command{
client := getClientGQL()
var service *opslevel.Service
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
service, err = getClientGQL().GetService(opslevel.ID(key))
cobra.CheckErr(err)
} else {
Expand Down Expand Up @@ -145,7 +145,7 @@ var deleteServiceCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
err = getClientGQL().DeleteService(opslevel.ServiceDeleteInput{
Id: opslevel.ID(key),
})
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var createMemberCmd = &cobra.Command{

var team *opslevel.Team
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
team, err = getClientGQL().GetTeam(opslevel.ID(key))
} else {
team, err = getClientGQL().GetTeamWithAlias(key)
Expand Down Expand Up @@ -85,7 +85,7 @@ opslevel create contact --type=email my-team [email protected] "Mailing List"`,

var team *opslevel.Team
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
team, err = getClientGQL().GetTeam(opslevel.ID(key))
} else {
team, err = getClientGQL().GetTeamWithAlias(key)
Expand Down Expand Up @@ -160,7 +160,7 @@ var getTeamCmd = &cobra.Command{
}

func GetTeam(key string) (*opslevel.Team, error) {
if common.IsID(key) {
if opslevel.IsID(key) {
return getClientGQL().GetTeam(opslevel.ID(key))
} else {
return getClientGQL().GetTeamWithAlias(key)
Expand Down Expand Up @@ -212,7 +212,7 @@ opslevel delete team my-team
ArgAliases: []string{"ID", "ALIAS"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
if common.IsID(key) {
if opslevel.IsID(key) {
err := getClientGQL().DeleteTeam(opslevel.ID(key))
cobra.CheckErr(err)
} else {
Expand All @@ -235,7 +235,7 @@ var deleteMemberCmd = &cobra.Command{

var team *opslevel.Team
var err error
if common.IsID(key) {
if opslevel.IsID(key) {
team, err = getClientGQL().GetTeam(opslevel.ID(key))
} else {
team, err = getClientGQL().GetTeamWithAlias(key)
Expand Down
11 changes: 0 additions & 11 deletions src/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package common

import (
"bytes"
b64 "encoding/base64"
"fmt"
"strings"

"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
Expand All @@ -23,15 +21,6 @@ func WasFound(condition bool, key string) {
}
}

// TODO: we should probably move this into opslevel-go
func IsID(value string) bool {
decoded, err := b64.RawURLEncoding.DecodeString(value)
if err != nil {
return false
}
return strings.HasPrefix(string(decoded), "gid://")
}

func JsonPrint(jsonBytes []byte, err error) {
cobra.CheckErr(err)
fmt.Printf("%s\n", string(jsonBytes))
Expand Down

0 comments on commit 28e1f54

Please sign in to comment.