Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmoy authored Nov 18, 2024
2 parents 35a39f7 + c91b09c commit 6863948
Show file tree
Hide file tree
Showing 564 changed files with 19,973 additions and 18,535 deletions.
8 changes: 4 additions & 4 deletions .ci/containers/build-environment/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Building Go dependencies
FROM golang:1.21-bullseye AS builder
FROM golang:1.23-bullseye AS builder

# Set working directory
WORKDIR /app
Expand All @@ -15,7 +15,7 @@ RUN go mod download
FROM ruby:3.1-bullseye

# golang
COPY --from=golang:1.21-bullseye /usr/local/go /usr/local/go
COPY --from=golang:1.23-bullseye /usr/local/go /usr/local/go
ENV GOPATH /go
ENV PATH /usr/local/go/bin:$PATH
ENV PATH $GOPATH/bin:$PATH
Expand All @@ -39,8 +39,8 @@ RUN git config --global user.email "[email protected]"
RUN go install golang.org/x/tools/cmd/goimports@d088b475e3360caabc032aaee1dc66351d4e729a
RUN go install github.com/github/[email protected]+incompatible

ADD "https://raw.githubusercontent.com/GoogleCloudPlatform/magic-modules/main/mmv1/Gemfile" Gemfile
ADD "https://raw.githubusercontent.com/GoogleCloudPlatform/magic-modules/main/mmv1/Gemfile.lock" Gemfile.lock
ADD "https://raw.githubusercontent.com/GoogleCloudPlatform/magic-modules/refs/heads/legacy-ruby/mmv1/Gemfile" Gemfile
ADD "https://raw.githubusercontent.com/GoogleCloudPlatform/magic-modules/refs/heads/legacy-ruby/mmv1/Gemfile.lock" Gemfile.lock
RUN bundle install
RUN rm Gemfile Gemfile.lock

Expand Down
4 changes: 2 additions & 2 deletions .ci/containers/go-plus/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Download go module cache for builds
FROM golang:1.21-bullseye AS builder
FROM golang:1.23-bullseye AS builder
ENV GOCACHE=/go/cache

RUN apt-get update && apt-get install -y unzip
Expand All @@ -12,7 +12,7 @@ WORKDIR /app1/magic-modules-main/.ci/magician
RUN go build -o /dev/null .

# Stage 2: Creating the final image
FROM golang:1.21-bullseye
FROM golang:1.23-bullseye
SHELL ["/bin/bash", "-c"]
ENV GOCACHE=/go/cache

Expand Down
1 change: 1 addition & 0 deletions .ci/infra/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ module "project-services" {
"binaryauthorization.googleapis.com",
"blockchainnodeengine.googleapis.com",
"certificatemanager.googleapis.com",
"cloudaicompanion.googleapis.com"
"cloudapis.googleapis.com",
"cloudasset.googleapis.com",
"cloudbilling.googleapis.com",
Expand Down
32 changes: 22 additions & 10 deletions .ci/magician/cmd/scheduled_pr_reminders.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ var scheduledPrReminders = &cobra.Command{
return fmt.Errorf("did not provide GITHUB_TOKEN environment variable")
}
gh := github.NewClient(nil).WithAuthToken(githubToken)
return execScheduledPrReminders(gh)
mgh := membership.NewClient(githubToken)
return execScheduledPrReminders(gh, mgh)
},
}

