Skip to content

Commit

Permalink
chore: github.Int/github.String/github.Bool -> github.Ptr
Browse files Browse the repository at this point in the history
Signed-off-by: Rui Chen <[email protected]>
  • Loading branch information
chenrui333 committed Dec 31, 2024
1 parent 4289b1b commit 53f364b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions e2e/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (g GithubClient) CreateAtlantisWebhook(ctx context.Context, hookURL string)
atlantisHook := &github.Hook{
Events: []string{"issue_comment", "pull_request", "push"},
Config: hookConfig,
Active: github.Bool(true),
Active: github.Ptr(true),
}

hook, _, err := g.client.Repositories.CreateHook(ctx, g.ownerName, g.repoName, atlantisHook)
Expand Down Expand Up @@ -146,7 +146,7 @@ func (g GithubClient) GetAtlantisStatus(ctx context.Context, branchName string)

func (g GithubClient) ClosePullRequest(ctx context.Context, pullRequestNumber int) error {
// clean up
_, _, err := g.client.PullRequests.Edit(ctx, g.ownerName, g.repoName, pullRequestNumber, &github.PullRequest{State: github.String("closed")})
_, _, err := g.client.PullRequests.Edit(ctx, g.ownerName, g.repoName, pullRequestNumber, &github.PullRequest{State: github.Ptr("closed")})
if err != nil {
return fmt.Errorf("error while closing new pull request: %v", err)
}
Expand Down
22 changes: 11 additions & 11 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1695,26 +1695,26 @@ func GitHubPullRequestParsed(headSHA string) *github.PullRequest {
headSHA = "13940d121be73f656e2132c6d7b4c8e87878ac8d"
}
return &github.PullRequest{
Number: github.Int(2),
State: github.String("open"),
HTMLURL: github.String("htmlurl"),
Number: github.Ptr(2),
State: github.Ptr("open"),
HTMLURL: github.Ptr("htmlurl"),
Head: &github.PullRequestBranch{
Repo: &github.Repository{
FullName: github.String("runatlantis/atlantis-tests"),
CloneURL: github.String("https://github.com/runatlantis/atlantis-tests.git"),
FullName: github.Ptr("runatlantis/atlantis-tests"),
CloneURL: github.Ptr("https://github.com/runatlantis/atlantis-tests.git"),
},
SHA: github.String(headSHA),
Ref: github.String("branch"),
SHA: github.Ptr(headSHA),
Ref: github.Ptr("branch"),
},
Base: &github.PullRequestBranch{
Repo: &github.Repository{
FullName: github.String("runatlantis/atlantis-tests"),
CloneURL: github.String("https://github.com/runatlantis/atlantis-tests.git"),
FullName: github.Ptr("runatlantis/atlantis-tests"),
CloneURL: github.Ptr("https://github.com/runatlantis/atlantis-tests.git"),
},
Ref: github.String("main"),
Ref: github.Ptr("main"),
},
User: &github.User{
Login: github.String("atlantisbot"),
Login: github.Ptr("atlantisbot"),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/events/apply_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestApplyCommandRunner_IsLocked(t *testing.T) {
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")

pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(logger, testdata.GithubRepo, testdata.Pull.Num)).ThenReturn(pull, nil)
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) {
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")

pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}

Expand Down
32 changes: 16 additions & 16 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func TestRunCommentCommand_DisableApplyAllDisabled(t *testing.T) {
vcsClient := setup(t)
applyCommandRunner.DisableApplyAll = true
pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestRunCommentCommand_ClosedPull(t *testing.T) {
" comment saying that this is not allowed")
vcsClient := setup(t)
pull := &github.PullRequest{
State: github.String("closed"),
State: github.Ptr("closed"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.ClosedPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
Expand Down Expand Up @@ -647,12 +647,12 @@ func TestRunUnlockCommand_VCSComment(t *testing.T) {
}{
{
name: "PR open",
prState: github.String("open"),
prState: github.Ptr("open"),
},

{
name: "PR closed",
prState: github.String("closed"),
prState: github.Ptr("closed"),
},
}

Expand Down Expand Up @@ -689,7 +689,7 @@ func TestRunUnlockCommandFail_VCSComment(t *testing.T) {

vcsClient := setup(t)
pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo),
Expand All @@ -713,7 +713,7 @@ func TestRunUnlockCommandFail_DisableUnlockLabel(t *testing.T) {

vcsClient := setup(t)
pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo),
Expand All @@ -737,7 +737,7 @@ func TestRunUnlockCommandFail_GetLabelsFail(t *testing.T) {

vcsClient := setup(t)
pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo),
Expand All @@ -763,7 +763,7 @@ func TestRunUnlockCommandDoesntRetrieveLabelsIfDisableUnlockLabelNotSet(t *testi

vcsClient := setup(t)
pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo),
Expand Down Expand Up @@ -865,7 +865,7 @@ func TestRunCommentCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_Fals

When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}})
When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil)
pull := &github.PullRequest{State: github.String("open")}
pull := &github.PullRequest{State: github.Ptr("open")}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil)
Expand Down Expand Up @@ -907,7 +907,7 @@ func TestRunGenericPlanCommand_DeletePlans(t *testing.T) {

When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}})
When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil)
pull := &github.PullRequest{State: github.String("open")}
pull := &github.PullRequest{State: github.Ptr("open")}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil)
Expand Down Expand Up @@ -1001,7 +1001,7 @@ func TestRunGenericPlanCommand_DiscardApprovals(t *testing.T) {

When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}})
When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil)
pull := &github.PullRequest{State: github.String("open")}
pull := &github.PullRequest{State: github.Ptr("open")}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil)
Expand All @@ -1025,7 +1025,7 @@ func TestFailedApprovalCreatesFailedStatusUpdate(t *testing.T) {
defer func() { autoMerger.GlobalAutomerge = false }()

pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}

