From 29b461d29f7734a69ce0ac45a347e7c8525f7499 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 4 May 2024 19:59:23 -0700 Subject: [PATCH] Add new fields to GH repos + handle null bools Add new fields + handle a few merge options that are bools with null values if not set 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_repo.go | 73 ++++++++++--------- 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/providers/github/resources/github.lr b/providers/github/resources/github.lr index 67bb1f8e6e..9373b1b5eb 100644 --- a/providers/github/resources/github.lr +++ b/providers/github/resources/github.lr @@ -354,6 +354,12 @@ private github.repository @defaults("fullName") { supportFile() github.file // Repository security file securityFile() github.file + // Whether the update branch button is enabled + allowUpdateBranch bool + // Whether commit signatures are required for commits + webCommitSignoffRequired bool + // Whether deleting pull request branches after merging a pull request is enabled + deleteBranchOnMerge bool } // GitHub license diff --git a/providers/github/resources/github.lr.go b/providers/github/resources/github.lr.go index 44725e97b2..91646ebc09 100644 --- a/providers/github/resources/github.lr.go +++ b/providers/github/resources/github.lr.go @@ -651,6 +651,15 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "github.repository.securityFile": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubRepository).GetSecurityFile()).ToDataRes(types.Resource("github.file")) }, + "github.repository.allowUpdateBranch": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubRepository).GetAllowUpdateBranch()).ToDataRes(types.Bool) + }, + "github.repository.webCommitSignoffRequired": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubRepository).GetWebCommitSignoffRequired()).ToDataRes(types.Bool) + }, + "github.repository.deleteBranchOnMerge": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubRepository).GetDeleteBranchOnMerge()).ToDataRes(types.Bool) + }, "github.license.key": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubLicense).GetKey()).ToDataRes(types.String) }, @@ -1645,6 +1654,18 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlGithubRepository).SecurityFile, ok = plugin.RawToTValue[*mqlGithubFile](v.Value, v.Error) return }, + "github.repository.allowUpdateBranch": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubRepository).AllowUpdateBranch, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "github.repository.webCommitSignoffRequired": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubRepository).WebCommitSignoffRequired, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "github.repository.deleteBranchOnMerge": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubRepository).DeleteBranchOnMerge, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, "github.license.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlGithubLicense).__id, ok = v.Value.(string) return @@ -3332,6 +3353,9 @@ type mqlGithubRepository struct { CodeOfConductFile plugin.TValue[*mqlGithubFile] SupportFile plugin.TValue[*mqlGithubFile] SecurityFile plugin.TValue[*mqlGithubFile] + AllowUpdateBranch plugin.TValue[bool] + WebCommitSignoffRequired plugin.TValue[bool] + DeleteBranchOnMerge plugin.TValue[bool] } // createGithubRepository creates a new instance of this resource @@ -3847,6 +3871,18 @@ func (c *mqlGithubRepository) GetSecurityFile() *plugin.TValue[*mqlGithubFile] { }) } +func (c *mqlGithubRepository) GetAllowUpdateBranch() *plugin.TValue[bool] { + return &c.AllowUpdateBranch +} + +func (c *mqlGithubRepository) GetWebCommitSignoffRequired() *plugin.TValue[bool] { + return &c.WebCommitSignoffRequired +} + +func (c *mqlGithubRepository) GetDeleteBranchOnMerge() *plugin.TValue[bool] { + return &c.DeleteBranchOnMerge +} + // mqlGithubLicense for the github.license resource type mqlGithubLicense struct { MqlRuntime *plugin.Runtime diff --git a/providers/github/resources/github.lr.manifest.yaml b/providers/github/resources/github.lr.manifest.yaml index af798f362b..c27d809da8 100755 --- a/providers/github/resources/github.lr.manifest.yaml +++ b/providers/github/resources/github.lr.manifest.yaml @@ -334,6 +334,8 @@ resources: min_mondoo_version: 6.4.0 allowSquashMerge: min_mondoo_version: 6.4.0 + allowUpdateBranch: + min_mondoo_version: 9.0.0 archived: {} branches: min_mondoo_version: 6.4.0 @@ -358,6 +360,8 @@ resources: min_mondoo_version: 9.0.0 defaultBranchName: min_mondoo_version: 6.4.0 + deleteBranchOnMerge: + min_mondoo_version: 9.0.0 description: {} disabled: {} files: @@ -427,6 +431,8 @@ resources: visibility: {} watchersCount: min_mondoo_version: 7.14.0 + webCommitSignoffRequired: + min_mondoo_version: 9.0.0 webhooks: min_mondoo_version: 6.11.0 workflows: diff --git a/providers/github/resources/github_repo.go b/providers/github/resources/github_repo.go index 6e526f8862..be6ece7eaf 100644 --- a/providers/github/resources/github_repo.go +++ b/providers/github/resources/github_repo.go @@ -37,41 +37,44 @@ func newMqlGithubRepository(runtime *plugin.Runtime, repo *github.Repository) (* } res, err := CreateResource(runtime, "github.repository", map[string]*llx.RawData{ - "id": llx.IntData(id), - "name": llx.StringDataPtr(repo.Name), - "fullName": llx.StringDataPtr(repo.FullName), - "description": llx.StringDataPtr(repo.Description), - "homepage": llx.StringDataPtr(repo.Homepage), - "topics": llx.ArrayData(convert.SliceAnyToInterface[string](repo.Topics), types.String), - "language": llx.StringData(repo.GetLanguage()), - "createdAt": llx.TimeDataPtr(githubTimestamp(repo.CreatedAt)), - "updatedAt": llx.TimeDataPtr(githubTimestamp(repo.UpdatedAt)), - "pushedAt": llx.TimeDataPtr(githubTimestamp(repo.PushedAt)), - "archived": llx.BoolDataPtr(repo.Archived), - "disabled": llx.BoolDataPtr(repo.Disabled), - "private": llx.BoolDataPtr(repo.Private), - "isFork": llx.BoolDataPtr(repo.Fork), - "watchersCount": llx.IntData(int64(repo.GetWatchersCount())), - "forksCount": llx.IntData(int64(repo.GetForksCount())), - "openIssuesCount": llx.IntData(int64(repo.GetOpenIssues())), - "stargazersCount": llx.IntData(int64(repo.GetStargazersCount())), - "visibility": llx.StringDataPtr(repo.Visibility), - "allowAutoMerge": llx.BoolDataPtr(repo.AllowAutoMerge), - "allowForking": llx.BoolDataPtr(repo.AllowForking), - "allowMergeCommit": llx.BoolDataPtr(repo.AllowMergeCommit), - "allowRebaseMerge": llx.BoolDataPtr(repo.AllowRebaseMerge), - "allowSquashMerge": llx.BoolDataPtr(repo.AllowSquashMerge), - "hasIssues": llx.BoolData(repo.GetHasIssues()), - "hasProjects": llx.BoolData(repo.GetHasProjects()), - "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()), - "owner": llx.ResourceData(owner, owner.MqlName()), + "id": llx.IntData(id), + "name": llx.StringDataPtr(repo.Name), + "fullName": llx.StringDataPtr(repo.FullName), + "description": llx.StringDataPtr(repo.Description), + "homepage": llx.StringDataPtr(repo.Homepage), + "topics": llx.ArrayData(convert.SliceAnyToInterface[string](repo.Topics), types.String), + "language": llx.StringData(repo.GetLanguage()), + "createdAt": llx.TimeDataPtr(githubTimestamp(repo.CreatedAt)), + "updatedAt": llx.TimeDataPtr(githubTimestamp(repo.UpdatedAt)), + "pushedAt": llx.TimeDataPtr(githubTimestamp(repo.PushedAt)), + "archived": llx.BoolDataPtr(repo.Archived), + "disabled": llx.BoolDataPtr(repo.Disabled), + "private": llx.BoolDataPtr(repo.Private), + "isFork": llx.BoolDataPtr(repo.Fork), + "watchersCount": llx.IntData(int64(repo.GetWatchersCount())), + "forksCount": llx.IntData(int64(repo.GetForksCount())), + "openIssuesCount": llx.IntData(int64(repo.GetOpenIssues())), + "stargazersCount": llx.IntData(int64(repo.GetStargazersCount())), + "visibility": llx.StringDataPtr(repo.Visibility), + "allowAutoMerge": llx.BoolData(convert.ToBool(repo.AllowAutoMerge)), + "allowForking": llx.BoolData(convert.ToBool(repo.AllowForking)), + "allowMergeCommit": llx.BoolData(convert.ToBool(repo.AllowMergeCommit)), + "allowRebaseMerge": llx.BoolData(convert.ToBool(repo.AllowRebaseMerge)), + "allowSquashMerge": llx.BoolData(convert.ToBool(repo.AllowSquashMerge)), + "allowUpdateBranch": llx.BoolData(convert.ToBool(repo.AllowUpdateBranch)), + "webCommitSignoffRequired": llx.BoolData(convert.ToBool(repo.WebCommitSignoffRequired)), + "deleteBranchOnMerge": llx.BoolData(convert.ToBool(repo.DeleteBranchOnMerge)), + "hasIssues": llx.BoolData(repo.GetHasIssues()), + "hasProjects": llx.BoolData(repo.GetHasProjects()), + "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()), + "owner": llx.ResourceData(owner, owner.MqlName()), }) if err != nil { return nil, err