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

refactor: Updated compatibility report to set colum headers, support collection of targets, default to markdown as output report #9

Merged
merged 1 commit into from
Apr 23, 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
2 changes: 1 addition & 1 deletion flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func createAndParseFlags(args []string) error {

flags.outputFormat = NewStringEnumValue(
[]string{"ascii", "markdown"},
"ascii",
"markdown",
)
fs.VarP(
flags.outputFormat,
Expand Down
47 changes: 20 additions & 27 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,7 @@ var agentRepo = nrRepo{url: `https://github.com/newrelic/node-newrelic.git`, bra
var apolloRepo = nrRepo{url: `https://github.com/newrelic/newrelic-node-apollo-server-plugin.git`, branch: `main`, testPath: `tests/versioned`}
var nextRepo = nrRepo{url: `https://github.com/newrelic/newrelic-node-nextjs.git`, branch: `main`, testPath: `tests/versioned`}

type nrRepo struct {
repoDir string
url string
branch string
testPath string
}

type dirIterChan struct {
name string
pkg *VersionedTestPackageJson
err error
}

type repoIterChan struct {
repoDir string
testPath string
err error
}
var columHeaders = map[string]string{"Name": `Package Name`, "MinSupportedVersion": `Minimum Supported Version`, "LatestVersion": `Latest Supported Version`, "MinAgentVersion": `Minimum Agent Version*`}

func main() {
err := run(os.Args)
Expand Down Expand Up @@ -202,6 +185,7 @@ func buildReleaseData(info PkgInfo, npm *NpmClient) (*ReleaseData, error) {
MinSupportedVersionRelease: minReleaseDate.ToFullDate().ToString(),
LatestVersion: latest,
LatestVersionRelease: latestReleaseDate.ToFullDate().ToString(),
MinAgentVersion: info.MinAgentVersion,
}

return result, nil
Expand Down Expand Up @@ -371,18 +355,24 @@ func renderAsMarkdown(data []ReleaseData, writer io.Writer) {
outputTable := releaseDataToTable(data)
io.WriteString(
writer,
heredoc.Docf(`
heredoc.Doc(`
## Instrumented Modules

The following table lists the modules that the %[1]newrelic%[1] Node.js
agent instruments, along with the minimum version of the module the agent
supports, the release date of that minimum version, and the version plus
release date of the most recent version (as of the time this document
was generated).
`, "`"),
After installation, the agent automatically instruments with our catalog of supported Node.js libraries and frameworks. This gives you immediate access to granular information specific to your web apps and servers. For unsupported frameworks or libraries, you'll need to instrument the agent yourself using the [Node.js agent API](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/api-guides/nodejs-agent-api/).

**Note**: The latest supported version may not reflect the most recent supported version.

`),
)
io.WriteString(writer, "\n")
io.WriteString(writer, outputTable.RenderMarkdown())
io.WriteString(writer, "\n\n")
io.WriteString(
writer,
heredoc.Docf(`
*When package is not specified, support is within the %snewrelic%s package.
`, "`", "`"),
)
}

func releaseDataToTable(data []ReleaseData) table.Writer {
Expand All @@ -393,8 +383,11 @@ func releaseDataToTable(data []ReleaseData) table.Writer {
rv := reflect.ValueOf(ReleaseData{})
rt := rv.Type()
for i := 0; i < rv.NumField(); i += 1 {
header = append(header, rt.Field(i).Name)
keys = append(keys, rt.Field(i).Name)
var value = rt.Field(i).Name
if columnHeader, ok := columHeaders[value]; ok {
header = append(header, columnHeader)
keys = append(keys, value)
}
}
outputTable.AppendHeader(header)

Expand Down
15 changes: 9 additions & 6 deletions parse-package.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package main

import (
"blitznote.com/src/semver/v3"
"errors"
"fmt"

"blitznote.com/src/semver/v3"
)

var ErrTargetMissing = errors.New("targets not found in dependencies list")

type PkgInfo struct {
Name string
MinVersion string
Name string
MinVersion string
MinAgentVersion string
}

func parsePackage(pkg *VersionedTestPackageJson) ([]PkgInfo, error) {
Expand All @@ -25,7 +27,7 @@ func parsePackage(pkg *VersionedTestPackageJson) ([]PkgInfo, error) {
}

for key, val := range test.Dependencies {
if key != target {
if key != target.Name {
continue
}

Expand All @@ -50,8 +52,9 @@ func parsePackage(pkg *VersionedTestPackageJson) ([]PkgInfo, error) {
}

pkgInfo := PkgInfo{
Name: target,
MinVersion: lastVersion.GetLowerBoundary().String(),
Name: target.Name,
MinVersion: lastVersion.GetLowerBoundary().String(),
MinAgentVersion: target.MinAgentVersion,
}
results = append(results, pkgInfo)
}
Expand Down
28 changes: 27 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@ import (
"bytes"
"encoding/json"
"fmt"

"github.com/spf13/cast"
)

type nrRepo struct {
repoDir string
url string
branch string
testPath string
}

type dirIterChan struct {
name string
pkg *VersionedTestPackageJson
err error
}

type repoIterChan struct {
repoDir string
testPath string
err error
}

// ReleaseData represents a row of information about a package. Specifically,
// it's the final computed information to be rendered into documents.
type ReleaseData struct {
Expand All @@ -15,11 +35,17 @@ type ReleaseData struct {
MinSupportedVersionRelease string
LatestVersion string
LatestVersionRelease string
MinAgentVersion string
}

type Target struct {
Name string `json:"name"`
MinAgentVersion string `json:"minAgentVersion"`
}

type VersionedTestPackageJson struct {
Name string `json:"name"`
Targets []string `json:"targets"`
Targets []Target `json:"targets"`
Version string `json:"version"`
Private bool `json:"private"`
Tests []TestDescription `json:"tests"`
Expand Down
Loading