modelPull := models.PullRequest{
Expand Down Expand Up @@ -1071,7 +1071,7 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) {
defer func() { autoMerger.GlobalAutomerge = false }()

pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}

modelPull := models.PullRequest{
Expand Down Expand Up @@ -1127,7 +1127,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) {
defer func() { autoMerger.GlobalAutomerge = false }()

pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}

modelPull := models.PullRequest{
Expand Down Expand Up @@ -1174,7 +1174,7 @@ func TestApplyWithAutoMerge_VSCMerge(t *testing.T) {

vcsClient := setup(t)
pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
Expand Down Expand Up @@ -1217,7 +1217,7 @@ func TestRunApply_DiscardedProjects(t *testing.T) {
Ok(t, err)
Ok(t, boltDB.UpdateProjectStatus(pull, "default", ".", models.DiscardedPlanStatus))
ghPull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(ghPull, nil)
When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(ghPull))).ThenReturn(pull, pull.BaseRepo, testdata.GithubRepo, nil)
Expand Down
14 changes: 7 additions & 7 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func TestParseGithubIssueCommentEvent(t *testing.T) {
comment := github.IssueCommentEvent{
Repo: &Repo,
Issue: &github.Issue{
Number: github.Int(1),
User: &github.User{Login: github.String("issue_user")},
HTMLURL: github.String("https://github.com/runatlantis/atlantis/issues/1"),
Number: github.Ptr(1),
User: &github.User{Login: github.Ptr("issue_user")},
HTMLURL: github.Ptr("https://github.com/runatlantis/atlantis/issues/1"),
},
Comment: &github.IssueComment{
User: &github.User{Login: github.String("comment_user")},
User: &github.User{Login: github.Ptr("comment_user")},
},
}

Expand Down Expand Up @@ -170,16 +170,16 @@ func TestParseGithubPullEventFromDraft(t *testing.T) {
logger := logging.NewNoopLogger(t)
// verify that close event treated as 'close' events by default
closeEvent := deepcopy.Copy(PullEvent).(github.PullRequestEvent)
closeEvent.Action = github.String("closed")
closeEvent.PullRequest.Draft = github.Bool(true)
closeEvent.Action = github.Ptr("closed")
closeEvent.PullRequest.Draft = github.Ptr(true)

_, evType, _, _, _, err := parser.ParseGithubPullEvent(logger, &closeEvent)
Ok(t, err)
Equals(t, models.ClosedPullEvent, evType)

// verify that draft PRs are treated as 'other' events by default
testEvent := deepcopy.Copy(PullEvent).(github.PullRequestEvent)
testEvent.PullRequest.Draft = github.Bool(true)
testEvent.PullRequest.Draft = github.Ptr(true)
_, evType, _, _, _, err = parser.ParseGithubPullEvent(logger, &testEvent)
Ok(t, err)
Equals(t, models.OtherPullEvent, evType)
Expand Down
2 changes: 1 addition & 1 deletion server/events/plan_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) {
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")

pull := &github.PullRequest{
State: github.String("open"),
State: github.Ptr("open"),
}
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}

Expand Down
10 changes: 5 additions & 5 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep
nextPage := 0
for {
comments, resp, err := g.client.Issues.ListComments(g.ctx, repo.Owner, repo.Name, pullNum, &github.IssueListCommentsOptions{
Sort: github.String("created"),
Direction: github.String("asc"),
Sort: github.Ptr("created"),
Direction: github.Ptr("asc"),
ListOptions: github.ListOptions{Page: nextPage},
})
if resp != nil {
Expand Down Expand Up @@ -913,9 +913,9 @@ func (g *GithubClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
logger.Info("Updating GitHub Check status for '%s' to '%s'", src, ghState)

status := &github.RepoStatus{
State: github.String(ghState),
Description: github.String(description),
Context: github.String(src),
State: github.Ptr(ghState),
Description: github.Ptr(description),
Context: github.Ptr(src),
TargetURL: &url,
}
_, resp, err := g.client.Repositories.CreateStatus(g.ctx, repo.Owner, repo.Name, pull.HeadCommit, status)
Expand Down
28 changes: 14 additions & 14 deletions server/events/vcs/testdata/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ import (

var PullEvent = github.PullRequestEvent{
Sender: &github.User{
Login: github.String("user"),
Login: github.Ptr("user"),
},
Repo: &Repo,
PullRequest: &Pull,
Action: github.String("opened"),
Action: github.Ptr("opened"),
}

var Pull = github.PullRequest{
Head: &github.PullRequestBranch{
SHA: github.String("sha256"),
Ref: github.String("ref"),
SHA: github.Ptr("sha256"),
Ref: github.Ptr("ref"),
Repo: &Repo,
},
Base: &github.PullRequestBranch{
SHA: github.String("sha256"),
SHA: github.Ptr("sha256"),
Repo: &Repo,
Ref: github.String("basebranch"),
Ref: github.Ptr("basebranch"),
},
HTMLURL: github.String("html-url"),
HTMLURL: github.Ptr("html-url"),
User: &github.User{
Login: github.String("user"),
Login: github.Ptr("user"),
},
Number: github.Int(1),
State: github.String("open"),
Number: github.Ptr(1),
State: github.Ptr("open"),
}

var Repo = github.Repository{
FullName: github.String("owner/repo"),
Owner: &github.User{Login: github.String("owner")},
Name: github.String("repo"),
CloneURL: github.String("https://github.com/owner/repo.git"),
FullName: github.Ptr("owner/repo"),
Owner: &github.User{Login: github.Ptr("owner")},
Name: github.Ptr("repo"),
CloneURL: github.Ptr("https://github.com/owner/repo.git"),
}

var ADPullEvent = azuredevops.Event{
Expand Down
14 changes: 7 additions & 7 deletions testdrive/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (g *Client) CheckForkSuccess(ownerName string, forkRepoName string) bool {
func (g *Client) CreateWebhook(ownerName string, repoName string, hookURL string) error {
contentType := "json"
hookConfig := &github.HookConfig{
ContentType: &contentType,
URL: &hookURL,
ContentType: github.Ptr(contentType),
URL: github.Ptr(hookURL),
}
atlantisHook := &github.Hook{
Events: []string{"issue_comment", "pull_request", "pull_request_review", "push"},
Config: hookConfig,
Active: github.Bool(true),
Active: github.Ptr(true),
}
_, _, err := g.client.Repositories.CreateHook(g.ctx, ownerName, repoName, atlantisHook)
return err
Expand All @@ -87,10 +87,10 @@ func (g *Client) CreatePullRequest(ownerName string, repoName string, head strin

// If not, create it.
newPullRequest := &github.NewPullRequest{
Title: github.String("Welcome to Atlantis!"),
Head: github.String(head),
Body: github.String(pullRequestBody),
Base: github.String(base),
Title: github.Ptr("Welcome to Atlantis!"),
Head: github.Ptr(head),
Body: github.Ptr(pullRequestBody),
Base: github.Ptr(base),
}
pull, _, err := g.client.PullRequests.Create(g.ctx, ownerName, repoName, newPullRequest)
if err != nil {
Expand Down

0 comments on commit 53f364b

Please sign in to comment.