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