From 6d76369cb1a1f01ec283c8cfc1d492a92fb9a178 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 29 Sep 2023 15:09:54 -0700 Subject: [PATCH] Add more properties to github.organization and github.repository (#1865) Use new things in the updated library Signed-off-by: Tim Smith --- providers/github/resources/github.lr | 6 ++++ providers/github/resources/github.lr.go | 36 +++++++++++++++++++ .../github/resources/github.lr.manifest.yaml | 6 ++++ providers/github/resources/github_org.go | 1 + providers/github/resources/github_repo.go | 4 +++ 5 files changed, 53 insertions(+) diff --git a/providers/github/resources/github.lr b/providers/github/resources/github.lr index 74e7143e2d..7b565b50cd 100644 --- a/providers/github/resources/github.lr +++ b/providers/github/resources/github.lr @@ -110,6 +110,8 @@ github.organization @defaults("login name") { membersCanCreatePublicPages bool // Whether members can create private pages membersCanCreatePrivatePages bool + // Whether members can create private repositories + membersCanForkPrivateRepos bool // List of users that are part of the owners group owners() []github.user // List of users that are part of the members group @@ -283,6 +285,10 @@ private github.repository @defaults("fullName") { hasPages bool // Whether the repository has downloads hasDownloads bool + // Whether the repository has discussions + hasDiscussions bool + // Whether the repository is an organization repository template + isTemplate bool // Whether the repository has open merge requests openMergeRequests() []github.mergeRequest // List of branches for the repository diff --git a/providers/github/resources/github.lr.go b/providers/github/resources/github.lr.go index 79df5d9a8d..a78c3ee115 100644 --- a/providers/github/resources/github.lr.go +++ b/providers/github/resources/github.lr.go @@ -316,6 +316,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "github.organization.membersCanCreatePrivatePages": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubOrganization).GetMembersCanCreatePrivatePages()).ToDataRes(types.Bool) }, + "github.organization.membersCanForkPrivateRepos": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubOrganization).GetMembersCanForkPrivateRepos()).ToDataRes(types.Bool) + }, "github.organization.owners": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubOrganization).GetOwners()).ToDataRes(types.Array(types.Resource("github.user"))) }, @@ -544,6 +547,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "github.repository.hasDownloads": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubRepository).GetHasDownloads()).ToDataRes(types.Bool) }, + "github.repository.hasDiscussions": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubRepository).GetHasDiscussions()).ToDataRes(types.Bool) + }, + "github.repository.isTemplate": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubRepository).GetIsTemplate()).ToDataRes(types.Bool) + }, "github.repository.openMergeRequests": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubRepository).GetOpenMergeRequests()).ToDataRes(types.Array(types.Resource("github.mergeRequest"))) }, @@ -1110,6 +1119,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlGithubOrganization).MembersCanCreatePrivatePages, ok = plugin.RawToTValue[bool](v.Value, v.Error) return }, + "github.organization.membersCanForkPrivateRepos": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubOrganization).MembersCanForkPrivateRepos, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, "github.organization.owners": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlGithubOrganization).Owners, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -1434,6 +1447,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlGithubRepository).HasDownloads, ok = plugin.RawToTValue[bool](v.Value, v.Error) return }, + "github.repository.hasDiscussions": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubRepository).HasDiscussions, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "github.repository.isTemplate": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubRepository).IsTemplate, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, "github.repository.openMergeRequests": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlGithubRepository).OpenMergeRequests, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -2225,6 +2246,7 @@ type mqlGithubOrganization struct { MembersCanCreatePages plugin.TValue[bool] MembersCanCreatePublicPages plugin.TValue[bool] MembersCanCreatePrivatePages plugin.TValue[bool] + MembersCanForkPrivateRepos plugin.TValue[bool] Owners plugin.TValue[[]interface{}] Members plugin.TValue[[]interface{}] Teams plugin.TValue[[]interface{}] @@ -2399,6 +2421,10 @@ func (c *mqlGithubOrganization) GetMembersCanCreatePrivatePages() *plugin.TValue return &c.MembersCanCreatePrivatePages } +func (c *mqlGithubOrganization) GetMembersCanForkPrivateRepos() *plugin.TValue[bool] { + return &c.MembersCanForkPrivateRepos +} + func (c *mqlGithubOrganization) GetOwners() *plugin.TValue[[]interface{}] { return plugin.GetOrCompute[[]interface{}](&c.Owners, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { @@ -2973,6 +2999,8 @@ type mqlGithubRepository struct { HasWiki plugin.TValue[bool] HasPages plugin.TValue[bool] HasDownloads plugin.TValue[bool] + HasDiscussions plugin.TValue[bool] + IsTemplate plugin.TValue[bool] OpenMergeRequests plugin.TValue[[]interface{}] Branches plugin.TValue[[]interface{}] DefaultBranchName plugin.TValue[string] @@ -3152,6 +3180,14 @@ func (c *mqlGithubRepository) GetHasDownloads() *plugin.TValue[bool] { return &c.HasDownloads } +func (c *mqlGithubRepository) GetHasDiscussions() *plugin.TValue[bool] { + return &c.HasDiscussions +} + +func (c *mqlGithubRepository) GetIsTemplate() *plugin.TValue[bool] { + return &c.IsTemplate +} + func (c *mqlGithubRepository) GetOpenMergeRequests() *plugin.TValue[[]interface{}] { return plugin.GetOrCompute[[]interface{}](&c.OpenMergeRequests, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { diff --git a/providers/github/resources/github.lr.manifest.yaml b/providers/github/resources/github.lr.manifest.yaml index 9281696b11..85857f39eb 100755 --- a/providers/github/resources/github.lr.manifest.yaml +++ b/providers/github/resources/github.lr.manifest.yaml @@ -233,6 +233,8 @@ resources: min_mondoo_version: 6.11.0 membersCanCreateRepositories: min_mondoo_version: 6.11.0 + membersCanForkPrivateRepos: + min_mondoo_version: 9.0.0 name: {} node_id: {} nodeId: @@ -325,6 +327,8 @@ resources: forksCount: min_mondoo_version: 7.14.0 fullName: {} + hasDiscussions: + min_mondoo_version: 9.0.0 hasDownloads: min_mondoo_version: 7.14.0 hasIssues: @@ -339,6 +343,8 @@ resources: id: {} isFork: min_mondoo_version: 7.14.0 + isTemplate: + min_mondoo_version: 9.0.0 language: min_mondoo_version: 7.14.0 license: diff --git a/providers/github/resources/github_org.go b/providers/github/resources/github_org.go index dd710c279a..5f39fce82c 100644 --- a/providers/github/resources/github_org.go +++ b/providers/github/resources/github_org.go @@ -81,6 +81,7 @@ func initGithubOrganization(runtime *plugin.Runtime, args map[string]*llx.RawDat args["membersCanCreatePages"] = llx.BoolData(convert.ToBool(org.MembersCanCreatePages)) args["membersCanCreatePublicPages"] = llx.BoolData(convert.ToBool(org.MembersCanCreatePublicPages)) args["membersCanCreatePrivatePages"] = llx.BoolData(convert.ToBool(org.MembersCanCreatePrivateRepos)) + args["membersCanForkPrivateRepos"] = llx.BoolData(convert.ToBool(org.MembersCanForkPrivateRepos)) return args, nil, nil } diff --git a/providers/github/resources/github_repo.go b/providers/github/resources/github_repo.go index 333dc3a876..c0e5986ec4 100644 --- a/providers/github/resources/github_repo.go +++ b/providers/github/resources/github_repo.go @@ -62,6 +62,8 @@ func newMqlGithubRepository(runtime *plugin.Runtime, repo *github.Repository) (* "hasWiki": llx.BoolData(repo.GetHasWiki()), "hasPages": llx.BoolData(repo.GetHasPages()), "hasDownloads": llx.BoolData(repo.GetHasDownloads()), + "hasDiscussions": llx.BoolData(repo.GetHasDiscussions()), + "isTemplate": llx.BoolData(repo.GetIsTemplate()), "defaultBranchName": llx.StringDataPtr(repo.DefaultBranch), "cloneUrl": llx.StringData(repo.GetCloneURL()), "sshUrl": llx.StringData(repo.GetSSHURL()), @@ -206,6 +208,8 @@ func initGithubRepository(runtime *plugin.Runtime, args map[string]*llx.RawData) args["hasWiki"] = llx.BoolData(repo.GetHasWiki()) args["hasPages"] = llx.BoolData(repo.GetHasPages()) args["hasDownloads"] = llx.BoolData(repo.GetHasDownloads()) + args["hasDiscussions"] = llx.BoolData(repo.GetHasDiscussions()) + args["isTemplate"] = llx.BoolData(repo.GetIsTemplate()) args["defaultBranchName"] = llx.StringDataPtr(repo.DefaultBranch) args["cloneUrl"] = llx.StringData(repo.GetCloneURL()) args["sshUrl"] = llx.StringData(repo.GetSSHURL())