From 75f7b884aded881401c58618552d0852e2fa8871 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 2 Aug 2022 10:02:05 +0200 Subject: [PATCH] Rename receiver variable for Release type, Fix bad logging statements --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index c9a002b..4a282f5 100644 --- a/main.go +++ b/main.go @@ -43,12 +43,12 @@ type Release struct { } // Generates a Textual summary for the release, intended to be used as the Jira issue summary -func (release Release) IssueSummary() string { - return fmt.Sprintf("Update %v to version %v", release.Project, release.Version) +func (r Release) IssueSummary() string { + return fmt.Sprintf("Update %v to version %v", r.Project, r.Version) } -func (release Release) JiraIssue() jira.Issue { - labels := append(config.AddLabels, release.Project) +func (r Release) JiraIssue() jira.Issue { + labels := append(config.AddLabels, r.Project) return jira.Issue{ Fields: &jira.IssueFields{ Description: "Update issue generated by https://github.2rioffice.com/platform/jelease using newreleases.io.", @@ -62,7 +62,7 @@ func (release Release) JiraIssue() jira.Issue { Name: config.DefaultStatus, }, Labels: labels, - Summary: release.IssueSummary(), + Summary: r.IssueSummary(), }, } } @@ -87,7 +87,7 @@ func handlePostWebhook(w http.ResponseWriter, r *http.Request) { err := decoder.Decode(&release) if err != nil { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) - logger.Printf("Couldn't decode request body to json: %v\n error: %v\n", r.Body, err) + logger.Printf("failed to decode request body to json with error: %v\n", err) return } @@ -98,9 +98,9 @@ func handlePostWebhook(w http.ResponseWriter, r *http.Request) { body, readErr := io.ReadAll(resp.Body) errCtx := errors.New("error response from Jira when searching previous issues") if readErr != nil { - logger.Printf("%v: %v. Failed to decode response body: %v", errCtx, err, string(body)) + logger.Println(fmt.Errorf("%v: %w. Failed to decode response body: %v", errCtx, err, readErr).Error()) } else { - logger.Printf("%v: %v. Response body: %v", errCtx, err, string(body)) + logger.Println(fmt.Errorf("%v: %w. Response body: %v", errCtx, err, string(body)).Error()) } http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return @@ -170,7 +170,7 @@ func handlePostWebhook(w http.ResponseWriter, r *http.Request) { if readErr != nil { logger.Printf("%v: %v. Failed to decode response body: %v", errCtx, err, readErr) } else { - logger.Printf("%v: %v. Response body: %v", errCtx, err, body) + logger.Printf("%v: %v. Response body: %v", errCtx, err, string(body)) } http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return