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

Method GetIssue

bridge/jira/client.go:581–634  ·  view source on GitHub ↗

GetIssue fetches an issue object via the /issue/{IssueIdOrKey} endpoint https://docs.atlassian.com/software/jira/docs/api/REST/8.2.6/#api/2/issue

(idOrKey string, fields []string, expand []string,
	properties []string)

Source from the content-addressed store, hash-verified

579// GetIssue fetches an issue object via the /issue/{IssueIdOrKey} endpoint
580// https://docs.atlassian.com/software/jira/docs/api/REST/8.2.6/#api/2/issue
581func (client *Client) GetIssue(idOrKey string, fields []string, expand []string,
582 properties []string) (*Issue, error) {
583
584 url := fmt.Sprintf("%s/rest/api/2/issue/%s", client.serverURL, idOrKey)
585
586 request, err := http.NewRequest("GET", url, nil)
587 if err != nil {
588 err := fmt.Errorf("Creating request %v", err)
589 return nil, err
590 }
591
592 query := request.URL.Query()
593 if len(fields) > 0 {
594 query.Add("fields", strings.Join(fields, ","))
595 }
596 if len(expand) > 0 {
597 query.Add("expand", strings.Join(expand, ","))
598 }
599 if len(properties) > 0 {
600 query.Add("properties", strings.Join(properties, ","))
601 }
602 request.URL.RawQuery = query.Encode()
603
604 if client.ctx != nil {
605 ctx, cancel := context.WithTimeout(client.ctx, defaultTimeout)
606 defer cancel()
607 request = request.WithContext(ctx)
608 }
609
610 response, err := client.Do(request)
611 if err != nil {
612 err := fmt.Errorf("Performing request %v", err)
613 return nil, err
614 }
615 defer response.Body.Close()
616
617 if response.StatusCode != http.StatusOK {
618 err := fmt.Errorf(
619 "HTTP response %d, query was %s", response.StatusCode,
620 request.URL.String())
621 return nil, err
622 }
623
624 var issue Issue
625
626 data, _ := io.ReadAll(response.Body)
627 err = json.Unmarshal(data, &issue)
628 if err != nil {
629 err := fmt.Errorf("Decoding response %v", err)
630 return nil, err
631 }
632
633 return &issue, nil
634}
635
636// GetComments returns a page of comments via the issue/{IssueIdOrKey}/comment
637// endpoint

Callers 1

GetChangeLogMethod · 0.95

Implementers 1

Clientbridge/github/mocks/Client.go

Calls 6

ErrorfMethod · 0.80
AddMethod · 0.80
QueryMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
ReadAllMethod · 0.65

Tested by

no test coverage detected