Skip to content

Commit

Permalink
Fix issue in adding subscriptions (#541)
Browse files Browse the repository at this point in the history
* Fix issue in adding subscriptions

* added testcase for subscribeCommand function

* Remove commented code

---------

Co-authored-by: kshitij katiyar <[email protected]>
  • Loading branch information
raghavaggarwal2308 and Kshitij-Katiyar authored Dec 19, 2024
1 parent 0d94466 commit cf6cb00
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cf6cb00

Please sign in to comment.