MCPcopy Create free account
hub / github.com/cli/cli / GetJob

Method GetJob

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

GetJob retrieves an agent job

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

Source from the content-addressed store, hash-verified

133
134// GetJob retrieves an agent job
135func (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}

Callers 2

TestGetJobFunction · 0.95

Calls 6

jobsBasePathV1Method · 0.95
JoinPathWithHostPrefixFunction · 0.92
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by 2

TestGetJobFunction · 0.76