Skip to content

Commit 12c3c2f

Browse files
committed
test cmds and make changes
test create cmd Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> test all cmds Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> lint fix Signed-off-by: Rizul Gupta <mail2rizul@gmail.com>
1 parent cca0dee commit 12c3c2f

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

cmd/harbor/root/webhook/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/goharbor/harbor-cli/pkg/api"
2020
"github.com/goharbor/harbor-cli/pkg/prompt"
21+
"github.com/goharbor/harbor-cli/pkg/utils"
2122
"github.com/goharbor/harbor-cli/pkg/views/webhook/create"
2223
"github.com/spf13/cobra"
2324
)
@@ -68,6 +69,10 @@ or leave them out and be guided through an interactive prompt to input each fiel
6869
opts.NotifyType != "" &&
6970
len(opts.EventType) != 0 &&
7071
opts.EndpointURL != "" {
72+
err = utils.ValidateURL(opts.EndpointURL)
73+
if err != nil {
74+
return err
75+
}
7176
err = api.CreateWebhook(&opts)
7277
} else {
7378
err = createWebhookView(createView)
@@ -84,7 +89,7 @@ or leave them out and be guided through an interactive prompt to input each fiel
8489
flags.StringVarP(&opts.ProjectName, "project", "", "", "Project Name")
8590
flags.StringVarP(&opts.Description, "description", "", "", "Webhook Description")
8691
flags.StringVarP(&opts.NotifyType, "notify-type", "", "", "Notify Type (http, slack)")
87-
flags.StringArrayVarP(&opts.EventType, "event-type", "", []string{}, "Event Types (comma separated)")
92+
flags.StringSliceVarP(&opts.EventType, "event-type", "", []string{}, "Event Types (comma separated)")
8893
flags.StringVarP(&opts.EndpointURL, "endpoint-url", "", "", "Webhook Endpoint URL")
8994
flags.StringVarP(&opts.PayloadFormat, "payload-format", "", "", "Payload Format (Default, CloudEvents)")
9095
flags.StringVarP(&opts.AuthHeader, "auth-header", "", "", "Authentication Header")

cmd/harbor/root/webhook/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ or interactively select a project and webhook if not provided.`,
8282
return fmt.Errorf("failed to delete webhook: %w", err)
8383
}
8484

85-
fmt.Printf("Webhook deleted successfully from project '%s'\n", projectName)
85+
fmt.Printf("Webhook deleted successfully from project '%s'\n", projectName)
8686
return nil
8787
},
8888
}
8989

9090
flags := cmd.Flags()
9191
flags.StringVarP(&projectName, "project", "", "", "Project name (required when providing webhook ID or name)")
92-
flags.Int64VarP(&webhookId, "webhook", "", -1, "Webhook ID (alternative to providing webhook name as argument)")
92+
flags.Int64VarP(&webhookId, "webhook-id", "", -1, "Webhook ID (alternative to providing webhook name as argument)")
9393

9494
return cmd
9595
}

cmd/harbor/root/webhook/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ or leave them out and use the interactive prompt to select and update a webhook.
100100
flags.Int64VarP(&opts.WebhookId, "webhook-id", "", -1, "Webhook ID")
101101
flags.StringVarP(&opts.Description, "description", "", "", "Webhook Description")
102102
flags.StringVarP(&opts.NotifyType, "notify-type", "", "", "Notify Type (http, slack)")
103-
flags.StringArrayVarP(&opts.EventType, "event-type", "", []string{}, "Event Types (comma separated)")
103+
flags.StringSliceVarP(&opts.EventType, "event-type", "", []string{}, "Event Types (comma separated)")
104104
flags.StringVarP(&opts.EndpointURL, "endpoint-url", "", "", "Webhook Endpoint URL")
105105
flags.StringVarP(&opts.PayloadFormat, "payload-format", "", "", "Payload Format (Default, CloudEvents)")
106106
flags.StringVarP(&opts.AuthHeader, "auth-header", "", "", "Authentication Header")

pkg/api/webhook_handler.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func CreateWebhook(opts *create.CreateView) error {
6767
})
6868

6969
if err != nil {
70-
log.Errorf("%s", err)
7170
return err
7271
}
7372

@@ -89,7 +88,6 @@ func DeleteWebhook(projectName string, webhookId int64) error {
8988
ProjectNameOrID: projectName,
9089
})
9190
if err != nil {
92-
log.Errorf("%s", err)
9391
return err
9492
}
9593
if response != nil {
@@ -125,7 +123,6 @@ func UpdateWebhook(opts *edit.EditView) error {
125123
},
126124
})
127125
if err != nil {
128-
log.Errorf("%s", err)
129126
return err
130127
}
131128
if response != nil {
@@ -145,7 +142,6 @@ func GetWebhookID(projectName string, WebhookName string) (int64, error) {
145142
})
146143

147144
if err != nil {
148-
log.Errorf("%s", err)
149145
return 0, err
150146
}
151147

@@ -171,7 +167,6 @@ func GetWebhook(projectName string, webhookId int64) (models.WebhookPolicy, erro
171167
XIsResourceName: &IsResourceName,
172168
})
173169
if err != nil {
174-
log.Errorf("%s", err)
175170
return models.WebhookPolicy{}, err
176171
}
177172
return *response.Payload, nil

0 commit comments

Comments
 (0)