Skip to content

Commit 9d4604d

Browse files
authored
Merge branch 'main' into dc-terraform
2 parents 3593a30 + e56ce0e commit 9d4604d

File tree

772 files changed

+11875
-6637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

772 files changed

+11875
-6637
lines changed

.ci/containers/build-environment/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 1777 "$GOPATH"
2323
WORKDIR $GOPATH
2424

2525
# terraform binary used by tfv/tgc
26-
COPY --from=hashicorp/terraform:1.8.3 /bin/terraform /bin/terraform
26+
COPY --from=hashicorp/terraform:1.10.0 /bin/terraform /bin/terraform
2727

2828
SHELL ["/bin/bash", "-c"]
2929

.ci/containers/go-plus/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RUN apt-get update && \
2929
apt-get clean && \
3030
rm -rf /var/lib/apt/lists/*
3131

32-
RUN wget https://releases.hashicorp.com/terraform/1.8.3/terraform_1.8.3_linux_amd64.zip \
33-
&& unzip terraform_1.8.3_linux_amd64.zip \
34-
&& rm terraform_1.8.3_linux_amd64.zip \
32+
RUN wget https://releases.hashicorp.com/terraform/1.10.0/terraform_1.10.0_linux_amd64.zip \
33+
&& unzip terraform_1.10.0_linux_amd64.zip \
34+
&& rm terraform_1.10.0_linux_amd64.zip \
3535
&& mv ./terraform /bin/terraform

.ci/magician/cmd/generate_downstream.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,15 @@ func createCommit(scratchRepo *source.Repo, commitMessage string, rnr ExecRunner
335335
commitSha = strings.TrimSpace(commitSha)
336336
fmt.Printf("Commit sha on the branch is: `%s`\n", commitSha)
337337

338-
variablePath := fmt.Sprintf("/workspace/commitSHA_modular-magician_%s.txt", scratchRepo.Name)
339-
fmt.Println("variablePath: ", variablePath)
340-
341-
err = rnr.WriteFile(variablePath, commitSha)
342-
if err != nil {
343-
fmt.Println("Error:", err)
338+
// auto-pr's use commitSHA_modular-magician_<repo>_.txt file to communicate commmit hash
339+
// across cloudbuild steps. Used in test-tpg to execute unit tests for the HEAD commit
340+
if strings.HasPrefix(scratchRepo.Branch, "auto-pr-") && !strings.HasSuffix(scratchRepo.Branch, "-old") {
341+
variablePath := fmt.Sprintf("/workspace/commitSHA_modular-magician_%s.txt", scratchRepo.Name)
342+
fmt.Println("variablePath: ", variablePath)
343+
err = rnr.WriteFile(variablePath, commitSha)
344+
if err != nil {
345+
fmt.Println("Error:", err)
346+
}
344347
}
345348

346349
return commitSha, err

.ci/magician/cmd/scheduled_pr_reminders.go

+59-24
Original file line numberDiff line numberDiff line change
@@ -267,29 +267,20 @@ func (s pullRequestReviewState) String() string {
267267
// We don't specially handle cases where the contributor has "acted" because it would be
268268
// significant additional effort, and this case is already handled by re-requesting review
269269
// automatically based on contributor actions.
270-
func notificationState(pr *github.PullRequest, issueEvents []*github.IssueEvent, reviews []*github.PullRequestReview) (pullRequestReviewState, time.Time, error) {
271-
slices.SortFunc(issueEvents, func(a, b *github.IssueEvent) int {
272-
if a.CreatedAt.Before(*b.CreatedAt.GetTime()) {
273-
return 1
270+
func notificationState(pr *github.PullRequest, issueEventsDesc []*github.IssueEvent, reviewsDesc []*github.PullRequestReview) (pullRequestReviewState, time.Time, error) {
271+
issueEventsDesc = sortedEventsDesc(issueEventsDesc)
272+
reviewsDesc = sortedReviewsDesc(reviewsDesc)
273+
274+
var readyForReviewTime = *pr.CreatedAt.GetTime()
275+
for _, event := range issueEventsDesc {
276+
if "ready_for_review" == *event.Event {
277+
readyForReviewTime = maxTime(*event.CreatedAt.GetTime(), readyForReviewTime)
274278
}
275-
if a.CreatedAt.After(*b.CreatedAt.GetTime()) {
276-
return -1
277-
}
278-
return 0
279-
})
280-
slices.SortFunc(reviews, func(a, b *github.PullRequestReview) int {
281-
if a.SubmittedAt.Before(*b.SubmittedAt.GetTime()) {
282-
return 1
283-
}
284-
if a.SubmittedAt.After(*b.SubmittedAt.GetTime()) {
285-
return -1
286-
}
287-
return 0
288-
})
279+
}
289280

290281
var latestReviewRequest *github.IssueEvent
291282
removedRequests := map[string]struct{}{}
292-
for _, event := range issueEvents {
283+
for _, event := range issueEventsDesc {
293284
if *event.Event == "review_request_removed" && event.RequestedReviewer != nil {
294285
removedRequests[*event.RequestedReviewer.Login] = struct{}{}
295286
continue
@@ -320,7 +311,7 @@ func notificationState(pr *github.PullRequest, issueEvents []*github.IssueEvent,
320311
var earliestCommented *github.PullRequestReview
321312

322313
ignoreBy := map[string]struct{}{}
323-
for _, review := range reviews {
314+
for _, review := range reviewsDesc {
324315
if review.SubmittedAt.Before(*latestReviewRequest.CreatedAt.GetTime()) {
325316
break
326317
}
@@ -355,15 +346,59 @@ func notificationState(pr *github.PullRequest, issueEvents []*github.IssueEvent,
355346
}
356347

357348
if earliestChangesRequested != nil {
358-
return waitingForContributor, *earliestChangesRequested.SubmittedAt.GetTime(), nil
349+
timeState := maxTime(*earliestChangesRequested.SubmittedAt.GetTime(), readyForReviewTime)
350+
return waitingForContributor, timeState, nil
359351
}
360352
if earliestApproved != nil {
361-
return waitingForMerge, *earliestApproved.SubmittedAt.GetTime(), nil
353+
timeState := maxTime(*earliestApproved.SubmittedAt.GetTime(), readyForReviewTime)
354+
return waitingForMerge, timeState, nil
362355
}
363356
if earliestCommented != nil {
364-
return waitingForContributor, *earliestCommented.SubmittedAt.GetTime(), nil
357+
timeState := maxTime(*earliestCommented.SubmittedAt.GetTime(), readyForReviewTime)
358+
return waitingForContributor, timeState, nil
359+
}
360+
timeState := maxTime(*latestReviewRequest.CreatedAt.GetTime(), readyForReviewTime)
361+
return waitingForReview, timeState, nil
362+
}
363+
364+
// compareTimeDesc returns sort ordering for descending time comparison (newest first)
365+
func compareTimeDesc(a, b time.Time) int {
366+
if a.Before(b) {
367+
return 1
368+
}
369+
if a.After(b) {
370+
return -1
371+
}
372+
return 0
373+
}
374+
375+
// sortedEventsDesc returns events sorted by creation time, newest first
376+
func sortedEventsDesc(events []*github.IssueEvent) []*github.IssueEvent {
377+
sortedEvents := make([]*github.IssueEvent, len(events))
378+
copy(sortedEvents, events)
379+
slices.SortFunc(sortedEvents, func(a, b *github.IssueEvent) int {
380+
return compareTimeDesc(*a.CreatedAt.GetTime(), *b.CreatedAt.GetTime())
381+
})
382+
return sortedEvents
383+
}
384+
385+
// sortedReviewsDesc returns reviews sorted by submission time, newest first
386+
func sortedReviewsDesc(reviews []*github.PullRequestReview) []*github.PullRequestReview {
387+
sortedReviews := make([]*github.PullRequestReview, len(reviews))
388+
copy(sortedReviews, reviews)
389+
slices.SortFunc(sortedReviews, func(a, b *github.PullRequestReview) int {
390+
return compareTimeDesc(*a.SubmittedAt.GetTime(), *b.SubmittedAt.GetTime())
391+
})
392+
return sortedReviews
393+
}
394+
395+
// maxTime - returns whichever time occured after the other
396+
func maxTime(time1, time2 time.Time) time.Time {
397+
// Return the later time
398+
if time1.After(time2) {
399+
return time1
365400
}
366-
return waitingForReview, *latestReviewRequest.CreatedAt.GetTime(), nil
401+
return time2
367402
}
368403

369404
// Calculates the number of PDT days between from and to (by calendar date, not # of hours).

.ci/magician/cmd/scheduled_pr_reminders_test.go

+183-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
)
1212

1313
func TestNotificationState(t *testing.T) {
14-
firstCoreReviewer := membership.AvailableReviewers()[0]
15-
secondCoreReviewer := membership.AvailableReviewers()[1]
14+
availableReviewers := membership.AvailableReviewers()
15+
firstCoreReviewer := availableReviewers[0]
16+
secondCoreReviewer := availableReviewers[1]
1617
cases := map[string]struct {
1718
pullRequest *github.PullRequest
1819
issueEvents []*github.IssueEvent
@@ -442,6 +443,183 @@ func TestNotificationState(t *testing.T) {
442443
expectState: waitingForMerge,
443444
expectSince: time.Date(2024, 2, 1, 0, 0, 0, 0, time.UTC),
444445
},
446+
"ready_for_review event after creation": {
447+
pullRequest: &github.PullRequest{
448+
User: &github.User{Login: github.String("author")},
449+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
450+
},
451+
issueEvents: []*github.IssueEvent{
452+
&github.IssueEvent{
453+
Event: github.String("review_requested"),
454+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)},
455+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
456+
},
457+
&github.IssueEvent{
458+
Event: github.String("ready_for_review"),
459+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)},
460+
},
461+
},
462+
expectState: waitingForReview,
463+
expectSince: time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC),
464+
},
465+
466+
"ready_for_review event before review request": {
467+
pullRequest: &github.PullRequest{
468+
User: &github.User{Login: github.String("author")},
469+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
470+
},
471+
issueEvents: []*github.IssueEvent{
472+
&github.IssueEvent{
473+
Event: github.String("ready_for_review"),
474+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)},
475+
},
476+
&github.IssueEvent{
477+
Event: github.String("review_requested"),
478+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)},
479+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
480+
},
481+
},
482+
expectState: waitingForReview,
483+
expectSince: time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC),
484+
},
485+
486+
"review after ready_for_review": {
487+
pullRequest: &github.PullRequest{
488+
User: &github.User{Login: github.String("author")},
489+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
490+
},
491+
issueEvents: []*github.IssueEvent{
492+
&github.IssueEvent{
493+
Event: github.String("ready_for_review"),
494+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)},
495+
},
496+
&github.IssueEvent{
497+
Event: github.String("review_requested"),
498+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)},
499+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
500+
},
501+
},
502+
reviews: []*github.PullRequestReview{
503+
&github.PullRequestReview{
504+
User: &github.User{Login: github.String(firstCoreReviewer)},
505+
State: github.String("APPROVED"),
506+
SubmittedAt: &github.Timestamp{time.Date(2024, 1, 4, 0, 0, 0, 0, time.UTC)},
507+
},
508+
},
509+
expectState: waitingForMerge,
510+
expectSince: time.Date(2024, 1, 4, 0, 0, 0, 0, time.UTC),
511+
},
512+
"changes_requested after ready_for_review": {
513+
pullRequest: &github.PullRequest{
514+
User: &github.User{Login: github.String("author")},
515+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
516+
},
517+
issueEvents: []*github.IssueEvent{
518+
&github.IssueEvent{
519+
Event: github.String("review_requested"),
520+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)}, // Earlier request
521+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
522+
},
523+
&github.IssueEvent{
524+
Event: github.String("ready_for_review"),
525+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)},
526+
},
527+
},
528+
reviews: []*github.PullRequestReview{
529+
&github.PullRequestReview{
530+
User: &github.User{Login: github.String(firstCoreReviewer)},
531+
State: github.String("CHANGES_REQUESTED"),
532+
SubmittedAt: &github.Timestamp{time.Date(2024, 1, 4, 0, 0, 0, 0, time.UTC)}, // Early changes requested
533+
},
534+
},
535+
expectState: waitingForContributor,
536+
expectSince: time.Date(2024, 1, 4, 0, 0, 0, 0, time.UTC), // Should use ready_for_review time
537+
},
538+
539+
"changes_requested before ready_for_review": {
540+
pullRequest: &github.PullRequest{
541+
User: &github.User{Login: github.String("author")},
542+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
543+
},
544+
issueEvents: []*github.IssueEvent{
545+
&github.IssueEvent{
546+
Event: github.String("review_requested"),
547+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
548+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
549+
},
550+
&github.IssueEvent{
551+
Event: github.String("ready_for_review"),
552+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)}, // Earlier ready
553+
},
554+
},
555+
reviews: []*github.PullRequestReview{
556+
&github.PullRequestReview{
557+
User: &github.User{Login: github.String(firstCoreReviewer)},
558+
State: github.String("CHANGES_REQUESTED"),
559+
SubmittedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)},
560+
},
561+
},
562+
expectState: waitingForContributor,
563+
expectSince: time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC), // Should use changes requested time since it's later
564+
},
565+
566+
"comment review after ready_for_review": {
567+
pullRequest: &github.PullRequest{
568+
User: &github.User{Login: github.String("author")},
569+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
570+
},
571+
issueEvents: []*github.IssueEvent{
572+
&github.IssueEvent{
573+
Event: github.String("ready_for_review"),
574+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
575+
},
576+
&github.IssueEvent{
577+
Event: github.String("review_requested"),
578+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)},
579+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
580+
},
581+
},
582+
reviews: []*github.PullRequestReview{
583+
&github.PullRequestReview{
584+
User: &github.User{Login: github.String(firstCoreReviewer)},
585+
State: github.String("COMMENTED"),
586+
SubmittedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)},
587+
},
588+
},
589+
expectState: waitingForContributor,
590+
expectSince: time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC), // Should use ready_for_review time
591+
},
592+
593+
"multiple ready_for_review events": {
594+
pullRequest: &github.PullRequest{
595+
User: &github.User{Login: github.String("author")},
596+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)},
597+
},
598+
issueEvents: []*github.IssueEvent{
599+
&github.IssueEvent{
600+
Event: github.String("ready_for_review"),
601+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)},
602+
},
603+
&github.IssueEvent{
604+
Event: github.String("review_requested"),
605+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 3, 0, 0, 0, 0, time.UTC)},
606+
RequestedReviewer: &github.User{Login: github.String(firstCoreReviewer)},
607+
},
608+
&github.IssueEvent{
609+
Event: github.String("ready_for_review"),
610+
CreatedAt: &github.Timestamp{time.Date(2024, 1, 5, 0, 0, 0, 0, time.UTC)}, // Later ready_for_review
611+
},
612+
},
613+
reviews: []*github.PullRequestReview{
614+
&github.PullRequestReview{
615+
User: &github.User{Login: github.String(firstCoreReviewer)},
616+
State: github.String("CHANGES_REQUESTED"),
617+
SubmittedAt: &github.Timestamp{time.Date(2024, 1, 4, 0, 0, 0, 0, time.UTC)},
618+
},
619+
},
620+
expectState: waitingForContributor,
621+
expectSince: time.Date(2024, 1, 5, 0, 0, 0, 0, time.UTC), // Should use latest ready_for_review time
622+
},
445623
}
446624

447625
for tn, tc := range cases {
@@ -786,8 +964,9 @@ func TestShouldNotify(t *testing.T) {
786964
}
787965

788966
func TestFormatReminderComment(t *testing.T) {
789-
firstCoreReviewer := membership.AvailableReviewers()[0]
790-
secondCoreReviewer := membership.AvailableReviewers()[1]
967+
availableReviewers := membership.AvailableReviewers()
968+
firstCoreReviewer := availableReviewers[0]
969+
secondCoreReviewer := availableReviewers[1]
791970
cases := map[string]struct {
792971
pullRequest *github.PullRequest
793972
state pullRequestReviewState

.ci/magician/cmd/templates/vcr/with_replay_failed_tests.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
</blockquote>
1010
</details>
1111

12-
[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/docs/getting-started/contributing/#general-contributing-steps)
12+
[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)

.ci/magician/cmd/test_terraform_vcr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func TestWithReplayFailedTests(t *testing.T) {
447447
"</blockquote>",
448448
"</details>",
449449
"",
450-
"[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/docs/getting-started/contributing/#general-contributing-steps)",
450+
"[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)",
451451
},
452452
"\n",
453453
),

0 commit comments

Comments
 (0)