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

feat: implement granular versioning to aid in generating relevant changelogs #182

Merged
merged 1 commit into from
Aug 7, 2023
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
64 changes: 54 additions & 10 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"strings"

"github.com/speakeasy-api/speakeasy/internal/utils"
"golang.org/x/exp/slices"

markdown "github.com/MichaelMure/go-term-markdown"
changelog "github.com/speakeasy-api/openapi-generation/v2"
"github.com/speakeasy-api/openapi-generation/v2/changelogs"
"github.com/speakeasy-api/openapi-generation/v2/pkg/generate"
"github.com/speakeasy-api/speakeasy/internal/auth"
"github.com/speakeasy-api/speakeasy/internal/config"
Expand Down Expand Up @@ -165,9 +167,10 @@ func genSDKInit() {
genSDKCmd.Flags().BoolP("output-tests", "t", false, "output internal tests for internal speakeasy use cases")
genSDKCmd.Flags().MarkHidden("output-tests")

genSDKChangelogCmd.Flags().StringP("target", "t", "", "target version to get changelog from (default: the latest change)")
genSDKChangelogCmd.Flags().StringP("target", "t", "", "target version to get changelog from (required if language is specified otherwise defaults to latest version of the generator)")
genSDKChangelogCmd.Flags().StringP("previous", "p", "", "the version to get changelogs between this and the target version")
genSDKChangelogCmd.Flags().StringP("specific", "s", "", "the version to get changelogs for")
genSDKChangelogCmd.Flags().StringP("specific", "s", "", "the version to get changelogs for, not used if language is specified")
genSDKChangelogCmd.Flags().StringP("language", "l", "", "the language to get changelogs for, if not specified the changelog for the generator itself will be returned")
genSDKChangelogCmd.Flags().BoolP("raw", "r", false, "don't format the output for the terminal")

genSDKCmd.AddCommand(genSDKVersionCmd)
Expand Down Expand Up @@ -261,26 +264,67 @@ func getChangelogs(cmd *cobra.Command, args []string) error {
return err
}

lang, err := cmd.Flags().GetString("language")
if err != nil {
return err
}

raw, err := cmd.Flags().GetBool("raw")
if err != nil {
return err
}

opts := []changelog.Option{}

if targetVersion != "" {
opts = append(opts, changelog.WithTargetVersion(targetVersion))
var changeLog string

if lang != "" {
if !slices.Contains(generate.GetSupportedLanguages(), lang) {
return fmt.Errorf("unsupported language %s", lang)
}

if targetVersion == "" {
return fmt.Errorf("target version is required when specifying a language")
}

targetVersions := map[string]string{}

pairs := strings.Split(targetVersion, ",")
for i := 0; i < len(pairs); i += 2 {
targetVersions[pairs[i]] = pairs[i+1]
}

var previousVersions map[string]string

if previousVersion != "" {
opts = append(opts, changelog.WithPreviousVersion(previousVersion))
previousVersions = map[string]string{}

pairs := strings.Split(previousVersion, ",")
for i := 0; i < len(pairs); i += 2 {
previousVersions[pairs[i]] = pairs[i+1]
}
}

changeLog, err = changelogs.GetChangeLog(lang, targetVersions, previousVersions)
if err != nil {
return fmt.Errorf("failed to get changelog for language %s: %w", lang, err)
}
} else if specificVersion != "" {
opts = append(opts, changelog.WithSpecificVersion(specificVersion))
} else {
opts = append(opts, changelog.WithSpecificVersion(changelog.GetLatestVersion()))
}

changeLog := changelog.GetChangeLog(opts...)
if targetVersion != "" {
opts = append(opts, changelog.WithTargetVersion(targetVersion))

if previousVersion != "" {
opts = append(opts, changelog.WithPreviousVersion(previousVersion))
}
} else if specificVersion != "" {
opts = append(opts, changelog.WithSpecificVersion(specificVersion))
} else {
opts = append(opts, changelog.WithSpecificVersion(changelog.GetLatestVersion()))
}

changeLog = changelog.GetChangeLog(opts...)
}

if raw {
fmt.Println(changeLog)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/pb33f/libopenapi v0.9.3
github.com/sethvargo/go-githubactions v1.1.0
github.com/speakeasy-api/openapi-generation/v2 v2.81.1
github.com/speakeasy-api/openapi-generation/v2 v2.82.0
github.com/speakeasy-api/speakeasy-client-sdk-go v1.14.0
github.com/speakeasy-api/speakeasy-core v0.0.0-20230614153131-6b4b81e1c6a4
github.com/speakeasy-api/speakeasy-proxy v0.0.0-20230602101639-c41c44041e5a
Expand Down Expand Up @@ -116,7 +116,7 @@ require (
github.com/sethvargo/go-envconfig v0.9.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/speakeasy-api/easytemplate v0.7.4 // indirect
github.com/speakeasy-api/sdk-gen-config v0.7.2 // indirect
github.com/speakeasy-api/sdk-gen-config v0.8.1 // indirect
github.com/speakeasy-api/speakeasy-go-sdk v1.8.0 // indirect
github.com/speakeasy-api/speakeasy-schemas v1.3.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/speakeasy-api/easytemplate v0.7.4 h1:6iesUjK410/ClRYhBZtV2G1H70C3+S3PbWyYOUcnjkM=
github.com/speakeasy-api/easytemplate v0.7.4/go.mod h1:wpCVerXH0vA5Fu34xgXK2jJC5UEL42WRa6Pk+1K32yw=
github.com/speakeasy-api/openapi-generation/v2 v2.77.1 h1:ZKm2csRBwFTdz704cxmIVzRt+cY9W/ecv3PhNBIgAnY=
github.com/speakeasy-api/openapi-generation/v2 v2.77.1/go.mod h1:fNlSqT35Jy5SP7gkil/kyfyqE0TfKg60Wy+lUN8HnJc=
github.com/speakeasy-api/openapi-generation/v2 v2.79.1 h1:fodcFHmmYcipnNPAK40lR+Yiexi3I5Fd3CyPpHhw2Xk=
github.com/speakeasy-api/openapi-generation/v2 v2.79.1/go.mod h1:fNlSqT35Jy5SP7gkil/kyfyqE0TfKg60Wy+lUN8HnJc=
github.com/speakeasy-api/openapi-generation/v2 v2.81.1 h1:/p7myP8Ap8wcIkpKZjjKVLLHnXGwFKXc/Inw0AwWsOk=
github.com/speakeasy-api/openapi-generation/v2 v2.81.1/go.mod h1:fNlSqT35Jy5SP7gkil/kyfyqE0TfKg60Wy+lUN8HnJc=
github.com/speakeasy-api/sdk-gen-config v0.7.2 h1:IpG64YpmhVBW1tpgDFdXY/HTL3ACzWTHlwmUcLdPZXg=
github.com/speakeasy-api/sdk-gen-config v0.7.2/go.mod h1:osr44mhKoRboNtEDMPaDoyH486pLLJH8yvKvnujqnUU=
github.com/speakeasy-api/openapi-generation/v2 v2.82.0 h1:BX041iN8G6bQxjJaVfqBnXeHwNBTBC48WqV9SrKYcBE=
github.com/speakeasy-api/openapi-generation/v2 v2.82.0/go.mod h1:yQgm6MWdCtJzJCPXJ2o0zOvSpDeuqAfSVkoGGQ0vvxg=
github.com/speakeasy-api/sdk-gen-config v0.8.1 h1:2DQibuWJuWGpCixaDJMiHkQUODKEJOWiklWoBDmqtZA=
github.com/speakeasy-api/sdk-gen-config v0.8.1/go.mod h1:osr44mhKoRboNtEDMPaDoyH486pLLJH8yvKvnujqnUU=
github.com/speakeasy-api/speakeasy-client-sdk-go v1.14.0 h1:RqYjM0okHjjEyKRxumaTmZDWt68nGZo1sbIfALyqLCg=
github.com/speakeasy-api/speakeasy-client-sdk-go v1.14.0/go.mod h1:xsmMkmsZjL9uh97GY6VbihZ6jScY90xoq2Dc7ukwB98=
github.com/speakeasy-api/speakeasy-core v0.0.0-20230614153131-6b4b81e1c6a4 h1:Bng5QJOkoz4ECa7gKEiaTM5WOwN6MfkPuw3h84ZXuZ4=
Expand Down
Loading