From d85d1c117d4a809ec47f3e531797ed197edcaf36 Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Mon, 26 Aug 2024 13:53:58 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Authored=20and=20Commited=20dates?= =?UTF-8?q?=20to=20:octocat:=20commits=20(#4607)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Authored and Commited date to :octocat: commits * fix: typo --- commited +++ committed --- providers/github/resources/github.lr | 4 ++++ providers/github/resources/github.lr.go | 24 +++++++++++++++++++ .../github/resources/github.lr.manifest.yaml | 6 +++++ providers/github/resources/github_repo.go | 20 +++++++++------- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/providers/github/resources/github.lr b/providers/github/resources/github.lr index 2586e7ac33..f835e25c7f 100644 --- a/providers/github/resources/github.lr +++ b/providers/github/resources/github.lr @@ -492,6 +492,10 @@ private github.commit @defaults("sha") { commit git.commit // Commit stats stats dict + // Authored Date + authoredDate time + // Committed Date + committedDate time } // GitHub repository pull request diff --git a/providers/github/resources/github.lr.go b/providers/github/resources/github.lr.go index af87ff7f55..aa0cca7ccb 100644 --- a/providers/github/resources/github.lr.go +++ b/providers/github/resources/github.lr.go @@ -810,6 +810,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "github.commit.stats": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubCommit).GetStats()).ToDataRes(types.Dict) }, + "github.commit.authoredDate": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubCommit).GetAuthoredDate()).ToDataRes(types.Time) + }, + "github.commit.committedDate": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubCommit).GetCommittedDate()).ToDataRes(types.Time) + }, "github.mergeRequest.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubMergeRequest).GetId()).ToDataRes(types.Int) }, @@ -1865,6 +1871,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlGithubCommit).Stats, ok = plugin.RawToTValue[interface{}](v.Value, v.Error) return }, + "github.commit.authoredDate": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubCommit).AuthoredDate, ok = plugin.RawToTValue[*time.Time](v.Value, v.Error) + return + }, + "github.commit.committedDate": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubCommit).CommittedDate, ok = plugin.RawToTValue[*time.Time](v.Value, v.Error) + return + }, "github.mergeRequest.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlGithubMergeRequest).__id, ok = v.Value.(string) return @@ -4341,6 +4355,8 @@ type mqlGithubCommit struct { Committer plugin.TValue[*mqlGithubUser] Commit plugin.TValue[*mqlGitCommit] Stats plugin.TValue[interface{}] + AuthoredDate plugin.TValue[*time.Time] + CommittedDate plugin.TValue[*time.Time] } // createGithubCommit creates a new instance of this resource @@ -4412,6 +4428,14 @@ func (c *mqlGithubCommit) GetStats() *plugin.TValue[interface{}] { return &c.Stats } +func (c *mqlGithubCommit) GetAuthoredDate() *plugin.TValue[*time.Time] { + return &c.AuthoredDate +} + +func (c *mqlGithubCommit) GetCommittedDate() *plugin.TValue[*time.Time] { + return &c.CommittedDate +} + // mqlGithubMergeRequest for the github.mergeRequest resource type mqlGithubMergeRequest struct { MqlRuntime *plugin.Runtime diff --git a/providers/github/resources/github.lr.manifest.yaml b/providers/github/resources/github.lr.manifest.yaml index 95043a2512..2a03b4cc7a 100755 --- a/providers/github/resources/github.lr.manifest.yaml +++ b/providers/github/resources/github.lr.manifest.yaml @@ -76,8 +76,14 @@ resources: github.commit: fields: author: {} + authoredDate: + min_mondoo_version: 9.0.0 commit: min_mondoo_version: 6.11.0 + commitedDate: + min_mondoo_version: 9.0.0 + committedDate: + min_mondoo_version: 9.0.0 committer: {} message: {} organizationName: {} diff --git a/providers/github/resources/github_repo.go b/providers/github/resources/github_repo.go index 2c4e8d13fc..34bebfaf8f 100644 --- a/providers/github/resources/github_repo.go +++ b/providers/github/resources/github_repo.go @@ -645,7 +645,7 @@ func newMqlGithubCommit(runtime *plugin.Runtime, rc *github.RepositoryCommit, ow conn := runtime.Connection.(*connection.GithubConnection) // if the github author is nil, we have to load the commit again - if rc.Author == nil { + if rc.Author == nil || rc.Commit == nil { rc, _, err = conn.Client().Repositories.GetCommit(conn.Context(), owner, repo, rc.GetSHA(), nil) if err != nil { return nil, err @@ -685,14 +685,16 @@ func newMqlGithubCommit(runtime *plugin.Runtime, rc *github.RepositoryCommit, ow } return CreateResource(runtime, "github.commit", map[string]*llx.RawData{ - "url": llx.StringData(rc.GetURL()), - "sha": llx.StringData(sha), - "author": llx.AnyData(githubAuthor), - "committer": llx.AnyData(githubCommitter), - "owner": llx.StringData(owner), - "repository": llx.StringData(repo), - "commit": llx.AnyData(mqlGitCommit), - "stats": llx.MapData(stats, types.Any), + "url": llx.StringData(rc.GetURL()), + "sha": llx.StringData(sha), + "author": llx.AnyData(githubAuthor), + "committer": llx.AnyData(githubCommitter), + "owner": llx.StringData(owner), + "repository": llx.StringData(repo), + "commit": llx.AnyData(mqlGitCommit), + "stats": llx.MapData(stats, types.Any), + "authoredDate": llx.TimeData(rc.Commit.Author.Date.Time), + "committedDate": llx.TimeData(rc.Commit.Committer.Date.Time), }) }