forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'GoogleCloudPlatform:main' into main
- Loading branch information
Showing
470 changed files
with
7,489 additions
and
2,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2024 Google LLC. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"magician/github" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// reassignReviewerCmd represents the reassignReviewer command | ||
var reassignReviewerCmd = &cobra.Command{ | ||
Use: "reassign-reviewer PR_NUMBER [REVIEWER]", | ||
Short: "Reassigns primary reviewer to the given reviewer or a random reviewer if none given", | ||
Long: `This command reassigns reviewers when invoked via a comment on a pull request. | ||
The command expects the following PR details as arguments: | ||
1. PR_NUMBER | ||
2. REVIEWER (optional) | ||
It then performs the following operations: | ||
1. Updates the reviewer comment to reflect the new primary reviewer. | ||
2. Requests a review from the new primary reviewer. | ||
`, | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
prNumber := args[0] | ||
fmt.Println("PR Number: ", prNumber) | ||
|
||
githubToken, ok := os.LookupEnv("GITHUB_TOKEN") | ||
if !ok { | ||
return fmt.Errorf("did not provide GITHUB_TOKEN environment variable") | ||
} | ||
gh := github.NewClient(githubToken) | ||
var newPrimaryReviewer string | ||
if len(args) > 1 { | ||
newPrimaryReviewer = args[1] | ||
} | ||
return execReassignReviewer(prNumber, newPrimaryReviewer, gh) | ||
}, | ||
} | ||
|
||
func execReassignReviewer(prNumber, newPrimaryReviewer string, gh GithubClient) error { | ||
comments, err := gh.GetPullRequestComments(prNumber) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
reviewerComment, currentReviewer := github.FindReviewerComment(comments) | ||
|
||
if currentReviewer == "" { | ||
fmt.Println("No reviewer comment found, creating one") | ||
newPrimaryReviewer, err = createReviewComment(prNumber, newPrimaryReviewer, gh) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
fmt.Println("Reassigning to random reviewer") | ||
newPrimaryReviewer, err = updateReviewComment(prNumber, currentReviewer, newPrimaryReviewer, reviewerComment.ID, gh) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
fmt.Println("New primary reviewer is ", newPrimaryReviewer) | ||
|
||
err = gh.RequestPullRequestReviewers(prNumber, []string{newPrimaryReviewer}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func createReviewComment(prNumber, newPrimaryReviewer string, gh GithubClient) (string, error) { | ||
if newPrimaryReviewer == "" { | ||
newPrimaryReviewer = github.GetRandomReviewer() | ||
} | ||
|
||
if newPrimaryReviewer == "" { | ||
return "", errors.New("no primary reviewer found") | ||
} | ||
|
||
err := gh.PostComment(prNumber, github.FormatReviewerComment(newPrimaryReviewer)) | ||
if err != nil { | ||
return "", err | ||
} | ||
return newPrimaryReviewer, nil | ||
} | ||
|
||
func updateReviewComment(prNumber, currentReviewer, newPrimaryReviewer string, reviewerCommentID int, gh GithubClient) (string, error) { | ||
if newPrimaryReviewer == "" { | ||
newPrimaryReviewer = github.GetNewRandomReviewer(currentReviewer) | ||
} | ||
|
||
if currentReviewer == newPrimaryReviewer { | ||
return newPrimaryReviewer, fmt.Errorf("primary reviewer is already %s", newPrimaryReviewer) | ||
} | ||
|
||
err := gh.UpdateComment(prNumber, github.FormatReviewerComment(newPrimaryReviewer), reviewerCommentID) | ||
if err != nil { | ||
return "", err | ||
} | ||
return newPrimaryReviewer, nil | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(reassignReviewerCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.