MCPcopy Index your code
hub / github.com/git-bug/git-bug / AddComment

Method AddComment

bridge/jira/client.go:1134–1180  ·  view source on GitHub ↗

AddComment adds a new comment to an issue (and returns it).

(issueKeyOrID, body string)

Source from the content-addressed store, hash-verified

1132
1133// AddComment adds a new comment to an issue (and returns it).
1134func (client *Client) AddComment(issueKeyOrID, body string) (*Comment, error) {
1135 url := fmt.Sprintf(
1136 "%s/rest/api/2/issue/%s/comment", client.serverURL, issueKeyOrID)
1137
1138 params := CommentCreate{Body: body}
1139 data, err := json.Marshal(params)
1140 if err != nil {
1141 return nil, err
1142 }
1143
1144 request, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
1145 if err != nil {
1146 return nil, err
1147 }
1148
1149 if client.ctx != nil {
1150 ctx, cancel := context.WithTimeout(client.ctx, defaultTimeout)
1151 defer cancel()
1152 request = request.WithContext(ctx)
1153 }
1154
1155 response, err := client.Do(request)
1156 if err != nil {
1157 err := fmt.Errorf("Performing request %v", err)
1158 return nil, err
1159 }
1160 defer response.Body.Close()
1161
1162 if response.StatusCode != http.StatusCreated {
1163 content, _ := io.ReadAll(response.Body)
1164 err := fmt.Errorf(
1165 "HTTP response %d, query was %s\n data: %s\n response: %s",
1166 response.StatusCode, request.URL.String(), data, content)
1167 return nil, err
1168 }
1169
1170 var result Comment
1171
1172 data, _ = io.ReadAll(response.Body)
1173 err = json.Unmarshal(data, &result)
1174 if err != nil {
1175 err := fmt.Errorf("Decoding response %v", err)
1176 return nil, err
1177 }
1178
1179 return &result, nil
1180}
1181
1182// UpdateComment changes the text of a comment
1183func (client *Client) UpdateComment(issueKeyOrID, commentID, body string) (

Callers 3

testCasesFunction · 0.45
testCasesFunction · 0.45
exportBugMethod · 0.45

Implementers 1

Clientbridge/github/mocks/Client.go

Calls 4

ErrorfMethod · 0.80
CloseMethod · 0.65
ReadAllMethod · 0.65
StringMethod · 0.65

Tested by 2

testCasesFunction · 0.36
testCasesFunction · 0.36