mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 11:41:27 +00:00
This introduces a linter to PRs to help with code reviews and code hygiene. I've also gone ahead and fixed (or ignored) the existing lints. I've only setup the default linters right now. There are many more options that are documented at https://golangci-lint.run/. The GitHub Action should add appropriate annotations to the lint job for the PR. Contributors can also lint locally using `make lint`.
44 lines
970 B
Go
44 lines
970 B
Go
package simulator
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/actions-runner-controller/actions-runner-controller/github"
|
|
"github.com/go-logr/logr"
|
|
)
|
|
|
|
type Simulator struct {
|
|
Client *github.Client
|
|
Log logr.Logger
|
|
}
|
|
|
|
func (c *Simulator) GetRunnerGroupsVisibleToRepository(ctx context.Context, org, repo string, managed *VisibleRunnerGroups) (*VisibleRunnerGroups, error) {
|
|
visible := NewVisibleRunnerGroups()
|
|
|
|
if org == "" {
|
|
panic(fmt.Sprintf("BUG: owner should not be empty in this context. repo=%v", repo))
|
|
}
|
|
|
|
runnerGroups, err := c.Client.ListOrganizationRunnerGroupsForRepository(ctx, org, repo)
|
|
if err != nil {
|
|
return visible, err
|
|
}
|
|
|
|
if c.Log.V(3).Enabled() {
|
|
c.Log.V(3).Info("ListOrganizationRunnerGroupsForRepository succeeded", "runerGroups", runnerGroups)
|
|
}
|
|
|
|
for _, runnerGroup := range runnerGroups {
|
|
ref := NewRunnerGroupFromGitHub(runnerGroup)
|
|
|
|
if !managed.Includes(ref) {
|
|
continue
|
|
}
|
|
|
|
visible.Add(ref)
|
|
}
|
|
|
|
return visible, nil
|
|
}
|