MCPcopy Create free account
hub / github.com/git-bug/git-bug / DoTransition

Method DoTransition

bridge/jira/client.go:1357–1408  ·  view source on GitHub ↗

DoTransition changes the "status" of an issue

(issueKeyOrID string, transitionID string)

Source from the content-addressed store, hash-verified

1355
1356// DoTransition changes the "status" of an issue
1357func (client *Client) DoTransition(issueKeyOrID string, transitionID string) (time.Time, error) {
1358 url := fmt.Sprintf(
1359 "%s/rest/api/2/issue/%s/transitions", client.serverURL, issueKeyOrID)
1360 var responseTime time.Time
1361
1362 // TODO(josh)[767ee72]: Figure out a good way to "configure" the
1363 // open/close state mapping. It would be *great* if we could actually
1364 // *compute* the necessary transitions and prompt for missing metadata...
1365 // but that is complex
1366 var buffer bytes.Buffer
1367 _, _ = fmt.Fprintf(&buffer,
1368 `{"transition":{"id":"%s"}, "resolution": {"name": "Done"}}`,
1369 transitionID)
1370 request, err := http.NewRequest("POST", url, bytes.NewBuffer(buffer.Bytes()))
1371 if err != nil {
1372 return responseTime, err
1373 }
1374
1375 if client.ctx != nil {
1376 ctx, cancel := context.WithTimeout(client.ctx, defaultTimeout)
1377 defer cancel()
1378 request = request.WithContext(ctx)
1379 }
1380
1381 response, err := client.Do(request)
1382 if err != nil {
1383 err := fmt.Errorf("Performing request %v", err)
1384 return responseTime, err
1385 }
1386 defer response.Body.Close()
1387
1388 if response.StatusCode != http.StatusNoContent {
1389 err := errors.Wrap(errTransitionNotAllowed, fmt.Sprintf(
1390 "HTTP response %d, query was %s", response.StatusCode,
1391 request.URL.String()))
1392 return responseTime, err
1393 }
1394
1395 dateHeader, ok := response.Header["Date"]
1396 if !ok || len(dateHeader) != 1 {
1397 // No "Date" header, or empty, or multiple of them. Regardless, we don't
1398 // have a date we can return
1399 return responseTime, nil
1400 }
1401
1402 responseTime, err = http.ParseTime(dateHeader[0])
1403 if err != nil {
1404 return time.Time{}, err
1405 }
1406
1407 return responseTime, nil
1408}
1409
1410// GetServerInfo Fetch server information from the /serverinfo endpoint
1411// https://docs.atlassian.com/software/jira/docs/api/REST/8.2.6/#api/2/issue

Callers 1

UpdateIssueStatusFunction · 0.80

Implementers 1

Clientbridge/github/mocks/Client.go

Calls 4

ErrorfMethod · 0.80
BytesMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected