Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a function that can delete a view by name && fixed the problem of capitalizing the wrong field. #326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 19 additions & 4 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (j *Jenkins) GetNode(ctx context.Context, name string) (*Node, error) {
if status == 200 {
return &node, nil
}
return nil, errors.New("No node found")
return nil, errors.New("no node found")
}

func (j *Jenkins) GetLabel(ctx context.Context, name string) (*Label, error) {
Expand All @@ -321,7 +321,7 @@ func (j *Jenkins) GetLabel(ctx context.Context, name string) (*Label, error) {
if status == 200 {
return &label, nil
}
return nil, errors.New("No label found")
return nil, errors.New("no label found")
}

func (j *Jenkins) GetBuild(ctx context.Context, jobName string, number int64) (*Build, error) {
Expand Down Expand Up @@ -489,7 +489,7 @@ func (j *Jenkins) UninstallPlugin(ctx context.Context, name string) error {
url := fmt.Sprintf("/pluginManager/plugin/%s/doUninstall", name)
resp, err := j.Requester.Post(ctx, url, strings.NewReader(""), struct{}{}, map[string]string{})
if resp.StatusCode != 200 {
return fmt.Errorf("Invalid status code returned: %d", resp.StatusCode)
return fmt.Errorf("invalid status code returned: %d", resp.StatusCode)
}
return err
}
Expand All @@ -511,7 +511,7 @@ func (j *Jenkins) InstallPlugin(ctx context.Context, name string, version string
resp, err := j.Requester.PostXML(ctx, "/pluginManager/installNecessaryPlugins", xml, j.Raw, map[string]string{})

if resp.StatusCode != 200 {
return fmt.Errorf("Invalid status code returned: %d", resp.StatusCode)
return fmt.Errorf("invalid status code returned: %d", resp.StatusCode)
}
return err
}
Expand Down Expand Up @@ -551,6 +551,21 @@ func (j *Jenkins) GetAllViews(ctx context.Context) ([]*View, error) {
return views, nil
}

func (j *Jenkins) DeleteView(ctx context.Context, name string) (error) {
endpoint := fmt.Sprintf("/view/%s/doDelete", name)
r, err := j.Requester.Post(ctx, endpoint, nil, nil, nil)

if err != nil {
return err
}

if r.StatusCode == 200 {
return nil
}
return errors.New(strconv.Itoa(r.StatusCode))
}


// Create View
// First Parameter - name of the View
// Second parameter - Type
Expand Down