MCPcopy
hub / github.com/kubernetes/test-infra / loadCache

Method loadCache

robots/issue-creator/creator/creator.go:218–276  ·  view source on GitHub ↗

loadCache loads the valid labels for the repo, the currently authenticated user, and the issue cache from github.

()

Source from the content-addressed store, hash-verified

216
217// loadCache loads the valid labels for the repo, the currently authenticated user, and the issue cache from github.
218func (c *IssueCreator) loadCache() error {
219 user, err := c.client.GetUser("")
220 if err != nil {
221 return fmt.Errorf("failed to fetch the User struct for the current authenticated user. errmsg: %w", err)
222 }
223 if user == nil {
224 return fmt.Errorf("received a nil User struct pointer when trying to look up the currently authenticated user")
225 }
226 if user.Login == nil {
227 return fmt.Errorf("the user struct for the currently authenticated user does not specify a login")
228 }
229 c.authorName = *user.Login
230
231 // Try to get the list of valid labels for the repo.
232 if validLabels, err := c.client.GetRepoLabels(c.org, c.project); err != nil {
233 c.validLabels = nil
234 glog.Errorf("Failed to retrieve the list of valid labels for repo '%s/%s'. Allowing all labels. errmsg: %v\n", c.org, c.project, err)
235 } else {
236 c.validLabels = make([]string, 0, len(validLabels))
237 for _, label := range validLabels {
238 if label.Name != nil && *label.Name != "" {
239 c.validLabels = append(c.validLabels, *label.Name)
240 }
241 }
242 }
243 // Try to get the valid collaborators for the repo.
244 if collaborators, err := c.client.GetCollaborators(c.org, c.project); err != nil {
245 c.Collaborators = nil
246 glog.Errorf("Failed to retrieve the list of valid collaborators for repo '%s/%s'. Allowing all assignees. errmsg: %v\n", c.org, c.project, err)
247 } else {
248 c.Collaborators = make([]string, 0, len(collaborators))
249 for _, user := range collaborators {
250 if user.Login != nil && *user.Login != "" {
251 c.Collaborators = append(c.Collaborators, strings.ToLower(*user.Login))
252 }
253 }
254 }
255
256 // Populate the issue cache (allIssues).
257 issues, err := c.client.GetIssues(
258 c.org,
259 c.project,
260 &github.IssueListByRepoOptions{
261 State: "all",
262 Creator: c.authorName,
263 },
264 )
265 if err != nil {
266 return fmt.Errorf("failed to refresh the list of all issues created by %s in repo '%s/%s'. errmsg: %w", c.authorName, c.org, c.project, err)
267 }
268 if len(issues) == 0 {
269 glog.Warningf("IssueCreator found no issues in the repo '%s/%s' authored by '%s'.\n", c.org, c.project, c.authorName)
270 }
271 c.allIssues = make(map[int]*github.Issue)
272 for _, i := range issues {
273 c.allIssues[*i.Number] = i
274 }
275 return nil

Callers 2

initializeMethod · 0.95
TestIssueCreatorFunction · 0.95

Calls 5

makeFunction · 0.85
GetUserMethod · 0.65
GetRepoLabelsMethod · 0.65
GetCollaboratorsMethod · 0.65
GetIssuesMethod · 0.65

Tested by 1

TestIssueCreatorFunction · 0.76