MCPcopy Create free account
hub / github.com/cli/cli / editDiscussionLabels

Method editDiscussionLabels

pkg/cmd/discussion/client/client.go:898–960  ·  view source on GitHub ↗

editDiscussionLabels adds and removes labels on a discussion. Removals are applied before additions. Either slice may be nil or empty to skip that step. Returns the discussion state as returned by the last mutation executed.

(repo ghrepo.Interface, discussionID string, addIDs, removeIDs []string)

Source from the content-addressed store, hash-verified

896// applied before additions. Either slice may be nil or empty to skip that step.
897// Returns the discussion state as returned by the last mutation executed.
898func (c *discussionClient) editDiscussionLabels(repo ghrepo.Interface, discussionID string, addIDs, removeIDs []string) (*discussionListNode, error) {
899 var node *discussionListNode
900
901 if len(removeIDs) > 0 {
902 ids := make([]githubv4.ID, len(removeIDs))
903 for i, id := range removeIDs {
904 ids[i] = githubv4.ID(id)
905 }
906
907 var mutation struct {
908 RemoveLabelsFromLabelable struct {
909 Labelable struct {
910 Discussion struct {
911 discussionListNode
912 } `graphql:"... on Discussion"`
913 }
914 } `graphql:"removeLabelsFromLabelable(input: $input)"`
915 }
916
917 variables := map[string]any{
918 "input": githubv4.RemoveLabelsFromLabelableInput{
919 LabelableID: githubv4.ID(discussionID),
920 LabelIDs: ids,
921 },
922 }
923
924 if err := c.gql.Mutate(repo.RepoHost(), "RemoveLabelsFromDiscussion", &mutation, variables); err != nil {
925 return nil, err
926 }
927 node = &mutation.RemoveLabelsFromLabelable.Labelable.Discussion.discussionListNode
928 }
929
930 if len(addIDs) > 0 {
931 ids := make([]githubv4.ID, len(addIDs))
932 for i, id := range addIDs {
933 ids[i] = githubv4.ID(id)
934 }
935
936 var mutation struct {
937 AddLabelsToLabelable struct {
938 Labelable struct {
939 Discussion struct {
940 discussionListNode
941 } `graphql:"... on Discussion"`
942 }
943 } `graphql:"addLabelsToLabelable(input: $input)"`
944 }
945
946 variables := map[string]any{
947 "input": githubv4.AddLabelsToLabelableInput{
948 LabelableID: githubv4.ID(discussionID),
949 LabelIDs: ids,
950 },
951 }
952
953 if err := c.gql.Mutate(repo.RepoHost(), "AddLabelsToDiscussion", &mutation, variables); err != nil {
954 return nil, err
955 }

Callers 3

CreateMethod · 0.95
UpdateMethod · 0.95
TestEditDiscussionLabelsFunction · 0.80

Calls 3

IDMethod · 0.65
MutateMethod · 0.65
RepoHostMethod · 0.65

Tested by 1

TestEditDiscussionLabelsFunction · 0.64