From 292ab5055d20c8965c796c475fc8dbbcda512ce5 Mon Sep 17 00:00:00 2001 From: seph Date: Tue, 21 May 2024 13:25:11 -0400 Subject: [PATCH 1/3] Some tweaks I don't entirely remember why I have these, but I'm sure we need them --- cmd/release-notes/fetch.go | 9 +++++---- cmd/release-notes/main.go | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cmd/release-notes/fetch.go b/cmd/release-notes/fetch.go index 677c873..aea5e4b 100644 --- a/cmd/release-notes/fetch.go +++ b/cmd/release-notes/fetch.go @@ -7,13 +7,13 @@ import ( ) const query = ` -query ($after: String, $timestamp: GitTimestamp!) { +query ($after: String, $since: GitTimestamp!, $until: GitTimestamp!) { repository(owner: "osquery", name: "osquery") { nameWithOwner object(expression: "master") { ... on Commit { oid - history(first: 100, after: $after, since: $timestamp) { + history(first: 100, after: $after, since: $since, until: $until) { pageInfo { endCursor hasNextPage @@ -89,7 +89,7 @@ type responseType struct { } } -func fetchCommits(ctx context.Context, graphqlClient *graphql.Client, token string, timestamp string) ([]responseType, error) { +func fetchCommits(ctx context.Context, graphqlClient *graphql.Client, token, since, until string) ([]responseType, error) { responses := []responseType{} cursor := "" @@ -102,7 +102,8 @@ func fetchCommits(ctx context.Context, graphqlClient *graphql.Client, token stri // Empirically, we can always have timestamp. The // after cursor still has the desired effect. - req.Var("timestamp", timestamp) + req.Var("since", since) + req.Var("until", until) // Set pagination if cursor != "" { diff --git a/cmd/release-notes/main.go b/cmd/release-notes/main.go index 6398175..1030eab 100644 --- a/cmd/release-notes/main.go +++ b/cmd/release-notes/main.go @@ -55,16 +55,24 @@ func main() { graphqlClient := graphql.NewClient("https://api.github.com/graphql") //graphqlClient.Log = func(s string) { log.Println(s) } - timestamp, err := getGitTimeStamp(ctx, graphqlClient, *flGithubToken, *flLastRelease) + since, err := getGitTimeStamp(ctx, graphqlClient, *flGithubToken, *flLastRelease) if err != nil { log.Fatal(err) } - commits, err := getGitCommits(ctx, graphqlClient, *flGithubToken, timestamp) + until, err := getGitTimeStamp(ctx, graphqlClient, *flGithubToken, *flNewRelease) if err != nil { log.Fatal(err) } + commits, err := getGitCommits(ctx, graphqlClient, *flGithubToken, since, until) + if err != nil { + log.Fatal(err) + } + if len(commits) == 0 { + log.Fatal("No git commits retrieved. Either a bad GITHUB_TOKEN or bad shas") + } + if err := changelogSnippet(commits, *flExistingChangelog, *flLastRelease, *flNewRelease); err != nil { log.Fatal(err) } @@ -209,27 +217,34 @@ func (c *Commit) ChangeSection() clSection { switch { case c.labelsInclude("documentation"): return clDocs + case c.labelsInclude("test", "CI/CD", "build", "cmake", "libraries"): + return clBuild case c.labelsInclude("packs"): return clPacks + case c.labelsInclude("bug"): // This should happen before virtual tables + return clBugFixes + case c.labelsInclude("virtual tables"): + return clTable + } return clToFix } -// labelsInclude checks the labels on this PR for whether all +// labelsInclude checks the labels on this PR for whether any // requested labels are applied. func (c *Commit) labelsInclude(labels ...string) bool { for _, l := range labels { - if _, ok := c.PRLabels[l]; !ok { - return false + if _, ok := c.PRLabels[l]; ok { + return true } } - return true + return false } -func getGitCommits(ctx context.Context, graphqlClient *graphql.Client, token string, timestamp string) ([]*Commit, error) { - responses, err := fetchCommits(ctx, graphqlClient, token, timestamp) +func getGitCommits(ctx context.Context, graphqlClient *graphql.Client, token, since, until string) ([]*Commit, error) { + responses, err := fetchCommits(ctx, graphqlClient, token, since, until) if err != nil { return nil, err } From c64574aef184942c878eda896ca0e2f74286c7b6 Mon Sep 17 00:00:00 2001 From: seph Date: Tue, 21 May 2024 13:45:55 -0400 Subject: [PATCH 2/3] readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9eca3c4..1b873df 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # packaging-tools -Tools for maintaining osquery resources +Tools for maintaining osquery releases ## Release Notes & Changelog Generation `cmd/release-notes` is a simple wrapper around github to generate a CHANGELOG. Examines an existing CHANGELOG file, and enumerates commits -via graphql to generate list of things to add to the changelog. +via graphql to generate list of things to add to the changelog. Output will be displayed to stdout. @@ -31,7 +31,7 @@ go run ./cmd/release-notes --help As an example: ``` shell -export GITHUB_TOKEN="{REDACTED]" +export GITHUB_TOKEN=`gh config get -h github.com oauth_token` -go run ./cmd/release-notes --changelog ~/checkouts/osquery/osquery/CHANGELOG.md --last 4.5.0 --new 4.5.1 +go run ./cmd/release-notes --changelog ~/checkouts/osquery/osquery/CHANGELOG.md --last 5.12.1 --new 5.12.2 ``` From 3d3db406f7b27526179d23f1786a094df82247e2 Mon Sep 17 00:00:00 2001 From: seph Date: Tue, 21 May 2024 13:47:14 -0400 Subject: [PATCH 3/3] readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1b873df..5f1c3f4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -# packaging-tools +# Tools Tools for maintaining osquery releases ## Release Notes & Changelog Generation `cmd/release-notes` is a simple wrapper around github to generate a -CHANGELOG. Examines an existing CHANGELOG file, and enumerates commits -via graphql to generate list of things to add to the changelog. +CHANGELOG. It uses graphql to cather the list of all commits, and +then examines an existing CHANGELOG file to suggest the omissions. + +It categorizes the commits based on simple logic based on the PR labels. Output will be displayed to stdout.