MCPcopy
hub / github.com/cli/cli / editDiscussionLabels

Method editDiscussionLabels

pkg/cmd/discussion/client/client.go:901–963  ·  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

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

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