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