Skip to content

Commit 0e9eb2c

Browse files
committed
Add new GitHub API endpoints for repositories
1 parent 2b85a83 commit 0e9eb2c

File tree

12 files changed

+75
-30
lines changed

12 files changed

+75
-30
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tmpdir = tmp
1414
all: test build
1515

1616
build: generate
17-
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o "$(builddir)/" ./...
17+
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o "$(builddir)/" ./cmd/...
1818

1919
check:
2020
golangci-lint run ./...
@@ -32,7 +32,8 @@ generate:
3232
GOOS= GOARCH= go generate -x ./...
3333

3434
install: all
35-
$(INSTALL_PROGRAM) -Dt "$(DESTDIR)$(bindir)" "$(builddir)"/*
35+
@$(INSTALL_PROGRAM) -d "$(DESTDIR)$(bindir)"
36+
@$(INSTALL_PROGRAM) -v "$(builddir)"/* "$(DESTDIR)$(bindir)"
3637

3738
test:
3839
@mkdir -p "$(tmpdir)/reports"

plugin/github/codescan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/code-scanning.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/code_scanning.go ../../docs
1818

1919
package github
2020

plugin/github/dependabot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/dependabot\*.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/dependabot\*.go ../../docs
1818

1919
package github
2020

plugin/github/depgraph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/dependency_graph.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/dependency_graph.go ../../docs
1818

1919
package github
2020

plugin/github/github.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,21 @@ type ghCfg struct {
6969
// PR
7070
reviewID int64
7171
// Repos
72-
affiliation string
73-
author string
74-
base string
75-
head string
76-
path string
77-
protected *bool
78-
ref string
79-
sha string
80-
sinceID int64
81-
sinceTime time.Time
82-
tag string
83-
typ string
84-
user string
85-
visibility string
72+
affiliation string
73+
author string
74+
base string
75+
head string
76+
path string
77+
protected *bool
78+
ref string
79+
sha string
80+
sinceID int64
81+
sinceTime time.Time
82+
subjectDigest *string
83+
tag string
84+
typ string
85+
user string
86+
visibility string
8687
// SecretScan
8788
// state string
8889
secretType []string

plugin/github/markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/markdown.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/markdown.go ../../docs
1818

1919
package github
2020

plugin/github/pr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/pulls\*.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/pulls\*.go ../../docs
1818

1919
package github
2020

plugin/github/repos.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/repos\*.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/repos\*.go ../../docs
1818

1919
package github
2020

@@ -31,9 +31,11 @@ import (
3131
func NewRepoCmd() *cobra.Command {
3232
var branch string
3333
var protected bool
34+
var subjectDigest string
3435
cfg := newGHCfg()
3536
cfg.branch = &branch
3637
cfg.protected = &protected
38+
cfg.subjectDigest = &subjectDigest
3739
cfg.visibility = "all"
3840
cfg.affiliation = "owner,collaborator,organization_member"
3941

@@ -51,13 +53,17 @@ func NewRepoCmd() *cobra.Command {
5153
"actions-permissions",
5254
"admin-enforcement",
5355
"all",
56+
"all-custom-property-values",
5457
"all-topics",
5558
"archive-link",
59+
"attestations",
5660
"automated-security-fixes",
5761
"branch",
5862
"branch-protection",
5963
"branches",
6064
"branches-head-commit",
65+
"by-authenticated-user",
66+
"by-user",
6167
"collaborators",
6268
"combined-status",
6369
"comment",
@@ -72,6 +78,7 @@ func NewRepoCmd() *cobra.Command {
7278
"contents",
7379
"contributors",
7480
"contributors-stats",
81+
"default-workflow-permissions",
7582
"download-contents",
7683
"download-contents-with-meta",
7784
"environment",
@@ -121,6 +128,8 @@ func NewRepoCmd() *cobra.Command {
121128
case "archive-link":
122129
addItemFlags(cfg, sub)
123130
sub.Flags().StringVar(cfg.branch, "branch", *cfg.branch, "Branch name")
131+
case "attestations":
132+
sub.Flags().StringVar(cfg.subjectDigest, "subject-digest", *cfg.subjectDigest, "The digest of the subject to get attestations for")
124133
case "branch":
125134
sub.Flags().StringVar(cfg.branch, "branch", *cfg.branch, "Branch name")
126135
case "branch-protection":
@@ -129,6 +138,17 @@ func NewRepoCmd() *cobra.Command {
129138
sub.Flags().StringVar(cfg.branch, "branch", *cfg.branch, "Branch name")
130139
case "branches":
131140
sub.Flags().BoolVar(cfg.protected, "protected", *cfg.protected, "Whether to return protected, unprotected, or all branches")
141+
case "by-authenticated-user":
142+
sub.Flags().StringVar(&cfg.visibility, "visibility", "all", "Visibility (all, public, private)")
143+
sub.Flags().StringVar(&cfg.affiliation, "affiliation", "owner,collaborator,organization_member", "Comma-separated list of (owner, collaborator, organization_member)")
144+
sub.Flags().StringVar(&cfg.typ, "type", "all", "Types of repositories you want returned (all, owner, public, private, member)")
145+
sub.Flags().StringVar(cfg.sort, "sort", "full_name", "The property to sort the results by (created, updated, pushed, full_name)")
146+
sub.Flags().StringVar(cfg.direction, "direction", *cfg.direction, `The order to sort by (default "asc" when using full_name, otherwise "desc")`)
147+
case "by-user":
148+
sub.Flags().StringVar(&cfg.user, "username", cfg.user, "Handle for the GitHub user account.")
149+
sub.Flags().StringVar(&cfg.typ, "type", "all", "Types of repositories you want returned (all, owner, member)")
150+
sub.Flags().StringVar(cfg.sort, "sort", "full_name", "The property to sort the results by (created, updated, pushed, full_name)")
151+
sub.Flags().StringVar(cfg.direction, "direction", *cfg.direction, `The order to sort by (default "asc" when using full_name, otherwise "desc")`)
132152
case "combined-status":
133153
sub.Flags().StringVar(&cfg.ref, "ref", cfg.ref, "Commit reference")
134154
case "comment":
@@ -216,11 +236,16 @@ func execRepos(cfg *ghCfg, cmd *cobra.Command) (x any, err error) {
216236
x, _, err = svc.GetAdminEnforcement(getCtx(cfg), cfg.owner, cfg.repo, *cfg.branch)
217237
case "all":
218238
x, _, err = svc.ListAll(getCtx(cfg), &github.RepositoryListAllOptions{Since: cfg.sinceID})
239+
case "all-custom-property-values":
240+
x, _, err = svc.GetAllCustomPropertyValues(getCtx(cfg), cfg.owner, cfg.repo)
219241
case "all-topics":
220242
x, _, err = svc.ListAllTopics(getCtx(cfg), cfg.owner, cfg.repo)
221243
case "archive-link":
222244
x, _, err = svc.GetArchiveLink(getCtx(cfg), cfg.owner, cfg.repo, github.Tarball,
223245
&github.RepositoryContentGetOptions{Ref: *cfg.branch}, int(cfg.id))
246+
case "attestations":
247+
x, _, err = svc.ListAttestations(getCtx(cfg), cfg.owner, cfg.repo, *cfg.subjectDigest,
248+
&github.ListOptions{Page: cfg.page, PerPage: cfg.perPage})
224249
case "automated-security-fixes":
225250
x, _, err = svc.GetAutomatedSecurityFixes(getCtx(cfg), cfg.owner, cfg.repo)
226251
case "branch":
@@ -233,6 +258,22 @@ func execRepos(cfg *ghCfg, cmd *cobra.Command) (x any, err error) {
233258
x, _, err = svc.ListBranches(getCtx(cfg), cfg.owner, cfg.repo, &github.BranchListOptions{
234259
Protected: cfg.protected, ListOptions: github.ListOptions{Page: cfg.page, PerPage: cfg.perPage},
235260
})
261+
case "by-authenticated-user":
262+
x, _, err = svc.ListByAuthenticatedUser(getCtx(cfg), &github.RepositoryListByAuthenticatedUserOptions{
263+
Visibility: cfg.visibility,
264+
Affiliation: cfg.affiliation,
265+
Type: cfg.typ,
266+
Sort: *cfg.sort,
267+
Direction: *cfg.direction,
268+
ListOptions: github.ListOptions{Page: cfg.page, PerPage: cfg.perPage},
269+
})
270+
case "by-user":
271+
x, _, err = svc.ListByUser(getCtx(cfg), cfg.user, &github.RepositoryListByUserOptions{
272+
Type: cfg.typ,
273+
Sort: *cfg.sort,
274+
Direction: *cfg.direction,
275+
ListOptions: github.ListOptions{Page: cfg.page, PerPage: cfg.perPage},
276+
})
236277
case "collaborators":
237278
x, _, err = svc.ListCollaborators(getCtx(cfg), cfg.owner, cfg.repo, &github.ListCollaboratorsOptions{
238279
Affiliation: "",
@@ -281,6 +322,8 @@ func execRepos(cfg *ghCfg, cmd *cobra.Command) (x any, err error) {
281322
})
282323
case "contributors-stats":
283324
x, _, err = svc.ListContributorsStats(getCtx(cfg), cfg.owner, cfg.repo)
325+
case "default-workflow-permissions":
326+
x, _, err = svc.GetDefaultWorkflowPermissions(getCtx(cfg), cfg.owner, cfg.repo)
284327
case "download-contents":
285328
x, _, err = svc.DownloadContents(getCtx(cfg), cfg.owner, cfg.repo, cfg.path, &github.RepositoryContentGetOptions{Ref: cfg.ref})
286329
case "download-contents-with-meta":

plugin/github/secretscan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/secret_scanning.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/secret_scanning.go ../../docs
1818

1919
package github
2020

plugin/github/teams.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//go:build !no_github
1616

17-
//go:generate go run github.com/abc-inc/heimdall/cmd/cmddoc github.com/google/go-github/v69@v69.2.0/github/teams\*.go ../../docs
17+
//go:generate go run github.com/abc-inc/heimdall/tools/cmddoc github.com/google/go-github/v69@v69.2.0/github/teams\*.go ../../docs
1818

1919
package github
2020

0 commit comments

Comments
 (0)