Skip to content

Commit

Permalink
Clean up some deprecations and logging behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dekimsey committed Mar 22, 2023
1 parent 9d21868 commit bc440ce
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions util/lambda_trigger/lambda_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
"regexp"
Expand Down Expand Up @@ -93,7 +94,7 @@ func getBrewVersion(product string, brewType string) (string, error) {
// This formula|cask may be new. We'll assume so.
return "", errBrewVersionNotFound
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand All @@ -111,7 +112,7 @@ func triggerGithubWorkflow(event *ReleaseEvent) error {
// Create dispatch event https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event
workflowEndpoint := "https://api.github.com/repos/hashicorp/homebrew-tap/dispatches"
postBody := fmt.Sprintf("{\"event_type\": \"version-updated\", \"client_payload\":{\"name\":\"%s\",\"version\":\"%s\",\"cask\":\"%t\"}}", event.Product, event.Version, event.Cask)
fmt.Printf("POSTing to Github: %s\n", postBody)
log.Printf("POSTing to Github: %s", postBody)

httpClient := &http.Client{}
req, err := http.NewRequest("POST", workflowEndpoint, bytes.NewBufferString(postBody))
Expand All @@ -125,16 +126,16 @@ func triggerGithubWorkflow(event *ReleaseEvent) error {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Printf("Github Response: %+v", body)
body, err := io.ReadAll(resp.Body)
log.Printf("Github Response: %+v", body)
return err
}

// HandleLambdaEvent handler function to trigger github workflow
func HandleLambdaEvent(snsEvent events.SNSEvent) error {
for _, record := range snsEvent.Records {
snsRecord := record.SNS
fmt.Printf("[%s %s] Message = %s \n", record.EventSource, snsRecord.Timestamp, snsRecord.Message)
log.Printf("[%s %s] Message = %s", record.EventSource, snsRecord.Timestamp, snsRecord.Message)
message := record.SNS.Message

// Parse message to ReleaseEvent type
Expand All @@ -149,7 +150,7 @@ func HandleLambdaEvent(snsEvent events.SNSEvent) error {
if err != nil || version == nil {
return err
}
fmt.Printf("Latest version is %s\n", *version)
log.Printf("Latest version is %s", *version)
event.Version = *version
oldVersion := ""
event.Cask = isCask(event.Product)
Expand All @@ -167,9 +168,9 @@ func HandleLambdaEvent(snsEvent events.SNSEvent) error {
}

if oldVersion != "" {
fmt.Printf("Current formula/cask version is %s\n", oldVersion)
log.Printf("Current formula/cask version is %s", oldVersion)
} else {
fmt.Printf("No previous version found, assuming new formula/cask\n")
log.Printf("No previous version found, assuming new formula/cask")
}

if event.Version == oldVersion {
Expand Down

0 comments on commit bc440ce

Please sign in to comment.