From 38186090f63e4359419f99c4f2405ff444e2c85a Mon Sep 17 00:00:00 2001 From: Kshitij Katiyar Date: Tue, 3 Oct 2023 17:17:18 +0530 Subject: [PATCH 1/5] [MI-3583]: Added a message to create subscription after running pipeline --- server/command.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/command.go b/server/command.go index f115b0d24..6bb6bb220 100644 --- a/server/command.go +++ b/server/command.go @@ -738,6 +738,30 @@ func (p *Plugin) pipelineRunCommand(ctx context.Context, namespace, ref, channel txt += fmt.Sprintf("**Ref**: %s\n", pipelineInfo.Ref) txt += fmt.Sprintf("**Triggered By**: %s\n", pipelineInfo.User) txt += fmt.Sprintf("**Visit pipeline [here](%s)** \n\n", pipelineInfo.WebURL) + + subs, err := p.GetSubscriptionsByChannel(channelID) + if err != nil { + return err.Error() + } + if len(subs) == 0 { + txt += "###### Currently there are no subscriptions present in this channel\n" + txt += fmt.Sprintf("You can create a subscription for pipeline by running the command `/gitlab subscriptions add %s pipeline`", namespace) + } else { + var isPipelineSubscriptionPresent bool + subscriptionFeatures := "pipeline" + for _, sub := range subs { + if sub.Repository == namespace { + subscriptionFeatures = sub.Features + " ," + subscriptionFeatures + if sub.Features == "pipeline" { + isPipelineSubscriptionPresent = true + } + } + } + if !isPipelineSubscriptionPresent { + txt += "###### Currently there are no subscriptions for pipeline present in this channel\n" + txt += fmt.Sprintf("You can create a subscription for pipline by running the command `/gitlab subscriptions add %s %s`", namespace, subscriptionFeatures) + } + } return txt } From 219fe563c26e496ce9f3ac8e9b8fd3999b8d31df Mon Sep 17 00:00:00 2001 From: Kshitij Katiyar Date: Thu, 5 Oct 2023 11:53:53 +0530 Subject: [PATCH 2/5] [MI-3583]: Improved the structure of if statement --- server/command.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/server/command.go b/server/command.go index 6bb6bb220..c5a9103ba 100644 --- a/server/command.go +++ b/server/command.go @@ -746,21 +746,21 @@ func (p *Plugin) pipelineRunCommand(ctx context.Context, namespace, ref, channel if len(subs) == 0 { txt += "###### Currently there are no subscriptions present in this channel\n" txt += fmt.Sprintf("You can create a subscription for pipeline by running the command `/gitlab subscriptions add %s pipeline`", namespace) - } else { - var isPipelineSubscriptionPresent bool - subscriptionFeatures := "pipeline" - for _, sub := range subs { - if sub.Repository == namespace { - subscriptionFeatures = sub.Features + " ," + subscriptionFeatures - if sub.Features == "pipeline" { - isPipelineSubscriptionPresent = true - } + return txt + } + var isPipelineSubscriptionPresent bool + subscriptionFeatures := "pipeline" + for _, sub := range subs { + if sub.Repository == namespace { + subscriptionFeatures = sub.Features + " ," + subscriptionFeatures + if sub.Features == "pipeline" { + isPipelineSubscriptionPresent = true } } - if !isPipelineSubscriptionPresent { - txt += "###### Currently there are no subscriptions for pipeline present in this channel\n" - txt += fmt.Sprintf("You can create a subscription for pipline by running the command `/gitlab subscriptions add %s %s`", namespace, subscriptionFeatures) - } + } + if !isPipelineSubscriptionPresent { + txt += "###### Currently there are no subscriptions for pipeline present in this channel\n" + txt += fmt.Sprintf("You can create a subscription for pipline by running the command `/gitlab subscriptions add %s %s`", namespace, subscriptionFeatures) } return txt } From 6462a00c5324b6cde94706a2caea83a90ada8a46 Mon Sep 17 00:00:00 2001 From: Kshitij Katiyar Date: Thu, 5 Oct 2023 12:00:51 +0530 Subject: [PATCH 3/5] [MI-3583]: Removed extra space in variable --- server/command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/command.go b/server/command.go index c5a9103ba..a8caca8d5 100644 --- a/server/command.go +++ b/server/command.go @@ -746,7 +746,7 @@ func (p *Plugin) pipelineRunCommand(ctx context.Context, namespace, ref, channel if len(subs) == 0 { txt += "###### Currently there are no subscriptions present in this channel\n" txt += fmt.Sprintf("You can create a subscription for pipeline by running the command `/gitlab subscriptions add %s pipeline`", namespace) - return txt + return txt } var isPipelineSubscriptionPresent bool subscriptionFeatures := "pipeline" From 261176f84f4ffee7492cba6469dbf7a642398d04 Mon Sep 17 00:00:00 2001 From: Kshitij Katiyar Date: Mon, 9 Oct 2023 15:21:34 +0530 Subject: [PATCH 4/5] [MI-3583]: Added a new line and constant --- server/command.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/command.go b/server/command.go index a8caca8d5..39855824d 100644 --- a/server/command.go +++ b/server/command.go @@ -86,7 +86,7 @@ const ( commandAdd = "add" commandDelete = "delete" commandList = "list" - + featurePipeline = "pipeline" commandRun = "run" ) @@ -748,12 +748,13 @@ func (p *Plugin) pipelineRunCommand(ctx context.Context, namespace, ref, channel txt += fmt.Sprintf("You can create a subscription for pipeline by running the command `/gitlab subscriptions add %s pipeline`", namespace) return txt } + var isPipelineSubscriptionPresent bool - subscriptionFeatures := "pipeline" + subscriptionFeatures := featurePipeline for _, sub := range subs { if sub.Repository == namespace { subscriptionFeatures = sub.Features + " ," + subscriptionFeatures - if sub.Features == "pipeline" { + if sub.Features == featurePipeline { isPipelineSubscriptionPresent = true } } From 63fdec2dfc1068112eea5048575c5f2d4fdf43dd Mon Sep 17 00:00:00 2001 From: Kshitij Katiyar Date: Mon, 9 Oct 2023 15:36:50 +0530 Subject: [PATCH 5/5] [MI-3583]: Moved the constant --- server/command.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/command.go b/server/command.go index 39855824d..3c6d56f65 100644 --- a/server/command.go +++ b/server/command.go @@ -86,8 +86,9 @@ const ( commandAdd = "add" commandDelete = "delete" commandList = "list" + commandRun = "run" + featurePipeline = "pipeline" - commandRun = "run" ) const (