GetJob retrieves an agent job
(ctx context.Context, owner, repo, jobID string)
| 129 | |
| 130 | // GetJob retrieves an agent job |
| 131 | func (c *CAPIClient) GetJob(ctx context.Context, owner, repo, jobID string) (*Job, error) { |
| 132 | if owner == "" || repo == "" || jobID == "" { |
| 133 | return nil, errors.New("owner, repo, and jobID are required") |
| 134 | } |
| 135 | url := fmt.Sprintf("%s/%s/%s/%s", c.jobsBasePathV1(), url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(jobID)) |
| 136 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | res, err := c.httpClient.Do(req) |
| 141 | if err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | defer res.Body.Close() |
| 145 | if res.StatusCode != http.StatusOK { |
| 146 | // Normalize to "<code> <text>" form |
| 147 | statusText := fmt.Sprintf("%d %s", res.StatusCode, http.StatusText(res.StatusCode)) |
| 148 | return nil, fmt.Errorf("failed to get job: %s", statusText) |
| 149 | } |
| 150 | var j Job |
| 151 | if err := json.NewDecoder(res.Body).Decode(&j); err != nil { |
| 152 | return nil, fmt.Errorf("failed to decode get job response: %w", err) |
| 153 | } |
| 154 | return &j, nil |
| 155 | } |