Skip to content

Commit

Permalink
fix: remove linterName from agent
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJi committed Sep 6, 2024
1 parent 08d3b0c commit 575c6f8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func applyCustomConfig(legacy, custom Linter) Linter {
legacy.DockerAsRunner.CopyLinterFromOrigin = custom.DockerAsRunner.CopyLinterFromOrigin
}

if custom.Name != "" {
legacy.Name = custom.Name
}

return legacy
}

Expand Down
2 changes: 1 addition & 1 deletion internal/linters/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func CreateGithubChecks(ctx context.Context, a Agent, lintErrs map[string][]Lint
owner = a.PullRequestEvent.Repo.GetOwner().GetLogin()
repo = a.PullRequestEvent.Repo.GetName()
startTime = a.PullRequestEvent.GetPullRequest().GetUpdatedAt()
linterName = a.LinterName
linterName = a.LinterConfig.Name
)

annotations := toGithubCheckRunAnnotations(lintErrs)
Expand Down
6 changes: 2 additions & 4 deletions internal/linters/linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ type Agent struct {
PullRequestEvent github.PullRequestEvent
// PullRequestChangedFiles is the changed files of a pull request.
PullRequestChangedFiles []*github.CommitFile
// LinterName is the linter name.
LinterName string
// RepoDir is the repo directory.
RepoDir string

Expand All @@ -147,7 +145,7 @@ If you have any questions about this comment, feel free to raise an issue here:
type LinterParser func(*xlog.Logger, []byte) (map[string][]LinterOutput, []string)

func GeneralHandler(log *xlog.Logger, a Agent, execRun func(a Agent) ([]byte, error), linterParser func(*xlog.Logger, []byte) (map[string][]LinterOutput, []string)) error {
linterName := a.LinterName
linterName := a.LinterConfig.Name
output, err := execRun(a)
if err != nil {
// NOTE(CarlJi): the error is *ExitError, it seems to have little information and needs to be handled in a better way.
Expand Down Expand Up @@ -212,7 +210,7 @@ func Report(log *xlog.Logger, a Agent, lintResults map[string][]LinterOutput) er
org = a.PullRequestEvent.Repo.GetOwner().GetLogin()
repo = a.PullRequestEvent.Repo.GetName()
orgRepo = a.PullRequestEvent.Repo.GetFullName()
linterName = a.LinterName
linterName = a.LinterConfig.Name
)

log.Infof("[%s] found total %d files with %d lint errors on repo %v", linterName, len(lintResults), countLinterErrors(lintResults), orgRepo)
Expand Down
3 changes: 0 additions & 3 deletions internal/linters/linters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func TestExecRun(t *testing.T) {
{
id: "case1 - without ARTIFACT",
input: Agent{
LinterName: "ut",
LinterConfig: config.Linter{
Enable: &tp,
Command: []string{"/bin/bash", "-c", "--"},
Expand All @@ -201,7 +200,6 @@ func TestExecRun(t *testing.T) {
{
id: "case2 - with ARTIFACT",
input: Agent{
LinterName: "ut",
LinterConfig: config.Linter{
Enable: &tp,
Command: []string{"/bin/bash", "-c", "--"},
Expand All @@ -215,7 +213,6 @@ func TestExecRun(t *testing.T) {
{
id: "case2 - with multi files under ARTIFACT",
input: Agent{
LinterName: "ut",
LinterConfig: config.Linter{
Enable: &tp,
Command: []string{"/bin/bash", "-c", "--"},
Expand Down
3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ func (s *Server) handle(ctx context.Context, event *github.PullRequestEvent) err
GitClient: s.gitClientFactory,
PullRequestEvent: *event,
PullRequestChangedFiles: pullRequestAffectedFiles,
LinterName: name,
RepoDir: r.Directory(),
Context: ctx,
ID: uuid.New().String(),
Expand All @@ -288,7 +287,7 @@ func (s *Server) handle(ctx context.Context, event *github.PullRequestEvent) err
agent.Runner = r
agent.Storage = s.storage
agent.GenLogKey = func() string {
return fmt.Sprintf("%s/%s/%s", agent.LinterName, agent.PullRequestEvent.Repo.GetFullName(), agent.ID)
return fmt.Sprintf("%s/%s/%s", agent.LinterConfig.Name, agent.PullRequestEvent.Repo.GetFullName(), agent.ID)
}
agent.GenLogViewUrl = func() string {
// if serverAddr is not provided, return empty string
Expand Down

0 comments on commit 575c6f8

Please sign in to comment.