diff --git a/server/command.go b/server/command.go index 3dde15ce..abcb6604 100644 --- a/server/command.go +++ b/server/command.go @@ -339,7 +339,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (res } } -func (p *Plugin) handleSetup(c *plugin.Context, args *model.CommandArgs, parameters []string) string { +func (p *Plugin) handleSetup(_ *plugin.Context, args *model.CommandArgs, parameters []string) string { userID := args.UserId isSysAdmin, err := p.isAuthorizedSysAdmin(userID) if err != nil { @@ -590,7 +590,7 @@ func parseTriggers(triggersCsv string) *gitlab.AddWebhookOptions { } } -func (p *Plugin) subscriptionDelete(info *gitlab.UserInfo, config *configuration, fullPath, channelID string) (string, error) { +func (p *Plugin) subscriptionDelete(_ *gitlab.UserInfo, config *configuration, fullPath, channelID string) (string, error) { normalizedPath := normalizePath(fullPath, config.GitlabURL) deleted, updatedSubscriptions, err := p.Unsubscribe(channelID, normalizedPath) if err != nil { @@ -720,7 +720,7 @@ func (p *Plugin) subscribeCommand(ctx context.Context, parameters []string, chan if len(parameters) < 2 { return missingOrgOrRepoFromSubscribeCommand } else if len(parameters) > 2 { - features = strings.Join(parameters[1:], " ") + features = strings.Join(parameters[2:], " ") } // Resolve namespace and project name fullPath := normalizePath(parameters[1], config.GitlabURL) @@ -740,6 +740,7 @@ func (p *Plugin) subscribeCommand(ctx context.Context, parameters []string, chan return invalidSubscribeSubCommand } } + func (p *Plugin) pipelinesCommand(ctx context.Context, parameters []string, channelID string, info *gitlab.UserInfo) string { if len(parameters) == 0 { return invalidPipelinesSubCommand diff --git a/server/command_test.go b/server/command_test.go index 9473fcb4..0a607d8e 100644 --- a/server/command_test.go +++ b/server/command_test.go @@ -41,6 +41,11 @@ var subscribeCommandTests = []subscribeCommandTest{ parameters: []string{"list"}, want: "Currently there are no subscriptions in this channel", }, + { + testName: "No Subcommand", + parameters: []string{}, + want: invalidSubscribeSubCommand, + }, { testName: "No Repository permissions", parameters: []string{"add", "group/project"}, @@ -93,6 +98,35 @@ var subscribeCommandTests = []subscribeCommandTest{ want: "Successfully subscribed to group.\nA Webhook is needed, run ```/gitlab webhook add group``` to create one now.\n**Note:** We are unable to determine the webhook status for this project. Please contact your project administrator", projectHookErr: errors.New("unable to get project hooks"), }, + { + testName: "Missing Organization/Repository", + parameters: []string{"add"}, + want: missingOrgOrRepoFromSubscribeCommand, + }, + + { + testName: "Additional Features Provided", + parameters: []string{"add", "group/project", "merges", "tag"}, + mockGitlab: true, + noAccess: true, + want: "You don't have the permissions to create subscriptions for this project.", + }, + + { + testName: "Delete Missing Repository", + parameters: []string{"delete"}, + want: specifyRepositoryMessage, + }, + { + testName: "Error Deleting Subscription", + parameters: []string{"delete", ""}, + want: "Encountered an error trying to unsubscribe. Please try again.", + }, + { + testName: "Invalid Subcommand", + parameters: []string{"unknown"}, + want: invalidSubscribeSubCommand, + }, } func TestSubscribeCommand(t *testing.T) {