MCPcopy Index your code
hub / github.com/cli/cli / GetJob

Method GetJob

pkg/cmd/agent-task/capi/job.go:131–155  ·  view source on GitHub ↗

GetJob retrieves an agent job

(ctx context.Context, owner, repo, jobID string)

Source from the content-addressed store, hash-verified

129
130// GetJob retrieves an agent job
131func (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}

Callers 2

TestGetJobFunction · 0.95

Calls 4

jobsBasePathV1Method · 0.95
DoMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by 2

TestGetJobFunction · 0.76