MCPcopy Index your code
hub / github.com/coder/coder / TaskByOwnerAndName

Method TaskByOwnerAndName

codersdk/aitasks.go:223–242  ·  view source on GitHub ↗

TaskByOwnerAndName fetches a single task by its owner and name.

(ctx context.Context, owner, ident string)

Source from the content-addressed store, hash-verified

221
222// TaskByOwnerAndName fetches a single task by its owner and name.
223func (c *Client) TaskByOwnerAndName(ctx context.Context, owner, ident string) (Task, error) {
224 if owner == "" {
225 owner = Me
226 }
227 res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/tasks/%s/%s", owner, ident), nil)
228 if err != nil {
229 return Task{}, err
230 }
231 defer res.Body.Close()
232 if res.StatusCode != http.StatusOK {
233 return Task{}, ReadBodyAsError(res)
234 }
235
236 var task Task
237 if err := json.NewDecoder(res.Body).Decode(&task); err != nil {
238 return Task{}, err
239 }
240
241 return task, nil
242}
243
244func splitTaskIdentifier(identifier string) (owner string, taskName string, err error) {
245 parts := strings.Split(identifier, "/")

Callers 2

TaskByIdentifierMethod · 0.95
TestTasksFunction · 0.80

Calls 3

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65

Tested by 1

TestTasksFunction · 0.64