Skip to content

Commit

Permalink
fix(internal/pkg/externalplugins/cherrypicker): do not change commit …
Browse files Browse the repository at this point in the history
…message (#1188)
  • Loading branch information
wuhuizuo authored Aug 6, 2024
1 parent 2c387de commit ac98cbf
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 129 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6.1.0
with:
version: v1.51.0
version: v1.59.1
args: --timeout=500s
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dupl
- gochecknoinits
- gocritic
Expand All @@ -22,10 +20,8 @@ linters:
- rowserrcheck
- exportloopref
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- varcheck
- whitespace
- errcheck
- errcheck
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ staticcheck: tools/bin/golangci-lint
tools/bin/golangci-lint run $$($(PACKAGE_DIRECTORIES)) --timeout 500s

tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.41.1
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.59.1

label-dumpling-checks:
@echo "label-dumpling checks"
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/externalplugins/blunderbuss/blunderbuss.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func handle(gc githubClient, opts *tiexternalplugins.TiCommunityBlunderbuss, rep
}

// Always seed random!
//nolint: staticcheck
rand.Seed(time.Now().UTC().UnixNano())
// List the contributors of the changes.
contributors, err := listChangesContributors(gc, repo.Owner.Login, repo.Name, pr.Number, log)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/externalplugins/cherrypicker/cherrypicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func (s *Server) handle(logger *logrus.Entry, requestor string,
}

// Try git cherry-pick.
cherrypick := ex.Command("git", "cherry-pick", "-m", "1", *pr.MergeSHA)
cherrypick := ex.Command("git", "cherry-pick", "-m", "1", "--cleanup=verbatim", *pr.MergeSHA)
cherrypick.SetDir(dir)
out, err = cherrypick.CombinedOutput()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestInviteIC(t *testing.T) {
BotUser: botUser,
GitClient: c,
ConfigAgent: ca,
Push: func(forkName, newBranch string, force bool) error { return nil },
Push: func(_, _ string, _ bool) error { return nil },
GitHubClient: ghc,
WebhookSecretGenerator: getSecret,
GitHubTokenGenerator: getGithubToken,
Expand Down
46 changes: 23 additions & 23 deletions internal/pkg/externalplugins/cherrypicker/cherrypicker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ type fghc struct {
collaborators []string
}

func (f *fghc) GetSingleCommit(org, repo, sha string) (github.RepositoryCommit, error) {
func (f *fghc) GetSingleCommit(_, _, sha string) (github.RepositoryCommit, error) {
f.Lock()
defer f.Unlock()
return f.commits[sha], nil
}

func (f *fghc) AddLabels(org, repo string, number int, labels ...string) error {
func (f *fghc) AddLabels(_, _ string, number int, labels ...string) error {
f.Lock()
defer f.Unlock()
for i := range f.prs {
Expand All @@ -128,7 +128,7 @@ func (f *fghc) AddLabels(org, repo string, number int, labels ...string) error {
return nil
}

func (f *fghc) AssignIssue(org, repo string, number int, logins []string) error {
func (f *fghc) AssignIssue(_, _ string, number int, logins []string) error {
f.Lock()
defer f.Unlock()
var users []github.User
Expand All @@ -143,19 +143,19 @@ func (f *fghc) AssignIssue(org, repo string, number int, logins []string) error
return nil
}

func (f *fghc) GetPullRequest(org, repo string, number int) (*github.PullRequest, error) {
func (f *fghc) GetPullRequest(string, string, int) (*github.PullRequest, error) {
f.Lock()
defer f.Unlock()
return f.pr, nil
}

func (f *fghc) GetPullRequestPatch(org, repo string, number int) ([]byte, error) {
func (f *fghc) GetPullRequestPatch(string, string, int) ([]byte, error) {
f.Lock()
defer f.Unlock()
return f.patch, nil
}

func (f *fghc) GetPullRequests(org, repo string) ([]github.PullRequest, error) {
func (f *fghc) GetPullRequests(string, string) ([]github.PullRequest, error) {
f.Lock()
defer f.Unlock()
return f.prs, nil
Expand All @@ -172,13 +172,13 @@ func (f *fghc) CreateComment(org, repo string, number int, comment string) error
return nil
}

func (f *fghc) GetRepo(owner, name string) (github.FullRepo, error) {
func (f *fghc) GetRepo(_, _ string) (github.FullRepo, error) {
f.Lock()
defer f.Unlock()
return github.FullRepo{}, nil
}

func (f *fghc) EnsureFork(forkingUser, org, repo string) (string, error) {
func (f *fghc) EnsureFork(_, _, repo string) (string, error) {
if repo == "changeme" {
return "changed", nil
}
Expand All @@ -188,7 +188,7 @@ func (f *fghc) EnsureFork(forkingUser, org, repo string) (string, error) {
return repo, nil
}

func (f *fghc) IsMember(org, user string) (bool, error) {
func (f *fghc) IsMember(_, user string) (bool, error) {
f.Lock()
defer f.Unlock()

Expand All @@ -200,15 +200,15 @@ func (f *fghc) IsMember(org, user string) (bool, error) {
}
}

func (f *fghc) IsCollaborator(org, repo, user string) (bool, error) {
func (f *fghc) IsCollaborator(_, _, user string) (bool, error) {
if strings.Contains(user, patternErrWhenIsCollaborator) {
return false, errors.New("fake error")
}

return sets.NewString(f.collaborators...).Has(user), nil
}

func (f *fghc) AddCollaborator(org, repo, user string, permission github.RepoPermissionLevel) error {
func (f *fghc) AddCollaborator(_, _, user string, _ github.RepoPermissionLevel) error {
if strings.Contains(user, patternErrWhenAddCollaborator) {
return errors.New("fake error")
}
Expand All @@ -217,7 +217,7 @@ func (f *fghc) AddCollaborator(org, repo, user string, permission github.RepoPer
return nil
}

func (f *fghc) ListRepoInvitations(org, repo string) ([]*gc.RepositoryInvitation, error) {
func (f *fghc) ListRepoInvitations(string, string) ([]*gc.RepositoryInvitation, error) {
return f.repoInvitations, nil
}

Expand All @@ -234,7 +234,7 @@ func prToString(pr github.PullRequest) string {
return fmt.Sprintf(prFormat, pr.Title, pr.Body, pr.Head.Ref, pr.Base.Ref, labels, assignees)
}

func (f *fghc) CreateIssue(org, repo, title, body string, milestone int, labels, assignees []string) (int, error) {
func (f *fghc) CreateIssue(_, _, title, body string, _ int, labels, assignees []string) (int, error) {
f.Lock()
defer f.Unlock()

Expand Down Expand Up @@ -262,7 +262,7 @@ func (f *fghc) CreateIssue(org, repo, title, body string, milestone int, labels,
return num, nil
}

func (f *fghc) CreatePullRequest(org, repo, title, body, head, base string, canModify bool) (int, error) {
func (f *fghc) CreatePullRequest(_, _, title, body, head, base string, _ bool) (int, error) {
f.Lock()
defer f.Unlock()
num := len(f.prs) + 1
Expand All @@ -276,19 +276,19 @@ func (f *fghc) CreatePullRequest(org, repo, title, body, head, base string, canM
return num, nil
}

func (f *fghc) ListIssueComments(org, repo string, number int) ([]github.IssueComment, error) {
func (f *fghc) ListIssueComments(_, _ string, _ int) ([]github.IssueComment, error) {
f.Lock()
defer f.Unlock()
return f.prComments, nil
}

func (f *fghc) GetIssueLabels(org, repo string, number int) ([]github.Label, error) {
func (f *fghc) GetIssueLabels(_, _ string, _ int) ([]github.Label, error) {
f.Lock()
defer f.Unlock()
return f.prLabels, nil
}

func (f *fghc) ListOrgMembers(org, role string) ([]github.TeamMember, error) {
func (f *fghc) ListOrgMembers(_, role string) ([]github.TeamMember, error) {
f.Lock()
defer f.Unlock()
if role != "all" {
Expand All @@ -297,7 +297,7 @@ func (f *fghc) ListOrgMembers(org, role string) ([]github.TeamMember, error) {
return f.orgMembers, nil
}

func (f *fghc) CreateFork(org, repo string) (string, error) {
func (f *fghc) CreateFork(_, repo string) (string, error) {
return repo, nil
}

Expand Down Expand Up @@ -418,7 +418,7 @@ func testCherryPickIC(clients localgit.Clients, t *testing.T) {
BotUser: botUser,
GitClient: c,
ConfigAgent: ca,
Push: func(forkName, newBranch string, force bool) error { return nil },
Push: func(_, _ string, _ bool) error { return nil },
GitHubClient: ghc,
WebhookSecretGenerator: getSecret,
GitHubTokenGenerator: getGithubToken,
Expand Down Expand Up @@ -600,7 +600,7 @@ func testCherryPickPRWithLabels(clients localgit.Clients, t *testing.T) {
BotUser: botUser,
GitClient: c,
ConfigAgent: ca,
Push: func(forkName, newBranch string, force bool) error { return nil },
Push: func(_, _ string, _ bool) error { return nil },
GitHubClient: ghc,
WebhookSecretGenerator: getSecret,
GitHubTokenGenerator: getGithubToken,
Expand Down Expand Up @@ -810,7 +810,7 @@ func testCherryPickPRWithComment(clients localgit.Clients, t *testing.T) {
BotUser: botUser,
GitClient: c,
ConfigAgent: ca,
Push: func(forkName, newBranch string, force bool) error { return nil },
Push: func(_, _ string, _ bool) error { return nil },
GitHubClient: ghc,
WebhookSecretGenerator: getSecret,
GitHubTokenGenerator: getGithubToken,
Expand Down Expand Up @@ -1037,7 +1037,7 @@ func testCherryPickPRLabeled(clients localgit.Clients, t *testing.T) {
BotUser: botUser,
GitClient: c,
ConfigAgent: ca,
Push: func(forkName, newBranch string, force bool) error { return nil },
Push: func(_, _ string, _ bool) error { return nil },
GitHubClient: ghc,
WebhookSecretGenerator: getSecret,
GitHubTokenGenerator: getGithubToken,
Expand Down Expand Up @@ -1363,7 +1363,7 @@ type threadUnsafeFGHC struct {
orgRepoCountCalled int
}

func (tuf *threadUnsafeFGHC) EnsureFork(login, org, repo string) (string, error) {
func (tuf *threadUnsafeFGHC) EnsureFork(_, _, _ string) (string, error) {
tuf.orgRepoCountCalled++
return "", errors.New("that is enough")
}
Expand Down
4 changes: 1 addition & 3 deletions internal/pkg/externalplugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,7 @@ func validateLabelBlockerAction(actions []string) error {
allowActionSet := sets.NewString(LabeledAction, UnlabeledAction)

for _, action := range actions {
if allowActionSet.Has(action) {
continue
} else {
if !allowActionSet.Has(action) {
return fmt.Errorf("actions contain illegal value %s", action)
}
}
Expand Down
Loading

0 comments on commit ac98cbf

Please sign in to comment.