Skip to content

Commit

Permalink
Embed files in membership-checker (GoogleCloudPlatform#7794)
Browse files Browse the repository at this point in the history
* embed files in membership-checker

* change to embed the file as a string instead of a filesystem
  • Loading branch information
shuyama1 authored and Madhura Phadnis committed Apr 27, 2023
1 parent 79b3bb5 commit e5475ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
13 changes: 8 additions & 5 deletions .ci/containers/membership-checker/reviewer_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
"fmt"
"net/http"
"strings"

_ "embed"
)

var (
//go:embed REVIEWER_ASSIGNMENT_COMMENT.md
reviewerAssignmentComment string
)

func requestReviewer(author, prNumber, GITHUB_TOKEN string) error {
Expand Down Expand Up @@ -153,12 +160,8 @@ func requestRandomReviewer(prNumber, GITHUB_TOKEN string) error {

func postComment(prNumber, reviewer, GITHUB_TOKEN string) error {
url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/issues/%s/comments", prNumber)
comment, err := readFile(".ci/containers/membership-checker/REVIEWER_ASSIGNMENT_COMMENT.md")
if err != nil {
return err
}

comment = strings.Replace(comment, "{{reviewer}}", reviewer, 1)
comment := strings.Replace(reviewerAssignmentComment, "{{reviewer}}", reviewer, 1)

body := map[string]string{
"body": comment,
Expand Down
9 changes: 0 additions & 9 deletions .ci/containers/membership-checker/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

"golang.org/x/exp/slices"
Expand Down Expand Up @@ -37,14 +36,6 @@ func requestCall(url, method, credentials string, result interface{}, body inter
return resp.StatusCode, nil
}

func readFile(filename string) (string, error) {
contents, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
return string(contents), nil
}

func removes(s1 []string, s2 []string) []string {
result := make([]string, 0, len(s1))

Expand Down

0 comments on commit e5475ce

Please sign in to comment.