Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add, get, assign, delete tags on ANY taggable resource type #163

Merged
18 commits merged into from
Sep 15, 2023
Merged

Conversation

ghost
Copy link

@ghost ghost commented Sep 8, 2023

Depends on

OpsLevel/opslevel-go#248

^Updated tag structs

Issues

https://github.com/OpsLevel/team-platform/issues/47

https://github.com/OpsLevel/team-platform/issues/44

Changelog

  • Add a better way to create and create --assign tags
  • Can update a tag if you have its ID
  • Delete any tag by using delete $TAG_ID
  • To get/list tags on an object, you can just use the existing opslevel object get ID/ALIAS and see the tags from there. The API does not support filtering on tags.
  • Updated go.mod since I wanted the slices library for Contains()
  • Also add support for get tag on any object

Tophatting

This works on any taggable resource, I used a Service in this example.

Create

$ opslevel create tag --type Service gamma taimoor x1
added new tag on gamma: Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjExMzk2
$ opslevel create tag --type Service gamma taimoor x2
added new tag on gamma: Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjExMzk3
Screenshot 2023-09-13 at 5 05 01 PM
$ opslevel create tag --type Service --assign gamma taimoor x3
updated new tag on gamma: Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjExNDAy
Screenshot 2023-09-13 at 5 05 18 PM

Update

$ opslevel update tag Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjE1NTA1 timur 3x
{
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjE1NTA1",
    "key": "timur",
    "value": "3x"
}

Delete

$ opslevel delete tag Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjExNDAy
deleted a tag: Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MjExNDAy%                                                                                                                                                              
Screenshot 2023-09-13 at 5 07 39 PM

@ghost ghost self-assigned this Sep 8, 2023
@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Merging #163 (ab2a3b8) into main (fc38982) will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff          @@
##            main    #163   +/-   ##
=====================================
  Coverage   6.22%   6.22%           
=====================================
  Files          5       5           
  Lines        257     257           
=====================================
  Hits          16      16           
  Misses       241     241           

@ghost ghost changed the title New tag commands for repo and team Add tag command for teams Sep 11, 2023
@ghost ghost force-pushed the repo-team-tags branch 2 times, most recently from 85e444f to 5ede4a0 Compare September 13, 2023 20:41
@ghost ghost changed the title Add tag command for teams Add, assign, delete tags on ANY taggable resource type Sep 13, 2023
@ghost ghost marked this pull request as ready for review September 13, 2023 21:13
@ghost ghost requested review from davidbloss and rocktavious September 13, 2023 21:39
src/cmd/tag.go Outdated Show resolved Hide resolved
src/cmd/tag.go Outdated Show resolved Hide resolved
src/cmd/tag.go Outdated Show resolved Hide resolved
@ghost ghost force-pushed the repo-team-tags branch from db07ba5 to b8eb29a Compare September 14, 2023 14:59
@ghost ghost force-pushed the repo-team-tags branch from b8eb29a to 86bdccf Compare September 14, 2023 15:04
src/cmd/tag.go Outdated Show resolved Hide resolved
@ghost ghost force-pushed the repo-team-tags branch from 63af09c to 4f092aa Compare September 14, 2023 17:38
deleteCmd.AddCommand(deleteTagCmd)
}

func validateResourceTypeArg() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW @davidbloss and @taimoor-at-opslevel - we can write tests in the CLI codebase that test these utility functions if we want to help ensure their functionality stays the same if we ever refactor.

The problem with testing the CLI is that things like deleteTagCmd are not testable with they way they are written.

@ghost ghost force-pushed the repo-team-tags branch 2 times, most recently from 7fccf5c to e40a684 Compare September 14, 2023 18:08
@ghost ghost requested review from rocktavious and davidbloss September 14, 2023 18:11
@ghost ghost marked this pull request as draft September 14, 2023 18:57
@ghost ghost changed the title Add, assign, delete tags on ANY taggable resource type Add, get, assign, delete tags on ANY taggable resource type Sep 14, 2023
@ghost ghost marked this pull request as ready for review September 14, 2023 22:07
@ghost
Copy link
Author

ghost commented Sep 14, 2023

@davidbloss and @rocktavious requesting re-review since opslevel service get tags and team get tags was replaced with opslevel get tags, which should be one command that works for all types once they have implemented TagConnection in opslevel-go.

tophatting:

$ opslevel get tag --type repository Z2lkOi8vb3BzbGV2ZWwvUmVwb3NpdG9yaWVzOjpHaXRodWIvOTU0MzE kyle
[
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MzU1MTI2",
    "key": "kyle",
    "value": "1234"
  }
]

$ opslevel get tag --type repository Z2lkOi8vb3BzbGV2ZWwvUmVwb3NpdG9yaWVzOjpHaXRodWIvOTU0MzE
[
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MzU1MTI4",
    "key": "david",
    "value": "9999"
  },
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MzU1MTI2",
    "key": "kyle",
    "value": "1234"
  },
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MzU1MTI0",
    "key": "taimoor",
    "value": "x1"
  },
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MzU1MTI1",
    "key": "taimoor",
    "value": "x2"
  }
]
$ opslevel get tag --type service gamma asdf
[
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzQyMTA1MQ",
    "key": "asdf",
    "value": "asdf"
  }
]
$ opslevel get tag --type team platform
[
  {
    "id": "Z2lkOi8vb3BzbGV2ZWwvVGFnLzU5MzU2Njky",
    "key": "test",
    "value": "hey"
  }
]
$ opslevel get tag --type team platform nonexistent # exact same behaviour as before
Error: tag with key 'nonexistent' not found on Team 'platform'
exit status 1

src/cmd/tag.go Outdated Show resolved Hide resolved
src/cmd/tag.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@rocktavious rocktavious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghost ghost force-pushed the repo-team-tags branch from 6541115 to fb7188a Compare September 15, 2023 15:09
Copy link
Contributor

@davidbloss davidbloss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghost ghost merged commit 89efd2c into main Sep 15, 2023
5 checks passed
@ghost ghost deleted the repo-team-tags branch September 15, 2023 18:35
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants