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

Method Update

pkg/cmd/discussion/client/client.go:1026–1097  ·  view source on GitHub ↗

Update updates a discussion's fields and/or labels. If field updates succeed but the label mutation fails, the returned discussion is non-nil (reflecting the updated fields without label changes) and err describes the label failure.

(repo ghrepo.Interface, input UpdateDiscussionInput)

Source from the content-addressed store, hash-verified

1024// but the label mutation fails, the returned discussion is non-nil (reflecting
1025// the updated fields without label changes) and err describes the label failure.
1026func (c *discussionClient) Update(repo ghrepo.Interface, input UpdateDiscussionInput) (*Discussion, error) {
1027 hasFieldUpdate := input.Title != nil || input.Body != nil || input.CategoryID != nil
1028 hasLabelUpdate := len(input.AddLabelIDs) > 0 || len(input.RemoveLabelIDs) > 0
1029
1030 if !hasFieldUpdate && !hasLabelUpdate {
1031 return nil, fmt.Errorf("nothing to update")
1032 }
1033
1034 var node *discussionListNode
1035
1036 if hasFieldUpdate {
1037 gqlInput := githubv4.UpdateDiscussionInput{
1038 DiscussionID: githubv4.ID(input.DiscussionID),
1039 }
1040 if input.Title != nil {
1041 gqlInput.Title = new(githubv4.String(*input.Title))
1042 }
1043 if input.Body != nil {
1044 gqlInput.Body = new(githubv4.String(*input.Body))
1045 }
1046 if input.CategoryID != nil {
1047 id := githubv4.ID(*input.CategoryID)
1048 gqlInput.CategoryID = &id
1049 }
1050
1051 var mutation struct {
1052 UpdateDiscussion struct {
1053 Discussion struct {
1054 discussionListNode
1055 }
1056 } `graphql:"updateDiscussion(input: $input)"`
1057 }
1058
1059 variables := map[string]any{
1060 "input": gqlInput,
1061 }
1062
1063 if err := c.gql.Mutate(repo.RepoHost(), "UpdateDiscussion", &mutation, variables); err != nil {
1064 return nil, err
1065 }
1066
1067 node = &mutation.UpdateDiscussion.Discussion.discussionListNode
1068 }
1069
1070 var secondaryErrs []error
1071 if hasLabelUpdate {
1072 labelNode, err := c.editDiscussionLabels(repo, input.DiscussionID, input.AddLabelIDs, input.RemoveLabelIDs)
1073 if err != nil {
1074 secondaryErrs = append(secondaryErrs, err)
1075 } else {
1076 node = labelNode
1077 }
1078 }
1079
1080 if node == nil {
1081 return nil, errors.Join(secondaryErrs...)
1082 }
1083

Callers

nothing calls this directly

Calls 7

editDiscussionLabelsMethod · 0.95
JoinMethod · 0.80
ErrorfMethod · 0.65
IDMethod · 0.65
MutateMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected