Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions api/client/dashbaards_v1_alpha.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"

models "github.com/semaphoreci/cli/api/models"
Expand All @@ -28,11 +27,11 @@ func (c *DashboardApiV1AlphaApi) ListDashboards() (*models.DashboardListV1Alpha,
body, status, err := c.BaseClient.List(c.ResourceNamePlural)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
}

return models.NewDashboardListV1AlphaFromJson(body)
Expand All @@ -42,11 +41,11 @@ func (c *DashboardApiV1AlphaApi) GetDashboard(name string) (*models.DashboardV1A
body, status, err := c.BaseClient.Get(c.ResourceNamePlural, name)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewDashboardV1AlphaFromJson(body)
Expand All @@ -70,17 +69,17 @@ func (c *DashboardApiV1AlphaApi) CreateDashboard(d *models.DashboardV1Alpha) (*m
json_body, err := d.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize object '%s'", err))
return nil, fmt.Errorf("failed to serialize object '%s'", err)
}

body, status, err := c.BaseClient.Post(c.ResourceNamePlural, json_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("creating %s on Semaphore failed '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("creating %s on Semaphore failed '%s'", c.ResourceNameSingular, err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewDashboardV1AlphaFromJson(body)
Expand All @@ -90,7 +89,7 @@ func (c *DashboardApiV1AlphaApi) UpdateDashboard(d *models.DashboardV1Alpha) (*m
json_body, err := d.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize %s object '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("failed to serialize %s object '%s'", c.ResourceNameSingular, err)
}

identifier := ""
Expand All @@ -104,11 +103,11 @@ func (c *DashboardApiV1AlphaApi) UpdateDashboard(d *models.DashboardV1Alpha) (*m
body, status, err := c.BaseClient.Patch(c.ResourceNamePlural, identifier, json_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("updating %s on Semaphore failed '%s'", c.ResourceNamePlural, err))
return nil, fmt.Errorf("updating %s on Semaphore failed '%s'", c.ResourceNamePlural, err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewDashboardV1AlphaFromJson(body)
Expand Down
29 changes: 14 additions & 15 deletions api/client/jobs_v1_alpha.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -35,11 +34,11 @@ func (c *JobsApiV1AlphaApi) ListJobs(states []string) (*models.JobListV1Alpha, e
body, status, err := c.BaseClient.ListWithParams(c.ResourceNamePlural, query)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewJobListV1AlphaFromJson(body)
Expand All @@ -49,11 +48,11 @@ func (c *JobsApiV1AlphaApi) GetJob(name string) (*models.JobV1Alpha, error) {
body, status, err := c.BaseClient.Get(c.ResourceNamePlural, name)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewJobV1AlphaFromJson(body)
Expand All @@ -64,11 +63,11 @@ func (c *JobsApiV1AlphaApi) GetJobDebugSSHKey(id string) (*models.JobDebugSSHKey
body, status, err := c.BaseClient.Get(c.ResourceNamePlural, path)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewJobDebugSSHKeyV1AlphaFromJSON(body)
Expand All @@ -78,17 +77,17 @@ func (c *JobsApiV1AlphaApi) CreateJob(j *models.JobV1Alpha) (*models.JobV1Alpha,
json_body, err := j.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize object '%s'", err))
return nil, fmt.Errorf("failed to serialize object '%s'", err)
}

body, status, err := c.BaseClient.Post(c.ResourceNamePlural, json_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("creating %s on Semaphore failed '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("creating %s on Semaphore failed '%s'", c.ResourceNameSingular, err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewJobV1AlphaFromJson(body)
Expand All @@ -98,18 +97,18 @@ func (c *JobsApiV1AlphaApi) CreateDebugJob(j *models.DebugJobV1Alpha) (*models.J
json_body, err := j.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize object '%s'", err))
return nil, fmt.Errorf("failed to serialize object '%s'", err)
}

path := fmt.Sprintf("%s/%s/%s", c.ResourceNamePlural, j.JobId, "debug")
body, status, err := c.BaseClient.Post(path, json_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("creating debug %s on Semaphore failed '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("creating debug %s on Semaphore failed '%s'", c.ResourceNameSingular, err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewJobV1AlphaFromJson(body)
Expand All @@ -120,11 +119,11 @@ func (c *JobsApiV1AlphaApi) StopJob(id string) error {
body, status, err := c.BaseClient.Post(path, []byte{})

if err != nil {
return errors.New(fmt.Sprintf("stopping %s on Semaphore failed '%s'", c.ResourceNameSingular, err))
return fmt.Errorf("stopping %s on Semaphore failed '%s'", c.ResourceNameSingular, err)
}

if status != 200 {
return errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions api/client/notifications_v1_alpha.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"

models "github.com/semaphoreci/cli/api/models"
Expand Down Expand Up @@ -70,7 +69,7 @@ func (c *NotificationsV1AlphaApi) CreateNotification(n *models.NotificationV1Alp
json_body, err := n.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize object '%s'", err))
return nil, fmt.Errorf("failed to serialize object '%s'", err)
}

body, status, err := c.BaseClient.Post(c.ResourceNamePlural, json_body)
Expand All @@ -90,7 +89,7 @@ func (c *NotificationsV1AlphaApi) UpdateNotification(n *models.NotificationV1Alp
json_body, err := n.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize %s object '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("failed to serialize %s object '%s'", c.ResourceNameSingular, err)
}

identifier := ""
Expand Down
31 changes: 15 additions & 16 deletions api/client/pipelines_v1_alpha.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"

uuid "github.com/google/uuid"
Expand Down Expand Up @@ -30,11 +29,11 @@ func (c *PipelinesApiV1AlphaApi) DescribePpl(id string) (*models.PipelineV1Alpha
body, status, err := c.BaseClient.Get(c.ResourceNamePlural, detailed)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewPipelineV1AlphaFromJson(body)
Expand All @@ -46,11 +45,11 @@ func (c *PipelinesApiV1AlphaApi) StopPpl(id string) ([]byte, error) {
body, status, err := c.BaseClient.Patch(c.ResourceNamePlural, id, request_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return body, nil
Expand All @@ -60,48 +59,48 @@ func (c *PipelinesApiV1AlphaApi) PartialRebuildPpl(id string) ([]byte, error) {
requestToken, err := uuid.NewUUID()

if err != nil {
return nil, errors.New(fmt.Sprintf("request token generation failed '%s'", err))
return nil, fmt.Errorf("request token generation failed '%s'", err)
}

actionArgs := fmt.Sprintf("%s?%s=%s", "partial_rebuild", "request_token", requestToken.String())
body, status, err := c.BaseClient.PostAction(c.ResourceNamePlural, id, actionArgs, []byte(""))

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return body, nil
}

func (c *PipelinesApiV1AlphaApi) ListPplByWfID(projectID, wfID string) ([]byte, error) {
detailed := fmt.Sprintf("%s?project_id=%s&wf_id=%s", c.ResourceNamePlural, projectID, wfID)
detailed := fmt.Sprintf("%s?project_id=%s&wf_id=%s", c.ResourceNamePlural, projectID, wfID)
body, status, err := c.BaseClient.List(detailed)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
if err != nil {
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return body, nil
}

func (c *PipelinesApiV1AlphaApi) ListPpl(projectID string) ([]byte, error) {
detailed := fmt.Sprintf("%s?project_id=%s", c.ResourceNamePlural, projectID)
detailed := fmt.Sprintf("%s?project_id=%s", c.ResourceNamePlural, projectID)
body, status, err := c.BaseClient.List(detailed)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
if err != nil {
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return body, nil
Expand Down
21 changes: 10 additions & 11 deletions api/client/projects_v1_alpha.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"

models "github.com/semaphoreci/cli/api/models"
Expand Down Expand Up @@ -38,11 +37,11 @@ func (c *ProjectApiV1AlphaApi) ListProjects() (*models.ProjectListV1Alpha, error
body, status, err := c.BaseClient.List(c.ResourceNamePlural)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewProjectListV1AlphaFromJson(body)
Expand All @@ -52,11 +51,11 @@ func (c *ProjectApiV1AlphaApi) GetProject(name string) (*models.ProjectV1Alpha,
body, status, err := c.BaseClient.Get(c.ResourceNamePlural, name)

if err != nil {
return nil, errors.New(fmt.Sprintf("connecting to Semaphore failed '%s'", err))
return nil, fmt.Errorf("connecting to Semaphore failed '%s'", err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewProjectV1AlphaFromJson(body)
Expand All @@ -80,17 +79,17 @@ func (c *ProjectApiV1AlphaApi) CreateProject(d *models.ProjectV1Alpha) (*models.
json_body, err := d.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize object '%s'", err))
return nil, fmt.Errorf("failed to serialize object '%s'", err)
}

body, status, err := c.BaseClient.Post(c.ResourceNamePlural, json_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("creating %s on Semaphore failed '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("creating %s on Semaphore failed '%s'", c.ResourceNameSingular, err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewProjectV1AlphaFromJson(body)
Expand All @@ -100,19 +99,19 @@ func (c *ProjectApiV1AlphaApi) UpdateProject(d *models.ProjectV1Alpha) (*models.
json_body, err := d.ToJson()

if err != nil {
return nil, errors.New(fmt.Sprintf("failed to serialize %s object '%s'", c.ResourceNameSingular, err))
return nil, fmt.Errorf("failed to serialize %s object '%s'", c.ResourceNameSingular, err)
}

identifier := d.Metadata.Id

body, status, err := c.BaseClient.Patch(c.ResourceNamePlural, identifier, json_body)

if err != nil {
return nil, errors.New(fmt.Sprintf("updating %s on Semaphore failed '%s'", c.ResourceNamePlural, err))
return nil, fmt.Errorf("updating %s on Semaphore failed '%s'", c.ResourceNamePlural, err)
}

if status != 200 {
return nil, errors.New(fmt.Sprintf("http status %d with message \"%s\" received from upstream", status, body))
return nil, fmt.Errorf("http status %d with message \"%s\" received from upstream", status, body)
}

return models.NewProjectV1AlphaFromJson(body)
Expand Down
Loading