From 1c24554fec9f557a04d67e6f32559ba9fa1c0b15 Mon Sep 17 00:00:00 2001 From: Scott Suarez Date: Thu, 19 Oct 2023 10:15:25 -0700 Subject: [PATCH] clean up container image and trigger code that is no longer needed (#9303) --- .ci/containers/membership-checker/Dockerfile | 8 - .../REVIEWER_ASSIGNMENT_COMMENT.md | 5 - .../membership-checker/build_trigger.go | 46 ----- .../membership-checker/community.go | 152 ---------------- .ci/containers/membership-checker/go.mod | 27 --- .ci/containers/membership-checker/go.sum | 135 --------------- .ci/containers/membership-checker/main.go | 131 -------------- .../membership-checker/membership.go | 95 ---------- .../membership-checker/membership_test.go | 23 --- .../membership-checker/reviewer_assignment.go | 163 ------------------ .../reviewer_assignment_test.go | 135 --------------- .ci/containers/membership-checker/utils.go | 48 ------ .../membership-checker/utils_test.go | 49 ------ .ci/gcb-changelog-checker.yml | 10 -- .ci/gcb-run-rake-tests.yml | 10 -- 15 files changed, 1037 deletions(-) delete mode 100644 .ci/containers/membership-checker/Dockerfile delete mode 100644 .ci/containers/membership-checker/REVIEWER_ASSIGNMENT_COMMENT.md delete mode 100644 .ci/containers/membership-checker/build_trigger.go delete mode 100644 .ci/containers/membership-checker/community.go delete mode 100644 .ci/containers/membership-checker/go.mod delete mode 100644 .ci/containers/membership-checker/go.sum delete mode 100644 .ci/containers/membership-checker/main.go delete mode 100644 .ci/containers/membership-checker/membership.go delete mode 100644 .ci/containers/membership-checker/membership_test.go delete mode 100644 .ci/containers/membership-checker/reviewer_assignment.go delete mode 100644 .ci/containers/membership-checker/reviewer_assignment_test.go delete mode 100644 .ci/containers/membership-checker/utils.go delete mode 100644 .ci/containers/membership-checker/utils_test.go delete mode 100644 .ci/gcb-changelog-checker.yml delete mode 100644 .ci/gcb-run-rake-tests.yml diff --git a/.ci/containers/membership-checker/Dockerfile b/.ci/containers/membership-checker/Dockerfile deleted file mode 100644 index 81f0e6b35dab..000000000000 --- a/.ci/containers/membership-checker/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM golang:1.20 - -WORKDIR /src -COPY . ./ - -RUN go build - -ENTRYPOINT [ "/src/membership-checker" ] \ No newline at end of file diff --git a/.ci/containers/membership-checker/REVIEWER_ASSIGNMENT_COMMENT.md b/.ci/containers/membership-checker/REVIEWER_ASSIGNMENT_COMMENT.md deleted file mode 100644 index 09d5bfc62936..000000000000 --- a/.ci/containers/membership-checker/REVIEWER_ASSIGNMENT_COMMENT.md +++ /dev/null @@ -1,5 +0,0 @@ -Hello! I am a robot. It looks like you are a: {{if eq .authorUserType "Community Contributor"}}Community Contributor{{else}}~Community Contributor~{{end}} {{if eq .authorUserType "Googler"}}Googler{{else}}~Googler~{{end}} {{if eq .authorUserType "Core Contributor"}}Core Contributor{{else}}~Core Contributor~{{end}}. {{if .trusted}}Tests will run automatically.{{else}}Tests will require approval to run.{{end}} - -@{{.reviewer}}, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. - -You can help make sure that review is quick by [doing a self-review](https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/) and by [running impacted tests locally](https://googlecloudplatform.github.io/magic-modules/get-started/run-provider-tests/). \ No newline at end of file diff --git a/.ci/containers/membership-checker/build_trigger.go b/.ci/containers/membership-checker/build_trigger.go deleted file mode 100644 index 2a6b90bc0cf8..000000000000 --- a/.ci/containers/membership-checker/build_trigger.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "google.golang.org/api/cloudbuild/v1" -) - -func triggerMMPresubmitRuns(projectId, repoName, commitSha string, substitutions map[string]string) error { - presubmitTriggerId, ok := os.LookupEnv("GENERATE_DIFFS_TRIGGER") - if !ok { - return fmt.Errorf("Did not provide GENERATE_DIFFS_TRIGGER environment variable") - } - - err := triggerCloudBuildRun(projectId, presubmitTriggerId, repoName, commitSha, substitutions) - if err != nil { - return err - } - - return nil -} - -func triggerCloudBuildRun(projectId, triggerId, repoName, commitSha string, substitutions map[string]string) error { - ctx := context.Background() - c, err := cloudbuild.NewService(ctx) - if err != nil { - return fmt.Errorf("Failed to create Cloud Build service client: %s", err) - } - - repoSource := &cloudbuild.RepoSource{ - ProjectId: projectId, - RepoName: repoName, - CommitSha: commitSha, - Substitutions: substitutions, - } - - _, err = c.Projects.Triggers.Run(projectId, triggerId, repoSource).Do() - if err != nil { - return fmt.Errorf("Failed to create Cloud Build run: %s", err) - } - - fmt.Println("Started Cloud Build Run: ", triggerId) - return nil -} diff --git a/.ci/containers/membership-checker/community.go b/.ci/containers/membership-checker/community.go deleted file mode 100644 index 18062d370018..000000000000 --- a/.ci/containers/membership-checker/community.go +++ /dev/null @@ -1,152 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "google.golang.org/api/cloudbuild/v1" -) - -func approveCommunityChecker(prNumber, projectId, commitSha string) error { - buildId, err := getPendingBuildId(projectId, commitSha) - if err != nil { - return err - } - - if buildId == "" { - return fmt.Errorf("Failed to find pending build for PR %s", prNumber) - } - - err = approveBuild(projectId, buildId) - if err != nil { - return err - } - - return nil -} - -func postAwaitingApprovalBuildLink(prNumber, GITHUB_TOKEN, projectId, commitSha string) error { - buildId, err := getPendingBuildId(projectId, commitSha) - if err != nil { - return err - } - - if buildId == "" { - return fmt.Errorf("Failed to find pending build for PR %s", prNumber) - } - - targetUrl := fmt.Sprintf("https://console.cloud.google.com/cloud-build/builds;region=global/%s?project=%s", buildId, projectId) - - postBody := map[string]string{ - "context": "Approve Build", - "state": "success", - "target_url": targetUrl, - } - - err = postBuildStatus(prNumber, GITHUB_TOKEN, commitSha, postBody) - if err != nil { - return err - } - - return nil -} - -func postBuildStatus(prNumber, GITHUB_TOKEN, commitSha string, body map[string]string) error { - - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/%s", commitSha) - - _, err := requestCall(url, "POST", GITHUB_TOKEN, nil, body) - if err != nil { - return err - } - - fmt.Printf("Successfully posted community-checker build link to pull request %s\n", prNumber) - - return nil -} - -func getPendingBuildId(projectId, commitSha string) (string, error) { - COMMUNITY_CHECKER_TRIGGER, ok := os.LookupEnv("COMMUNITY_CHECKER_TRIGGER") - if !ok { - return "", fmt.Errorf("Did not provide COMMUNITY_CHECKER_TRIGGER environment variable") - } - - ctx := context.Background() - - c, err := cloudbuild.NewService(ctx) - if err != nil { - return "", err - } - - filter := fmt.Sprintf("trigger_id=%s AND status=PENDING", COMMUNITY_CHECKER_TRIGGER) - // Builds will be sorted by createTime, descending order. - // 50 should be enough to include the one needs auto approval - pageSize := int64(50) - - builds, err := c.Projects.Builds.List(projectId).Filter(filter).PageSize(pageSize).Do() - if err != nil { - return "", err - } - - for _, build := range builds.Builds { - if build.Substitutions["COMMIT_SHA"] == commitSha { - return build.Id, nil - } - } - - return "", nil -} - -func approveBuild(projectId, buildId string) error { - ctx := context.Background() - - c, err := cloudbuild.NewService(ctx) - if err != nil { - return err - } - - name := fmt.Sprintf("projects/%s/builds/%s", projectId, buildId) - - approveBuildRequest := &cloudbuild.ApproveBuildRequest{ - ApprovalResult: &cloudbuild.ApprovalResult{ - Decision: "APPROVED", - }, - } - - _, err = c.Projects.Builds.Approve(name, approveBuildRequest).Do() - if err != nil { - return err - } - - fmt.Println("Auto approved build ", buildId) - - return nil -} - -func addAwaitingApprovalLabel(prNumber, GITHUB_TOKEN string) error { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/issues/%s/labels", prNumber) - - body := map[string][]string{ - "labels": []string{"awaiting-approval"}, - } - _, err := requestCall(url, "POST", GITHUB_TOKEN, nil, body) - - if err != nil { - return fmt.Errorf("Failed to add awaiting approval label: %s", err) - } - - return nil - -} - -func removeAwaitingApprovalLabel(prNumber, GITHUB_TOKEN string) error { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/issues/%s/labels/awaiting-approval", prNumber) - _, err := requestCall(url, "DELETE", GITHUB_TOKEN, nil, nil) - - if err != nil { - return fmt.Errorf("Failed to remove awaiting approval label: %s", err) - } - - return nil -} diff --git a/.ci/containers/membership-checker/go.mod b/.ci/containers/membership-checker/go.mod deleted file mode 100644 index 903d7b9a2c54..000000000000 --- a/.ci/containers/membership-checker/go.mod +++ /dev/null @@ -1,27 +0,0 @@ -module membership-checker - -go 1.20 - -require ( - golang.org/x/exp v0.0.0-20230314191032-db074128a8ec - google.golang.org/api v0.112.0 -) - -require ( - cloud.google.com/go/compute v1.18.0 // indirect - cloud.google.com/go/compute/metadata v0.2.3 // indirect - github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - github.com/golang/protobuf v1.5.2 // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect - github.com/googleapis/gax-go/v2 v2.7.0 // indirect - go.opencensus.io v0.24.0 // indirect - golang.org/x/net v0.8.0 // indirect - golang.org/x/oauth2 v0.6.0 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488 // indirect - google.golang.org/grpc v1.53.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect -) diff --git a/.ci/containers/membership-checker/go.sum b/.ci/containers/membership-checker/go.sum deleted file mode 100644 index da929d371259..000000000000 --- a/.ci/containers/membership-checker/go.sum +++ /dev/null @@ -1,135 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.110.0 h1:Zc8gqp3+a9/Eyph2KDmcGaPtbKRIoqq4YTlL4NMD0Ys= -cloud.google.com/go/compute v1.18.0 h1:FEigFqoDbys2cvFkZ9Fjq4gnHBP55anJ0yQyau2f9oY= -cloud.google.com/go/compute v1.18.0/go.mod h1:1X7yHxec2Ga+Ss6jPyjxRxpu2uu7PLgsOVXvgU0yacs= -cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= -cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= -cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9aurXEpJX+U6FLtpYTdC3R06k= -github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= -github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ= -github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= -go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230314191032-db074128a8ec h1:pAv+d8BM2JNnNctsLJ6nnZ6NqXT8N4+eauvZSb3P0I0= -golang.org/x/exp v0.0.0-20230314191032-db074128a8ec/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw= -golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.112.0 h1:iDmzvZ4C086R3+en4nSyIf07HlQKMOX1Xx2dmia/+KQ= -google.golang.org/api v0.112.0/go.mod h1:737UfWHNsOq4F3REUTmb+GN9pugkgNLCayLTfoIKpPc= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488 h1:QQF+HdiI4iocoxUjjpLgvTYDHKm99C/VtTBFnfiCJos= -google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488/go.mod h1:TvhZT5f700eVlTNwND1xoEZQeWTB2RY/65kplwl/bFA= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= -google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/.ci/containers/membership-checker/main.go b/.ci/containers/membership-checker/main.go deleted file mode 100644 index d9a1d2bb0dbd..000000000000 --- a/.ci/containers/membership-checker/main.go +++ /dev/null @@ -1,131 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - GITHUB_TOKEN, ok := os.LookupEnv("GITHUB_TOKEN") - if !ok { - fmt.Println("Did not provide GITHUB_TOKEN environment variable") - os.Exit(1) - } - if len(os.Args) <= 7 { - fmt.Println("Not enough arguments") - os.Exit(1) - } - - projectId := "graphite-docker-images" - repoName := "magic-modules" - - target := os.Args[1] - fmt.Println("Trigger Target: ", target) - - prNumber := os.Args[2] - fmt.Println("PR Number: ", prNumber) - - commitSha := os.Args[3] - fmt.Println("Commit SHA: ", commitSha) - - branchName := os.Args[4] - fmt.Println("Branch Name: ", branchName) - - headRepoUrl := os.Args[5] - fmt.Println("Head Repo URL: ", headRepoUrl) - - headBranch := os.Args[6] - fmt.Println("Head Branch: ", headBranch) - - baseBranch := os.Args[7] - fmt.Println("Base Branch: ", baseBranch) - - substitutions := map[string]string{ - "BRANCH_NAME": branchName, - "_PR_NUMBER": prNumber, - "_HEAD_REPO_URL": headRepoUrl, - "_HEAD_BRANCH": headBranch, - "_BASE_BRANCH": baseBranch, - } - - author, err := getPullRequestAuthor(prNumber, GITHUB_TOKEN) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - authorUserType := getUserType(author, GITHUB_TOKEN) - trusted := authorUserType == coreContributorUserType || authorUserType == googlerUserType - - if target == "auto_run" && authorUserType != coreContributorUserType { - fmt.Println("Not core contributor - assigning reviewer") - - firstRequestedReviewer, err := getPullRequestRequestedReviewer(prNumber, GITHUB_TOKEN) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - previouslyInvolvedReviewers, err := getPullRequestPreviousAssignedReviewers(prNumber, GITHUB_TOKEN) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - reviewersToRequest, newPrimaryReviewer := chooseReviewers(firstRequestedReviewer, previouslyInvolvedReviewers) - - for _, reviewer := range reviewersToRequest { - err = requestPullRequestReviewer(prNumber, reviewer, GITHUB_TOKEN) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - } - - if newPrimaryReviewer != "" { - comment := formatReviewerComment(newPrimaryReviewer, authorUserType, trusted) - err = postComment(prNumber, comment, GITHUB_TOKEN, authorUserType) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - } - } - - // auto_run(contributor-membership-checker) will be run on every commit or /gcbrun: - // only triggers builds for trusted users - - // needs_approval(community-checker) will be run after approval: - // 1. will be auto approved (by contributor-membership-checker) for trusted users - // 2. needs approval from team reviewer via cloud build for untrusted users - // 3. only triggers build for untrusted users (because trusted users will be handled by auto_run) - if (target == "auto_run" && trusted) || (target == "needs_approval" && !trusted) { - err = triggerMMPresubmitRuns(projectId, repoName, commitSha, substitutions) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - } - - // in contributor-membership-checker job: - // 1. auto approve community-checker run for trusted users - // 2. add awaiting-approval label to external contributor PRs - if target == "auto_run" { - if trusted { - err = approveCommunityChecker(prNumber, projectId, commitSha) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - } else { - addAwaitingApprovalLabel(prNumber, GITHUB_TOKEN) - postAwaitingApprovalBuildLink(prNumber, GITHUB_TOKEN, projectId, commitSha) - } - } - - // in community-checker job: - // remove awaiting-approval label from external contributor PRs - if target == "needs_approval" { - removeAwaitingApprovalLabel(prNumber, GITHUB_TOKEN) - } -} diff --git a/.ci/containers/membership-checker/membership.go b/.ci/containers/membership-checker/membership.go deleted file mode 100644 index 812509795a15..000000000000 --- a/.ci/containers/membership-checker/membership.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - "time" - - "golang.org/x/exp/slices" -) - -var ( - // This is for the random-assignee rotation. - reviewerRotation = []string{ - "slevenick", - "c2thorn", - "rileykarson", - "melinath", - "ScottSuarez", - "shuyama1", - "SarahFrench", - "roaks3", - "zli82016", - "trodge", - "hao-nan-li", - "NickElliot", - } - - // This is for new team members who are onboarding - trustedContributors = []string{} - - // This is for reviewers who are "on vacation": will not receive new review assignments but will still receive re-requests for assigned PRs. - onVacationReviewers = []string{ - } -) - -type userType int64 - -const ( - communityUserType userType = iota - googlerUserType - coreContributorUserType -) - -func (ut userType) String() string { - switch ut { - case googlerUserType: - return "Googler" - case coreContributorUserType: - return "Core Contributor" - default: - return "Community Contributor" - } -} - -// Check if a user is team member to not request a random reviewer -func isTeamMember(author string) bool { - return slices.Contains(reviewerRotation, author) || slices.Contains(trustedContributors, author) -} - -func isTeamReviewer(reviewer string) bool { - return slices.Contains(reviewerRotation, reviewer) -} - -func getUserType(user, GITHUB_TOKEN string) userType { - if isTeamMember(user) { - fmt.Println("User is a team member") - return coreContributorUserType - } - - if isOrgMember(user, "GoogleCloudPlatform", GITHUB_TOKEN) { - fmt.Println("User is a GCP org member") - return googlerUserType - } - - if isOrgMember(user, "googlers", GITHUB_TOKEN) { - fmt.Println("User is a googlers org member") - return googlerUserType - } - - return communityUserType -} - -func isOrgMember(author, org, GITHUB_TOKEN string) bool { - url := fmt.Sprintf("https://api.github.com/orgs/%s/members/%s", org, author) - res, _ := requestCall(url, "GET", GITHUB_TOKEN, nil, nil) - - return res != 404 -} - -func getRandomReviewer() string { - availableReviewers := removes(reviewerRotation, onVacationReviewers) - rand.Seed(time.Now().UnixNano()) - reviewer := availableReviewers[rand.Intn(len(availableReviewers))] - return reviewer -} diff --git a/.ci/containers/membership-checker/membership_test.go b/.ci/containers/membership-checker/membership_test.go deleted file mode 100644 index 3e3e2b2989dd..000000000000 --- a/.ci/containers/membership-checker/membership_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "testing" - - "golang.org/x/exp/slices" -) - -func TestTrustedContributors(t *testing.T) { - for _, member := range trustedContributors { - if slices.Contains(reviewerRotation, member) { - t.Fatalf(`%v should not be on reviewerRotation list`, member) - } - } -} - -func TestOnVacationReviewers(t *testing.T) { - for _, member := range onVacationReviewers { - if !slices.Contains(reviewerRotation, member) { - t.Fatalf(`%v is not on reviewerRotation list`, member) - } - } -} diff --git a/.ci/containers/membership-checker/reviewer_assignment.go b/.ci/containers/membership-checker/reviewer_assignment.go deleted file mode 100644 index 4dca8ff47e22..000000000000 --- a/.ci/containers/membership-checker/reviewer_assignment.go +++ /dev/null @@ -1,163 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "strings" - "text/template" - - _ "embed" -) - -var ( - //go:embed REVIEWER_ASSIGNMENT_COMMENT.md - reviewerAssignmentComment string -) - -// Returns a list of users to request review from, as well as a new primary reviewer if this is the first run. -func chooseReviewers(firstRequestedReviewer string, previouslyInvolvedReviewers []string) (reviewersToRequest []string, newPrimaryReviewer string) { - hasPrimaryReviewer := false - newPrimaryReviewer = "" - - if firstRequestedReviewer != "" { - hasPrimaryReviewer = true - } - - if previouslyInvolvedReviewers != nil { - for _, reviewer := range previouslyInvolvedReviewers { - if isTeamReviewer(reviewer) { - hasPrimaryReviewer = true - reviewersToRequest = append(reviewersToRequest, reviewer) - } - } - } - - if !hasPrimaryReviewer { - newPrimaryReviewer = getRandomReviewer() - reviewersToRequest = append(reviewersToRequest, newPrimaryReviewer) - } - - return reviewersToRequest, newPrimaryReviewer -} - -func getPullRequestAuthor(prNumber, GITHUB_TOKEN string) (string, error) { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/issues/%s", prNumber) - - var pullRequest struct { - User struct { - Login string `json:"login"` - } `json:"user"` - } - - _, err := requestCall(url, "GET", GITHUB_TOKEN, &pullRequest, nil) - if err != nil { - return "", err - } - - return pullRequest.User.Login, nil -} - -func getPullRequestRequestedReviewer(prNumber, GITHUB_TOKEN string) (string, error) { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/pulls/%s/requested_reviewers", prNumber) - - var requestedReviewers struct { - Users []struct { - Login string `json:"login"` - } `json:"users"` - } - - _, err := requestCall(url, "GET", GITHUB_TOKEN, &requestedReviewers, nil) - if err != nil { - return "", err - } - - if requestedReviewers.Users == nil || len(requestedReviewers.Users) == 0 { - return "", nil - } - - return requestedReviewers.Users[0].Login, nil -} - -func getPullRequestPreviousAssignedReviewers(prNumber, GITHUB_TOKEN string) ([]string, error) { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/pulls/%s/reviews", prNumber) - - var reviews []struct { - User struct { - Login string `json:"login"` - } `json:"user"` - } - - _, err := requestCall(url, "GET", GITHUB_TOKEN, &reviews, nil) - if err != nil { - return nil, err - } - - previousAssignedReviewers := map[string]struct{}{} - for _, review := range reviews { - previousAssignedReviewers[review.User.Login] = struct{}{} - } - - result := []string{} - for key, _ := range previousAssignedReviewers { - result = append(result, key) - } - - return result, nil -} - -func requestPullRequestReviewer(prNumber, assignee, GITHUB_TOKEN string) error { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/pulls/%s/requested_reviewers", prNumber) - - body := map[string][]string{ - "reviewers": []string{assignee}, - "team_reviewers": []string{}, - } - - reqStatusCode, err := requestCall(url, "POST", GITHUB_TOKEN, nil, body) - if err != nil { - return err - } - - if reqStatusCode != http.StatusCreated { - return fmt.Errorf("Error adding reviewer for PR %s", prNumber) - } - - fmt.Printf("Successfully added reviewer %s to pull request %s\n", assignee, prNumber) - - return nil -} - -func formatReviewerComment(newPrimaryReviewer string, authorUserType userType, trusted bool) string { - tmpl, err := template.New("REVIEWER_ASSIGNMENT_COMMENT.md").Parse(reviewerAssignmentComment) - if err != nil { - panic(fmt.Sprintf("Unable to parse REVIEWER_ASSIGNMENT_COMMENT.md: %s", err)) - } - sb := new(strings.Builder) - tmpl.Execute(sb, map[string]interface{}{ - "reviewer": newPrimaryReviewer, - "authorUserType": authorUserType.String(), - "trusted": trusted, - }) - return sb.String() -} - -func postComment(prNumber, comment, GITHUB_TOKEN string, authorUserType userType) error { - url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/issues/%s/comments", prNumber) - - body := map[string]string{ - "body": comment, - } - - reqStatusCode, err := requestCall(url, "POST", GITHUB_TOKEN, nil, body) - if err != nil { - return err - } - - if reqStatusCode != http.StatusCreated { - return fmt.Errorf("Error posting comment for PR %s", prNumber) - } - - fmt.Printf("Successfully posted comment to pull request %s\n", prNumber) - - return nil -} diff --git a/.ci/containers/membership-checker/reviewer_assignment_test.go b/.ci/containers/membership-checker/reviewer_assignment_test.go deleted file mode 100644 index 4763b650ee1b..000000000000 --- a/.ci/containers/membership-checker/reviewer_assignment_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package main - -import ( - "fmt" - "strings" - "testing" - - "golang.org/x/exp/slices" -) - -func TestChooseReviewers(t *testing.T) { - cases := map[string]struct { - FirstRequestedReviewer string - PreviouslyInvolvedReviewers []string - ExpectReviewersFromList, ExpectSpecificReviewers []string - ExpectPrimaryReviewer bool - }{ - "no previous review requests assigns new reviewer from team": { - FirstRequestedReviewer: "", - PreviouslyInvolvedReviewers: []string{}, - ExpectReviewersFromList: removes(reviewerRotation, onVacationReviewers), - ExpectPrimaryReviewer: true, - }, - "first requested reviewer means that primary reviewer was already selected": { - FirstRequestedReviewer: "foobar", - PreviouslyInvolvedReviewers: []string{}, - ExpectPrimaryReviewer: false, - }, - "previously involved team member reviewers should have review requested and mean that primary reviewer was already selected": { - FirstRequestedReviewer: "", - PreviouslyInvolvedReviewers: []string{reviewerRotation[0]}, - ExpectSpecificReviewers: []string{reviewerRotation[0]}, - ExpectPrimaryReviewer: false, - }, - "previously involved reviewers that are not team members are ignored": { - FirstRequestedReviewer: "", - PreviouslyInvolvedReviewers: []string{"foobar"}, - ExpectReviewersFromList: removes(reviewerRotation, onVacationReviewers), - ExpectPrimaryReviewer: true, - }, - "only previously involved team member reviewers will have review requested": { - FirstRequestedReviewer: "", - PreviouslyInvolvedReviewers: []string{reviewerRotation[0], "foobar", reviewerRotation[1]}, - ExpectSpecificReviewers: []string{reviewerRotation[0], reviewerRotation[1]}, - ExpectPrimaryReviewer: false, - }, - "primary reviewer will not have review requested even if other team members previously reviewed": { - FirstRequestedReviewer: reviewerRotation[1], - PreviouslyInvolvedReviewers: []string{reviewerRotation[0]}, - ExpectSpecificReviewers: []string{reviewerRotation[0]}, - ExpectPrimaryReviewer: false, - }, - } - - for tn, tc := range cases { - tc := tc - t.Run(tn, func(t *testing.T) { - t.Parallel() - reviewers, primaryReviewer := chooseReviewers(tc.FirstRequestedReviewer, tc.PreviouslyInvolvedReviewers) - if tc.ExpectPrimaryReviewer && primaryReviewer == "" { - t.Error("wanted primary reviewer to be returned; got none") - } - if !tc.ExpectPrimaryReviewer && primaryReviewer != "" { - t.Errorf("wanted no primary reviewer; got %s", primaryReviewer) - } - if len(tc.ExpectReviewersFromList) > 0 { - for _, reviewer := range reviewers { - if !slices.Contains(tc.ExpectReviewersFromList, reviewer) { - t.Errorf("wanted reviewer %s to be in list %v but they were not", reviewer, tc.ExpectReviewersFromList) - } - } - } - if len(tc.ExpectSpecificReviewers) > 0 { - if !slices.Equal(reviewers, tc.ExpectSpecificReviewers) { - t.Errorf("wanted reviewers to be %v; instead got %v", tc.ExpectSpecificReviewers, reviewers) - } - } - }) - } -} - -func TestFormatReviewerComment(t *testing.T) { - cases := map[string]struct { - Reviewer string - AuthorUserType userType - Trusted bool - }{ - "community contributor": { - Reviewer: "foobar", - AuthorUserType: communityUserType, - Trusted: false, - }, - "googler": { - Reviewer: "foobar", - AuthorUserType: googlerUserType, - Trusted: true, - }, - "core contributor": { - Reviewer: "foobar", - AuthorUserType: coreContributorUserType, - Trusted: true, - }, - } - - for tn, tc := range cases { - tc := tc - t.Run(tn, func(t *testing.T) { - t.Parallel() - comment := formatReviewerComment(tc.Reviewer, tc.AuthorUserType, tc.Trusted) - t.Log(comment) - if !strings.Contains(comment, fmt.Sprintf("@%s", tc.Reviewer)) { - t.Errorf("wanted comment to contain @%s; does not.", tc.Reviewer) - } - if !strings.Contains(comment, tc.AuthorUserType.String()) { - t.Errorf("wanted comment to contain user type (%s); does not.", tc.AuthorUserType.String()) - } - if strings.Contains(comment, fmt.Sprintf("~%s~", tc.AuthorUserType.String())) { - t.Errorf("wanted user type (%s) in comment to not be crossed out, but it is", tc.AuthorUserType.String()) - } - for _, ut := range []userType{communityUserType, googlerUserType, coreContributorUserType} { - if ut != tc.AuthorUserType && !strings.Contains(comment, fmt.Sprintf("~%s~", ut.String())) { - t.Errorf("wanted other user type (%s) in comment to be crossed out, but it is not", ut) - } - } - - if tc.Trusted && !strings.Contains(comment, "Tests will run automatically") { - t.Errorf("wanted comment to say tests will run automatically; does not") - } - if !tc.Trusted && !strings.Contains(comment, "Tests will require approval") { - t.Errorf("wanted comment to say tests will require approval; does not") - } - }) - - } -} diff --git a/.ci/containers/membership-checker/utils.go b/.ci/containers/membership-checker/utils.go deleted file mode 100644 index b08a7572691e..000000000000 --- a/.ci/containers/membership-checker/utils.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - - "golang.org/x/exp/slices" -) - -func requestCall(url, method, credentials string, result interface{}, body interface{}) (int, error) { - client := &http.Client{} - jsonBody, err := json.Marshal(body) - if err != nil { - return 1, fmt.Errorf("Error marshaling JSON: %s", err) - } - req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonBody)) - if err != nil { - return 2, fmt.Errorf("Error creating request: %s", err) - } - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", credentials)) - req.Header.Set("Content-Type", "application/json") - resp, err := client.Do(req) - if err != nil { - return 3, err - } - defer resp.Body.Close() - - if result != nil { - if err = json.NewDecoder(resp.Body).Decode(&result); err != nil { - return 4, err - } - } - - return resp.StatusCode, nil -} - -func removes(s1 []string, s2 []string) []string { - result := make([]string, 0, len(s1)) - - for _, v := range s1 { - if !slices.Contains(s2, v) { - result = append(result, v) - } - } - return result -} diff --git a/.ci/containers/membership-checker/utils_test.go b/.ci/containers/membership-checker/utils_test.go deleted file mode 100644 index adea48f933cb..000000000000 --- a/.ci/containers/membership-checker/utils_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "reflect" - "testing" -) - -func TestRemovesList(t *testing.T) { - cases := map[string]struct { - Original, Removal, Expected []string - }{ - "Remove list": { - Original: []string{"a", "b", "c"}, - Removal: []string{"b"}, - Expected: []string{"a", "c"}, - }, - "Remove case sensitive elements": { - Original: []string{"a", "b", "c", "A", "B"}, - Removal: []string{"b", "c", "A"}, - Expected: []string{"a", "B"}, - }, - "Remove nonexistent elements": { - Original: []string{"a", "b", "c", "A", "B"}, - Removal: []string{"a", "A", "d"}, - Expected: []string{"b", "c", "B"}, - }, - "Remove none": { - Original: []string{"a", "b", "c", "A", "B"}, - Removal: []string{}, - Expected: []string{"a", "b", "c", "A", "B"}, - }, - "Remove all": { - Original: []string{"a", "b", "c", "A", "B"}, - Removal: []string{"a", "b", "c", "A", "B"}, - Expected: []string{}, - }, - "Remove all and extra nonexistent elements": { - Original: []string{"a", "b", "c", "A", "B"}, - Removal: []string{"a", "b", "c", "A", "B", "D"}, - Expected: []string{}, - }, - } - for tn, tc := range cases { - result := removes(tc.Original, tc.Removal) - if !reflect.DeepEqual(result, tc.Expected) { - t.Errorf("bad: %s, '%s' removes '%s' expect result: %s, but got: %s", tn, tc.Original, tc.Removal, tc.Expected, result) - } - } -} diff --git a/.ci/gcb-changelog-checker.yml b/.ci/gcb-changelog-checker.yml deleted file mode 100644 index aa2c5289675f..000000000000 --- a/.ci/gcb-changelog-checker.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -steps: - - name: 'gcr.io/graphite-docker-images/bash-plus' - entrypoint: 'bash' - args: - - -c - - echo "This build step has been moved to a github action." - - -# noop - moved to pull_request event on https://github.com/GoogleCloudPlatform/magic-modules/pull/8727. diff --git a/.ci/gcb-run-rake-tests.yml b/.ci/gcb-run-rake-tests.yml deleted file mode 100644 index 9d9072cbaf74..000000000000 --- a/.ci/gcb-run-rake-tests.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -steps: -- name: 'gcr.io/graphite-docker-images/build-environment' - id: run-rake-tests - entrypoint: bundle - dir: mmv1 - args: - - exec - - rake - - test