From 691f4b19e297e5eebc34c3f8c85c943646c3ccd7 Mon Sep 17 00:00:00 2001 From: anandrkskd Date: Tue, 5 Jan 2021 20:02:20 +0530 Subject: [PATCH 1/2] add comments and resolving lint errors --- pkg/ci-firewall/cli/genericclioptions/runnable.go | 1 + pkg/requestor/requestor.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/ci-firewall/cli/genericclioptions/runnable.go b/pkg/ci-firewall/cli/genericclioptions/runnable.go index cc63b64..12c4a61 100644 --- a/pkg/ci-firewall/cli/genericclioptions/runnable.go +++ b/pkg/ci-firewall/cli/genericclioptions/runnable.go @@ -25,6 +25,7 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { LogErrorAndExit(o.Run(), "") } +//AddStripANSIColorFlag remove ANSI color form log func AddStripANSIColorFlag(cmd *cobra.Command, v *bool) { cmd.Flags().BoolVar(v, "stripansicolor", false, "If true, then ANSI color will be stripped before printing the logs") } diff --git a/pkg/requestor/requestor.go b/pkg/requestor/requestor.go index 4efa83c..7cfacd8 100644 --- a/pkg/requestor/requestor.go +++ b/pkg/requestor/requestor.go @@ -42,6 +42,7 @@ func NewRequestor(amqpURI, sendqName, exchangeName, topic, repoURL, kind, target return r } +//initQueues initializes rabbitmq queues for PR, Branch or Tag. Returns error if fails func (r *Requestor) initQueus() error { if r.kind != messages.RequestTypePR && r.kind != messages.RequestTypeBranch && r.kind != messages.RequestTypeTag { return fmt.Errorf("kind should be %s, %s or %s", messages.RequestTypePR, messages.RequestTypeBranch, messages.RequestTypeTag) @@ -57,15 +58,16 @@ func (r *Requestor) initQueus() error { return nil } +//sendBuildRequest creates build request. Returns error if fails func (r *Requestor) sendBuildRequest() error { - var err error - err = r.sendq.Publish(messages.NewRemoteBuildRequestMessage(r.repoURL, r.kind, r.target, r.setupScript, r.runscript, r.recieveQueueName, r.runScriptURL, r.mainBranch)) + var err error = r.sendq.Publish(messages.NewRemoteBuildRequestMessage(r.repoURL, r.kind, r.target, r.setupScript, r.runscript, r.recieveQueueName, r.runScriptURL, r.mainBranch)) if err != nil { return fmt.Errorf("failed to send build request %w", err) } return nil } +// consumeMessages send ack for finished work on a delivery(i.e. - successfull execution of request from rcvq), and returns error if fails func (r *Requestor) consumeMessages() error { err := r.rcvq.Consume(func(deliveries <-chan amqp.Delivery, done chan error) { success := true @@ -107,7 +109,7 @@ func (r *Requestor) consumeMessages() error { if success { done <- nil } else { - done <- fmt.Errorf("Failed the test, see logs above ^") + done <- fmt.Errorf("failed the test, see logs above ^") } return } @@ -141,6 +143,7 @@ func (r *Requestor) Done() chan error { return r.done } +//Shutdown shuts down the requestor and worker , returns error if any func (r *Requestor) ShutDown() error { err := r.sendq.Shutdown() if err != nil { From 0e3f9fc4a278a1da160633883ff15b675f6ad187 Mon Sep 17 00:00:00 2001 From: anandrkskd Date: Wed, 6 Jan 2021 17:25:50 +0530 Subject: [PATCH 2/2] adding comments and resolve a typo --- pkg/jenkins/jenkins.go | 1 + pkg/requestor/requestor.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/jenkins/jenkins.go b/pkg/jenkins/jenkins.go index af99cf1..1761c81 100644 --- a/pkg/jenkins/jenkins.go +++ b/pkg/jenkins/jenkins.go @@ -8,6 +8,7 @@ import ( "github.com/bndr/gojenkins" ) +//CleanupOldBuilds stops old jenkins jobs which are running, or else returns error func CleanupOldBuilds(url, username, password, jobName string, currentBuild int, filter func(params map[string]string) bool) error { jenkins, err := gojenkins.CreateJenkins(nil, url, username, password).Init() if err != nil { diff --git a/pkg/requestor/requestor.go b/pkg/requestor/requestor.go index 7cfacd8..4086034 100644 --- a/pkg/requestor/requestor.go +++ b/pkg/requestor/requestor.go @@ -43,7 +43,7 @@ func NewRequestor(amqpURI, sendqName, exchangeName, topic, repoURL, kind, target } //initQueues initializes rabbitmq queues for PR, Branch or Tag. Returns error if fails -func (r *Requestor) initQueus() error { +func (r *Requestor) initQueues() error { if r.kind != messages.RequestTypePR && r.kind != messages.RequestTypeBranch && r.kind != messages.RequestTypeTag { return fmt.Errorf("kind should be %s, %s or %s", messages.RequestTypePR, messages.RequestTypeBranch, messages.RequestTypeTag) } @@ -124,7 +124,7 @@ func (r *Requestor) consumeMessages() error { } func (r *Requestor) Run() error { - err := r.initQueus() + err := r.initQueues() if err != nil { return err }