Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #6

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# packaging-tools
# 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.
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.

Expand All @@ -31,7 +33,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
```
9 changes: 5 additions & 4 deletions cmd/release-notes/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 := ""
Expand All @@ -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 != "" {
Expand Down
31 changes: 23 additions & 8 deletions cmd/release-notes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading