Skip to content

Commit

Permalink
Renamed job update to step update
Browse files Browse the repository at this point in the history
  • Loading branch information
keithpitt committed Oct 23, 2018
1 parent 0ee861b commit 7176b66
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 44 deletions.
2 changes: 2 additions & 0 deletions api/buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Client struct {
Agents *AgentsService
Pings *PingsService
Jobs *JobsService
Steps *StepsService
Chunks *ChunksService
MetaData *MetaDataService
HeaderTimes *HeaderTimesService
Expand All @@ -66,6 +67,7 @@ func NewClient(httpClient *http.Client) *Client {
c.Agents = &AgentsService{c}
c.Pings = &PingsService{c}
c.Jobs = &JobsService{c}
c.Steps = &StepsService{c}
c.Chunks = &ChunksService{c}
c.MetaData = &MetaDataService{c}
c.HeaderTimes = &HeaderTimesService{c}
Expand Down
20 changes: 0 additions & 20 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ type Job struct {
ChunksFailedCount int `json:"chunks_failed_count,omitempty"`
}

// JobUpdate represents a change request to a job
type JobUpdate struct {
UUID string `json:"uuid,omitempty"`
Attribute string `json:"attribute,omitempty"`
Value string `json:"value,omitempty"`
Append bool `json:"append,omitempty"`
}

type JobState struct {
State string `json:"state,omitempty"`
}
Expand Down Expand Up @@ -112,15 +104,3 @@ func (js *JobsService) Finish(job *Job) (*Response, error) {

return js.client.Do(req, nil)
}

// Updates a job
func (js *JobsService) Update(jobId string, jobUpdate *JobUpdate) (*Response, error) {
u := fmt.Sprintf("jobs/%s", jobId)

req, err := js.client.NewRequest("PUT", u, jobUpdate)
if err != nil {
return nil, err
}

return js.client.Do(req, nil)
}
31 changes: 31 additions & 0 deletions api/steps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package api

import (
"fmt"
)

// StepsService handles communication with the step related methods of the
// Buildkite Agent API.
type StepsService struct {
client *Client
}

// StepUpdate represents a change request to a step
type StepUpdate struct {
UUID string `json:"uuid,omitempty"`
Attribute string `json:"attribute,omitempty"`
Value string `json:"value,omitempty"`
Append bool `json:"append,omitempty"`
}

// Updates a step
func (js *StepsService) Update(stepId string, stepUpdate *StepUpdate) (*Response, error) {
u := fmt.Sprintf("steps/%s", stepId)

req, err := js.client.NewRequest("PUT", u, stepUpdate)
if err != nil {
return nil, err
}

return js.client.Do(req, nil)
}
42 changes: 21 additions & 21 deletions clicommand/job_update.go → clicommand/step_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,48 @@ import (
"github.com/urfave/cli"
)

var JobUpdateHelpDescription = `Usage:
var StepUpdateHelpDescription = `Usage:
buildkite-agent job update <attribute> <value> [arguments...]
buildkite-agent step update <attribute> <value> [arguments...]
Description:
Update an attribute of a job
Update an attribute of a step
Example:
$ buildkite-agent job update "label" "New Label"
$ buildkite-agent job update "label" " (add to end of label)" --append
$ buildkite-agent job update "label" < ./tmp/some-new-label
$ ./script/label-generator | buildkite-agent job update "label"`
$ buildkite-agent step update "label" "New Label"
$ buildkite-agent step update "label" " (add to end of label)" --append
$ buildkite-agent step update "label" < ./tmp/some-new-label
$ ./script/label-generator | buildkite-agent step update "label"`

type JobUpdateConfig struct {
type StepUpdateConfig struct {
Attribute string `cli:"arg:0" label:"attribute" validate:"required"`
Value string `cli:"arg:1" label:"value" validate:"required"`
Append bool `cli:"append"`
Job string `cli:"job" validate:"required"`
Step string `cli:"step" validate:"required"`
AgentAccessToken string `cli:"agent-access-token" validate:"required"`
Endpoint string `cli:"endpoint" validate:"required"`
NoColor bool `cli:"no-color"`
Debug bool `cli:"debug"`
DebugHTTP bool `cli:"debug-http"`
}

var JobUpdateCommand = cli.Command{
var StepUpdateCommand = cli.Command{
Name: "update",
Usage: "Change an attribute on a job",
Description: JobUpdateHelpDescription,
Usage: "Change an attribute on a step",
Description: StepUpdateHelpDescription,
Flags: []cli.Flag{
cli.StringFlag{
Name: "job",
Name: "step",
Value: "",
Usage: "Which job should the change be made to",
EnvVar: "BUILDKITE_JOB_ID",
Usage: "Target the step of a specific step",
EnvVar: "BUILDKITE_STEP_ID",
},
cli.BoolFlag{
Name: "append",
Usage: "Append to current attribute instead of replacing it",
EnvVar: "BUILDKITE_JOB_UPDATE_APPEND",
EnvVar: "BUILDKITE_STEP_UPDATE_APPEND",
},
AgentAccessTokenFlag,
EndpointFlag,
Expand All @@ -64,7 +64,7 @@ var JobUpdateCommand = cli.Command{
},
Action: func(c *cli.Context) {
// The configuration will be loaded into this struct
cfg := JobUpdateConfig{}
cfg := StepUpdateConfig{}

// Load the configuration
if err := cliconfig.Load(c, &cfg); err != nil {
Expand Down Expand Up @@ -93,11 +93,11 @@ var JobUpdateCommand = cli.Command{

// Generate a UUID that will identifiy this change. We do this
// outside of the retry loop because we want this UUID to be
// the same for each attempt at updating the job.
// the same for each attempt at updating the step.
uuid := api.NewUUID()

// Create the value to update
update := &api.JobUpdate{
update := &api.StepUpdate{
UUID: uuid,
Attribute: cfg.Attribute,
Value: cfg.Value,
Expand All @@ -106,7 +106,7 @@ var JobUpdateCommand = cli.Command{

// Post the change
err := retry.Do(func(s *retry.Stats) error {
resp, err := client.Jobs.Update(cfg.Job, update)
resp, err := client.Steps.Update(cfg.Step, update)
if resp != nil && (resp.StatusCode == 401 || resp.StatusCode == 404) {
s.Break()
}
Expand All @@ -117,7 +117,7 @@ var JobUpdateCommand = cli.Command{
return err
}, &retry.Config{Maximum: 10, Interval: 5 * time.Second})
if err != nil {
logger.Fatal("Failed to change job: %s", err)
logger.Fatal("Failed to change step: %s", err)
}
},
}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func main() {
},
},
{
Name: "job",
Usage: "Make changes to a job",
Name: "step",
Usage: "Make changes to a step",
Subcommands: []cli.Command{
clicommand.JobUpdateCommand,
clicommand.StepUpdateCommand,
},
},
clicommand.BootstrapCommand,
Expand Down

0 comments on commit 7176b66

Please sign in to comment.