GetProject returns the project JSON object given its id or key
(projectIDOrKey string)
| 908 | |
| 909 | // GetProject returns the project JSON object given its id or key |
| 910 | func (client *Client) GetProject(projectIDOrKey string) (*Project, error) { |
| 911 | url := fmt.Sprintf( |
| 912 | "%s/rest/api/2/project/%s", client.serverURL, projectIDOrKey) |
| 913 | |
| 914 | request, err := http.NewRequest("GET", url, nil) |
| 915 | if err != nil { |
| 916 | return nil, err |
| 917 | } |
| 918 | |
| 919 | if client.ctx != nil { |
| 920 | ctx, cancel := context.WithTimeout(client.ctx, defaultTimeout) |
| 921 | defer cancel() |
| 922 | request = request.WithContext(ctx) |
| 923 | } |
| 924 | |
| 925 | response, err := client.Do(request) |
| 926 | if err != nil { |
| 927 | return nil, err |
| 928 | } |
| 929 | |
| 930 | defer response.Body.Close() |
| 931 | |
| 932 | if response.StatusCode != http.StatusOK { |
| 933 | err := fmt.Errorf( |
| 934 | "HTTP response %d, query was %s", response.StatusCode, url) |
| 935 | return nil, err |
| 936 | } |
| 937 | |
| 938 | var project Project |
| 939 | |
| 940 | data, _ := io.ReadAll(response.Body) |
| 941 | err = json.Unmarshal(data, &project) |
| 942 | if err != nil { |
| 943 | err := fmt.Errorf("Decoding response %v", err) |
| 944 | return nil, err |
| 945 | } |
| 946 | |
| 947 | return &project, nil |
| 948 | } |
| 949 | |
| 950 | // CreateIssue creates a new JIRA issue and returns it |
| 951 | func (client *Client) CreateIssue(projectIDOrKey, title, body string, |