github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/github/ghmetrics/ghpath.go (about)

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ghmetrics
    18  
    19  import (
    20  	"sigs.k8s.io/prow/pkg/simplifypath"
    21  )
    22  
    23  func repositoryTree() []simplifypath.Node {
    24  	return []simplifypath.Node{
    25  		l("branches", v("branch", l("protection",
    26  			l("restrictions", l("users"), l("teams")),
    27  			l("required_status_checks", l("contexts")),
    28  			l("required_pull_request_reviews"),
    29  			l("required_signatures"),
    30  			l("enforce_admins")))),
    31  		l("issues",
    32  			l("comments", v("commentId")),
    33  			l("events", v("eventId")),
    34  			v("issueId",
    35  				l("lock"),
    36  				l("comments"),
    37  				l("events"),
    38  				l("assignees"),
    39  				l("reactions"),
    40  				l("labels", simplifypath.VGreedy("labelId")))),
    41  		l("keys", v("keyId")),
    42  		l("labels", v("labelId")),
    43  		l("milestones", v("milestone")),
    44  		l("pulls",
    45  			v("pullId",
    46  				l("commits"),
    47  				l("files"),
    48  				l("comments"),
    49  				l("reviews"),
    50  				l("requested_reviewers"),
    51  				l("merge"))),
    52  		l("releases", v("releaseId")),
    53  		l("statuses", v("statusId")),
    54  		l("subscribers", v("subscriberId")),
    55  		l("assignees", v("assigneeId")),
    56  		l("archive", v("zip")),
    57  		l("collaborators", v("collaboratorId", l("permission"))),
    58  		l("comments", v("commentId")),
    59  		l("compare", v("sha")),
    60  		l("contents", v("contentId")),
    61  		l("commits",
    62  			v("sha",
    63  				l("check-runs"),
    64  				l("status")),
    65  		),
    66  		l("git",
    67  			l("commits", v("sha")),
    68  			l("ref", v("refId")),
    69  			l("tags", v("tagId")),
    70  			l("trees", v("sha")),
    71  			l("refs", l("heads", v("ref")))),
    72  		l("stars"),
    73  		l("merges"),
    74  		l("stargazers"),
    75  		l("notifications"),
    76  		l("hooks"),
    77  		l("deployments"),
    78  		l("downloads"),
    79  		l("events"),
    80  		l("forks"),
    81  		l("topics"),
    82  		l("vulnerability-alerts"),
    83  		l("automated-security-fixes"),
    84  		l("contributors"),
    85  		l("languages"),
    86  		l("teams"),
    87  		l("tags"),
    88  		l("transfer"),
    89  	}
    90  }
    91  
    92  func organizationTree() []simplifypath.Node {
    93  	return []simplifypath.Node{
    94  		l("credential-authorizations", v("credentialId")),
    95  		l("repos"),
    96  		l("issues"),
    97  		l("invitations"),
    98  		l("members", v("login")),
    99  		l("memberships", v("login")),
   100  		l("teams"),
   101  		l("team", v("teamId",
   102  			l("repos"),
   103  			l("members"))),
   104  	}
   105  }
   106  
   107  var simplifier = simplifypath.NewSimplifier(l("", // shadow element mimicing the root
   108  	l(""),
   109  	l("app", l("installations", v("id", l("access_tokens")))),
   110  	l("repos",
   111  		v("owner",
   112  			v("repo",
   113  				repositoryTree()...))),
   114  	l("repositories",
   115  		v("repoId",
   116  			repositoryTree()...)),
   117  	l("user",
   118  		l("following", v("userId")),
   119  		l("keys", v("keyId")),
   120  		l("email", l("visibility")),
   121  		l("emails"),
   122  		l("public_emails"),
   123  		l("followers"),
   124  		l("starred"),
   125  		l("issues"),
   126  		v("id", l("repos")),
   127  	),
   128  	l("users",
   129  		v("username",
   130  			l("followers", v("username")),
   131  			l("repos"),
   132  			l("hovercard"),
   133  			l("following"))),
   134  	l("orgs",
   135  		v("orgname",
   136  			organizationTree()...)),
   137  	l("organizations",
   138  		v("orgId",
   139  			organizationTree()...)),
   140  	l("organizations",
   141  		v("orgId",
   142  			l("members"),
   143  			l("repos"),
   144  			l("teams"))),
   145  	l("issues", v("issueId")),
   146  	l("search",
   147  		l("repositories"),
   148  		l("commits"),
   149  		l("code"),
   150  		l("issues"),
   151  		l("users"),
   152  		l("topics"),
   153  		l("labels")),
   154  	l("gists",
   155  		l("public"),
   156  		l("starred")),
   157  	l("notifications", l("threads", v("threadId", l("subscription")))),
   158  	l("emojis"),
   159  	l("events"),
   160  	l("feeds"),
   161  	l("hub"),
   162  	l("rate_limit"),
   163  	l("teams", v("id",
   164  		l("members"),
   165  		l("memberships", v("user")),
   166  		l("repos", v("org", v("repo"))),
   167  		l("invitations"),
   168  	)),
   169  	// end point for gh api v4
   170  	l("graphql"),
   171  	l("licenses")))
   172  
   173  // l and v keep the tree legible
   174  
   175  func l(fragment string, children ...simplifypath.Node) simplifypath.Node {
   176  	return simplifypath.L(fragment, children...)
   177  }
   178  
   179  func v(fragment string, children ...simplifypath.Node) simplifypath.Node {
   180  	return simplifypath.V(fragment, children...)
   181  }