func execScheduledPrReminders(gh *github.Client) error {
func execScheduledPrReminders(gh *github.Client, mgh GithubClient) error {
ctx := context.Background()
opt := &github.PullRequestListOptions{
State: "open",
Expand Down Expand Up @@ -165,7 +166,14 @@ func execScheduledPrReminders(gh *github.Client) error {
)
sinceDays := businessDaysDiff(since, time.Now())
if shouldNotify(pr, state, sinceDays) {
comment, err := formatReminderComment(pr, state, sinceDays)
// Determine the current primary reviewer.
comments, err := mgh.GetPullRequestComments(fmt.Sprintf("%d", *pr.Number))
if err != nil {
return err
}
_, currentReviewer := membership.FindReviewerComment(comments)

reminderComment, err := formatReminderComment(pr, state, sinceDays, currentReviewer)
if err != nil {
fmt.Printf(
"%d/%d: PR %d: error rendering comment: %s\n",
Expand All @@ -177,15 +185,15 @@ func execScheduledPrReminders(gh *github.Client) error {
continue
}
if dryRun {
fmt.Printf("DRY RUN: Would post comment: %s\n", comment)
fmt.Printf("DRY RUN: Would post comment: %s\n", reminderComment)
} else {
_, _, err := gh.Issues.CreateComment(
ctx,
"GoogleCloudPlatform",
"magic-modules",
*pr.Number,
&github.IssueComment{
Body: github.String(comment),
Body: github.String(reminderComment),
},
)
if err != nil {
Expand Down Expand Up @@ -433,7 +441,7 @@ func shouldNotify(pr *github.PullRequest, state pullRequestReviewState, sinceDay
return false
}

func formatReminderComment(pullRequest *github.PullRequest, state pullRequestReviewState, sinceDays int) (string, error) {
func formatReminderComment(pullRequest *github.PullRequest, state pullRequestReviewState, sinceDays int, currentReviewer string) (string, error) {
embeddedTemplate := ""
switch state {
case waitingForMerge:
Expand All @@ -454,11 +462,15 @@ func formatReminderComment(pullRequest *github.PullRequest, state pullRequestRev
panic(fmt.Sprintf("Unable to parse template for %s: %s", state.String(), err))
}

coreReviewers := []string{}
for _, reviewer := range pullRequest.RequestedReviewers {
if membership.IsCoreReviewer(*reviewer.Login) {
coreReviewers = append(coreReviewers, *reviewer.Login)
var coreReviewers []string
if currentReviewer == "" {
for _, reviewer := range pullRequest.RequestedReviewers {
if membership.IsCoreReviewer(*reviewer.Login) {
coreReviewers = append(coreReviewers, *reviewer.Login)
}
}
} else {
coreReviewers = append(coreReviewers, currentReviewer)
}

data := reminderCommentData{
Expand Down
27 changes: 26 additions & 1 deletion .ci/magician/cmd/scheduled_pr_reminders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ func TestFormatReminderComment(t *testing.T) {
sinceDays int
expectedStrings []string
notExpectedStrings []string
currentReviewer string
}{
// waitingForMerge
"waitingForMerge one week": {
Expand Down Expand Up @@ -933,6 +934,30 @@ func TestFormatReminderComment(t *testing.T) {
"@other-reviewer",
},
},
"waitingForReview three days with current reviewer": {
pullRequest: &github.PullRequest{
User: &github.User{Login: github.String("pr-author")},
RequestedReviewers: []*github.User{
&github.User{Login: github.String(firstCoreReviewer)},
&github.User{Login: github.String(secondCoreReviewer)},
&github.User{Login: github.String("other-reviewer")},
},
},
state: waitingForReview,
sinceDays: 3,
expectedStrings: []string{
"waiting for review for 3 weekdays",
"disable-review-reminders",
"@" + secondCoreReviewer,
},
notExpectedStrings: []string{
"@GoogleCloudPlatform/terraform-team",
"@pr-author",
"@other-reviewer",
"@" + firstCoreReviewer,
},
currentReviewer: secondCoreReviewer,
},

// waitingForContributor
"waitingForContributor two weeks": {
Expand Down Expand Up @@ -1048,7 +1073,7 @@ func TestFormatReminderComment(t *testing.T) {
t.Run(tn, func(t *testing.T) {
t.Parallel()

comment, err := formatReminderComment(tc.pullRequest, tc.state, tc.sinceDays)
comment, err := formatReminderComment(tc.pullRequest, tc.state, tc.sinceDays, tc.currentReviewer)
assert.Nil(t, err)

for _, s := range tc.expectedStrings {
Expand Down
Loading

0 comments on commit 6863948

Please sign in to comment.