From 59de9ba6608216c1a9182a683d43127f4dcac145 Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Wed, 24 Jan 2024 17:01:12 +0000 Subject: [PATCH 1/2] refactor(*): eliminated various warnings prompted by golangci-lint Signed-off-by: k4yt3x --- cmd/autobump/azuredevops.go | 44 +++++++++++++++++++++++++++---------- cmd/autobump/changelog.go | 13 +++++------ cmd/autobump/config.go | 25 +++++++++++++-------- cmd/autobump/git.go | 24 ++++++++++---------- cmd/autobump/gitlab.go | 11 ++++++---- cmd/autobump/main.go | 21 +++++++++--------- cmd/autobump/project.go | 17 ++++++++------ cmd/autobump/utils.go | 22 ++++++++++++------- cmd/autobump/versioning.go | 5 ++--- 9 files changed, 109 insertions(+), 73 deletions(-) diff --git a/cmd/autobump/azuredevops.go b/cmd/autobump/azuredevops.go index 8481e6c..f52d5e1 100644 --- a/cmd/autobump/azuredevops.go +++ b/cmd/autobump/azuredevops.go @@ -5,12 +5,12 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/go-git/go-git/v5" - log "github.com/sirupsen/logrus" "io" - "io/ioutil" "net/http" "strings" + + "github.com/go-git/go-git/v5" + log "github.com/sirupsen/logrus" ) // AzureDevOpsInfo struct to hold organization, project, and repo info @@ -48,8 +48,12 @@ func createAzureDevOpsPullRequest( } // TODO: refactor to use this library: https://github.com/microsoft/azure-devops-go-api - url := fmt.Sprintf("https://dev.azure.com/%s/%s/_apis/git/repositories/%s/pullrequests?api-version=6.0", - azureInfo.OrganizationName, azureInfo.ProjectName, azureInfo.RepositoryID) + url := fmt.Sprintf( + "https://dev.azure.com/%s/%s/_apis/git/repositories/%s/pullrequests?api-version=6.0", + azureInfo.OrganizationName, + azureInfo.ProjectName, + azureInfo.RepositoryID, + ) prTitle := fmt.Sprintf("chore(bump): bumped version to %s", newVersion) payload := map[string]interface{}{ "sourceRefName": fmt.Sprintf("refs/heads/%s", sourceBranch), @@ -69,7 +73,10 @@ func createAzureDevOpsPullRequest( } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(":"+personalAccessToken))) + req.Header.Set( + "Authorization", + "Basic "+base64.StdEncoding.EncodeToString([]byte(":"+personalAccessToken)), + ) log.Infof("POST %s", url) resp, err := client.Do(req) @@ -80,7 +87,11 @@ func createAzureDevOpsPullRequest( body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusCreated { - return fmt.Errorf("failed to create pull request (status: %d), response body is: %s", resp.StatusCode, body) + return fmt.Errorf( + "failed to create pull request (status: %d), response body is: %s", + resp.StatusCode, + body, + ) } log.Info("Successfully created Azure DevOps pull request") @@ -88,7 +99,10 @@ func createAzureDevOpsPullRequest( } // GetAzureDevOpsInfo extracts organization, project, and repo information from the remote URL -func GetAzureDevOpsInfo(repo *git.Repository, personalAccessToken string) (info AzureDevOpsInfo, err error) { +func GetAzureDevOpsInfo( + repo *git.Repository, + personalAccessToken string, +) (info AzureDevOpsInfo, err error) { remoteURL, err := getRemoteRepoURL(repo) if err != nil { return info, err @@ -109,14 +123,22 @@ func GetAzureDevOpsInfo(repo *git.Repository, personalAccessToken string) (info } // fetch repositoryId using Azure DevOps API - url := fmt.Sprintf("https://dev.azure.com/%s/%s/_apis/git/repositories/%s?api-version=6.0", organizationName, projectName, repositoryName) + url := fmt.Sprintf( + "https://dev.azure.com/%s/%s/_apis/git/repositories/%s?api-version=6.0", + organizationName, + projectName, + repositoryName, + ) client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { return info, err } - req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(":"+personalAccessToken))) + req.Header.Set( + "Authorization", + "Basic "+base64.StdEncoding.EncodeToString([]byte(":"+personalAccessToken)), + ) log.Infof("GET %s", url) resp, err := client.Do(req) @@ -125,7 +147,7 @@ func GetAzureDevOpsInfo(repo *git.Repository, personalAccessToken string) (info } defer resp.Body.Close() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { return info, err } diff --git a/cmd/autobump/changelog.go b/cmd/autobump/changelog.go index e3c1e38..184faf5 100644 --- a/cmd/autobump/changelog.go +++ b/cmd/autobump/changelog.go @@ -12,7 +12,8 @@ import ( log "github.com/sirupsen/logrus" ) -const defaultChangelogUrl = "https://raw.githubusercontent.com/rios0rios0/autobump/main/configs/CHANGELOG.template.md" +const defaultChangelogUrl = "https://raw.githubusercontent.com/rios0rios0/" + + "autobump/main/configs/CHANGELOG.template.md" func updateChangelogFile(changelogPath string) (*semver.Version, error) { lines, err := readLines(changelogPath) @@ -51,12 +52,12 @@ func getNextVersion(changelogPath string) (*semver.Version, error) { func createChangelogIfNotExists(changelogPath string) (bool, error) { if _, err := os.Stat(changelogPath); os.IsNotExist(err) { log.Warnf("Creating empty CHANGELOG file at '%s'.", changelogPath) - var fileContent, err = downloadFile(defaultChangelogUrl) + fileContent, err := downloadFile(defaultChangelogUrl) if err != nil { log.Errorf("It wasn't possible to download the CHANGELOG model file: %v", err) } - err = os.WriteFile(changelogPath, fileContent, 0644) + err = os.WriteFile(changelogPath, fileContent, 0o644) if err != nil { log.Errorf("Error creating CHANGELOG file: %v", err) return false, err @@ -88,7 +89,8 @@ func isChangelogUnreleasedEmpty(changelogPath string) (bool, error) { } if unreleased { - if match, _ := regexp.MatchString(`^\s*-\s*[^ ]+`, line); match { + re := regexp.MustCompile(`^\s*-\s*[^ ]+`) + if match := re.MatchString(line); match { return false, nil } } @@ -230,17 +232,14 @@ func updateSection( for i := 0; i < majorChanges; i++ { nextVersion = nextVersion.IncMajor() } - break case minorChanges > 0: for i := 0; i < minorChanges; i++ { nextVersion = nextVersion.IncMinor() } - break case patchChanges > 0: for i := 0; i < patchChanges; i++ { nextVersion = nextVersion.IncPatch() } - break } // Sort the items inside the sections alphabetically diff --git a/cmd/autobump/config.go b/cmd/autobump/config.go index 14a3b09..cd9ecf1 100644 --- a/cmd/autobump/config.go +++ b/cmd/autobump/config.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "net/url" "os" @@ -40,9 +39,10 @@ type ProjectConfig struct { NewVersion string } -const defaultConfigUrl = "https://raw.githubusercontent.com/rios0rios0/autobump/main/configs/autobump.yaml" +const defaultConfigUrl = "https://raw.githubusercontent.com/rios0rios0/autobump/" + + "main/configs/autobump.yaml" -var missingLanguagesKeyError = errors.New("missing languages key") +var missingLanguagesKeyError = fmt.Errorf("missing languages key") // readConfig reads the config file and returns a GlobalConfig struct func readConfig(configPath string) (*GlobalConfig, error) { @@ -93,7 +93,10 @@ func readConfig(configPath string) (*GlobalConfig, error) { if globalConfig.AzureDevOpsAccessToken != "" { _, err = os.Stat(globalConfig.AzureDevOpsAccessToken) if !os.IsNotExist(err) { - log.Infof("Reading Azure DevOps access token from file %s", globalConfig.AzureDevOpsAccessToken) + log.Infof( + "Reading Azure DevOps access token from file %s", + globalConfig.AzureDevOpsAccessToken, + ) token, err := os.ReadFile(globalConfig.AzureDevOpsAccessToken) if err != nil { return nil, err @@ -125,7 +128,7 @@ func decodeConfig(data []byte) (*GlobalConfig, error) { func validateGlobalConfig(globalConfig *GlobalConfig, batch bool) error { var missingKeys []string - if batch == true && len(globalConfig.Projects) == 0 { + if batch && len(globalConfig.Projects) == 0 { missingKeys = append(missingKeys, "projects") } @@ -133,17 +136,18 @@ func validateGlobalConfig(globalConfig *GlobalConfig, batch bool) error { if projectConfig.Path == "" { missingKeys = append(missingKeys, fmt.Sprintf("projects[%d].path", i)) } - if batch == true && globalConfig.GitLabAccessToken == "" && + if batch && globalConfig.GitLabAccessToken == "" && projectConfig.ProjectAccessToken == "" { log.Error( - "Project access token is required when personal access token is not set in batch mode", + "Project access token is required when personal access token " + + "is not set in batch mode", ) missingKeys = append(missingKeys, fmt.Sprintf("projects[%d].project_access_token", i)) } } if len(missingKeys) > 0 { - return errors.New("missing keys: " + strings.Join(missingKeys, ", ")) + return fmt.Errorf("missing keys: " + strings.Join(missingKeys, ", ")) } if globalConfig.LanguagesConfig == nil { @@ -161,7 +165,10 @@ func findConfigOnMissing(configPath string) string { var err error configPath, err = findConfig() if err != nil { - log.Warn("Config file not found in default locations, using the repository configuration as the last resort") + log.Warn( + "Config file not found in default locations, " + + "using the repository configuration as the last resort", + ) configPath = defaultConfigUrl } diff --git a/cmd/autobump/git.go b/cmd/autobump/git.go index a27ec4c..214c0c5 100644 --- a/cmd/autobump/git.go +++ b/cmd/autobump/git.go @@ -1,17 +1,17 @@ package main import ( - "errors" "fmt" - "github.com/Masterminds/semver/v3" - "github.com/go-git/go-git/v5/plumbing/object" - "github.com/go-git/go-git/v5/plumbing/protocol/packp/capability" - "github.com/go-git/go-git/v5/plumbing/transport" "os" "path/filepath" "strings" "time" + "github.com/Masterminds/semver/v3" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/go-git/go-git/v5/plumbing/protocol/packp/capability" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/ProtonMail/go-crypto/openpgp" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" @@ -199,7 +199,6 @@ func getAuthMethods( Password: globalConfig.GitLabCIJobToken, }) } - break case "AzureDevOps": log.Infof("Using Azure DevOps access token to authenticate") transport.UnsupportedCapabilities = []capability.Capability{ @@ -209,15 +208,14 @@ func getAuthMethods( Username: username, Password: globalConfig.AzureDevOpsAccessToken, }) - break default: log.Errorf("No authentication mechanism implemented for service type '%s'", service) - return nil, errors.New("no authentication mechanism implemented") + return nil, fmt.Errorf("no authentication mechanism implemented") } if len(authMethods) == 0 { log.Error("No authentication credentials found for any authentication method") - return nil, errors.New("no authentication credentials found for any authentication method") + return nil, fmt.Errorf("no authentication credentials found for any authentication method") } return authMethods, nil @@ -308,14 +306,14 @@ func getLatestTag() (*LatestTag, error) { } var latestTag *plumbing.Reference - err = tags.ForEach(func(tag *plumbing.Reference) error { + _ = tags.ForEach(func(tag *plumbing.Reference) error { latestTag = tag return nil }) // get the date time of the tag commit, err := repo.CommitObject(latestTag.Hash()) - var latestTagDate = commit.Committer.When + latestTagDate := commit.Committer.When if err != nil { log.Fatal(err) } @@ -325,7 +323,7 @@ func getLatestTag() (*LatestTag, error) { // if the project is already started with no tags in the history if commits >= 5 { log.Warnf("No tags found in Git history, falling back to '%s'", defaultGitTag) - var version, _ = semver.NewVersion(defaultGitTag) + version, _ := semver.NewVersion(defaultGitTag) return &LatestTag{ Tag: version, Date: time.Now(), @@ -337,7 +335,7 @@ func getLatestTag() (*LatestTag, error) { } } - var version, _ = semver.NewVersion(latestTag.Name().Short()) + version, _ := semver.NewVersion(latestTag.Name().Short()) return &LatestTag{ Tag: version, Date: latestTagDate, diff --git a/cmd/autobump/gitlab.go b/cmd/autobump/gitlab.go index 11711b7..5476b29 100644 --- a/cmd/autobump/gitlab.go +++ b/cmd/autobump/gitlab.go @@ -9,7 +9,10 @@ import ( "github.com/xanzy/go-gitlab" ) -// TODO: this should be better using an Adapter pattern (interface with many providers and implementing the methods) +// TODO: this should be better using an Adapter pattern +// +// (interface with many providers and implementing the methods) +// // createGitLabMergeRequest creates a new merge request on GitLab func createGitLabMergeRequest( globalConfig *GlobalConfig, @@ -48,10 +51,10 @@ func createGitLabMergeRequest( mrTitle := fmt.Sprintf("chore(bump): bumped version to %s", newVersion) mergeRequestOptions := &gitlab.CreateMergeRequestOptions{ - SourceBranch: gitlab.String(sourceBranch), - TargetBranch: gitlab.String("main"), + SourceBranch: gitlab.Ptr(sourceBranch), + TargetBranch: gitlab.Ptr("main"), Title: &mrTitle, - RemoveSourceBranch: gitlab.Bool(true), + RemoveSourceBranch: gitlab.Ptr(true), } _, _, err = gitlabClient.MergeRequests.CreateMergeRequest(projectID, mergeRequestOptions) diff --git a/cmd/autobump/main.go b/cmd/autobump/main.go index dafb5f5..648cb88 100644 --- a/cmd/autobump/main.go +++ b/cmd/autobump/main.go @@ -21,7 +21,6 @@ var ( cwd, err := os.Getwd() if err != nil { log.Fatalf("Failed to get the current working directory: %v", err) - os.Exit(1) } projectConfig := &ProjectConfig{ @@ -34,7 +33,6 @@ var ( projectLanguage, err := detectLanguage(globalConfig, projectConfig.Path) if err != nil { log.Fatalf("Failed to detect project language: %v", err) - os.Exit(1) } projectConfig.Language = projectLanguage } @@ -42,10 +40,8 @@ var ( err = processRepo(globalConfig, projectConfig) if err != nil { log.Fatalf("Failed to process repo: %v", err) - - // TODO: rollback the process removing the branch if exists, reverting the files and going back to main - - os.Exit(1) + // TODO: rollback the process removing the branch if exists, + // reverting the files and going back to main } }, } @@ -58,7 +54,6 @@ var ( err := iterateProjects(globalConfig) if err != nil { log.Fatalf("Failed to iterate projects: %v", err) - os.Exit(1) } }, } @@ -73,7 +68,6 @@ func findReadAndValidateConfig(configPath string) *GlobalConfig { globalConfig, err := readConfig(configPath) if err != nil { log.Fatalf("Failed to read config: %v", err) - os.Exit(1) } if err = validateGlobalConfig(globalConfig, false); err != nil { @@ -84,16 +78,18 @@ func findReadAndValidateConfig(configPath string) *GlobalConfig { data, err = downloadFile(defaultConfigUrl) if err != nil { log.Fatalf("Failed to download default config: %v", err) - os.Exit(1) } var defaultConfig *GlobalConfig defaultConfig, err = decodeConfig(data) + if err != nil { + log.Fatalf("Failed to decode default config: %v", err) + } + // TODO: this merge could be done, for each language globalConfig.LanguagesConfig = defaultConfig.LanguagesConfig } else { log.Fatalf("Config validation failed: %v", err) - os.Exit(1) } } @@ -106,5 +102,8 @@ func main() { batchCmd.Flags().StringVarP(&configPath, "config", "c", "", "config file path") rootCmd.AddCommand(batchCmd) - rootCmd.Execute() + err := rootCmd.Execute() + if err != nil { + log.Fatalf("Uncaught error: %v", err) + } } diff --git a/cmd/autobump/project.go b/cmd/autobump/project.go index 595eb22..7951dcb 100644 --- a/cmd/autobump/project.go +++ b/cmd/autobump/project.go @@ -1,15 +1,15 @@ package main import ( - "errors" "fmt" + "os" + "path/filepath" + "strings" + "github.com/ProtonMail/go-crypto/openpgp" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" log "github.com/sirupsen/logrus" - "os" - "path/filepath" - "strings" ) // detectLanguage detects the language of a project by looking at the files in the project @@ -72,7 +72,7 @@ func detectLanguage(globalConfig *GlobalConfig, cwd string) (string, error) { return detected, nil } - return "", errors.New("project language not recognized") + return "", fmt.Errorf("project language not recognized") } // getGlobalGitConfig gets a Git option from local and global Git config @@ -237,6 +237,10 @@ func processRepo(globalConfig *GlobalConfig, projectConfig *ProjectConfig) error // get version file relative path for _, versionFile := range versionFiles { versionFileRelativePath, err := filepath.Rel(projectPath, versionFile.Path) + if err != nil { + return err + } + if _, err := os.Stat(versionFile.Path); os.IsNotExist(err) { continue } @@ -362,7 +366,6 @@ func iterateProjects(globalConfig *GlobalConfig) error { // verify if the project path exists if _, err = os.Stat(project.Path); os.IsNotExist(err) { - // if the project path does not exist, check if it is a remote repository if !strings.HasPrefix(project.Path, "https://") && !strings.HasPrefix(project.Path, "git@") { @@ -370,7 +373,7 @@ func iterateProjects(globalConfig *GlobalConfig) error { // if it is neither a local path nor a remote repository, skip the project log.Errorf("Project path does not exist: %s\n", project.Path) log.Warn("Skipping project") - err = errors.New("project path does not exist") + err = fmt.Errorf("project path does not exist") continue } } diff --git a/cmd/autobump/utils.go b/cmd/autobump/utils.go index b8e1ddd..0259abe 100644 --- a/cmd/autobump/utils.go +++ b/cmd/autobump/utils.go @@ -2,9 +2,8 @@ package main import ( "bufio" - "errors" "fmt" - "io/ioutil" + "io" "net/http" "os" "os/exec" @@ -12,7 +11,7 @@ import ( "github.com/ProtonMail/go-crypto/openpgp" log "github.com/sirupsen/logrus" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) // readLines reads a whole file into memory @@ -53,7 +52,7 @@ func findFile(locations []string, filename string) (string, error) { return location, nil } } - return "", errors.New(filename + " not found") + return "", fmt.Errorf(filename + " not found") } // downloadFile downloads a file from the given URL @@ -66,7 +65,7 @@ func downloadFile(url string) ([]byte, error) { } defer resp.Body.Close() - data, err = ioutil.ReadAll(resp.Body) + data, err = io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -86,7 +85,14 @@ func getGpgKey(gpgKeyId, gpgKeyPath string) (*openpgp.Entity, error) { if _, err = os.Stat(location); os.IsNotExist(err) { // TODO: until today Go is not capable to read the key from the keyring (kbx) - cmd := exec.Command("gpg", "--export-secret-key", "--output", location, "--armor", gpgKeyId) + cmd := exec.Command( + "gpg", + "--export-secret-key", + "--output", + location, + "--armor", + gpgKeyId, + ) err = cmd.Run() if err != nil { return nil, fmt.Errorf("failed to execute command GPG: %w", err) @@ -96,7 +102,7 @@ func getGpgKey(gpgKeyId, gpgKeyPath string) (*openpgp.Entity, error) { privateKeyFile, err := os.Open(location) if err != nil { - return nil, errors.New("failed to open private key file") + return nil, fmt.Errorf("failed to open private key file") } defer privateKeyFile.Close() @@ -112,7 +118,7 @@ func getGpgKey(gpgKeyId, gpgKeyPath string) (*openpgp.Entity, error) { fmt.Print("Enter the passphrase for your GPG key: ") var passphrase []byte - passphrase, err = terminal.ReadPassword(0) + passphrase, err = term.ReadPassword(0) // assume the passphrase to be empty if unable to read from the terminal if err != nil { if strings.TrimSpace(err.Error()) == "inappropriate ioctl for device" { diff --git a/cmd/autobump/versioning.go b/cmd/autobump/versioning.go index 714acbc..f05f85e 100644 --- a/cmd/autobump/versioning.go +++ b/cmd/autobump/versioning.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "os" "path/filepath" @@ -52,7 +51,7 @@ func updateVersion(globalConfig *GlobalConfig, projectConfig *ProjectConfig) err } if !oneVersionFileExists { - return errors.New(fmt.Sprintf("No version file found for %s", projectConfig.Language)) + return fmt.Errorf("No version file found for %s", projectConfig.Language) } return nil @@ -72,7 +71,7 @@ func getVersionFiles( languageConfig, exists := globalConfig.LanguagesConfig[projectConfig.Language] if !exists { - return nil, errors.New(fmt.Sprintf("Language %s not found in config", language)) + return nil, fmt.Errorf("Language %s not found in config", language) } for _, versionFile := range languageConfig.VersionFiles { From 37a2ff9063d5b69e2ae0fc96b515af8520c73fd4 Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Wed, 24 Jan 2024 21:04:10 +0000 Subject: [PATCH 2/2] feat(versioning): added the feature to read project names from language config Signed-off-by: k4yt3x --- CHANGELOG.md | 8 ++++++++ cmd/autobump/language.go | 14 +++++++++++++ cmd/autobump/python.go | 41 ++++++++++++++++++++++++++++++++++++++ cmd/autobump/versioning.go | 12 +++++++++++ go.mod | 1 + go.sum | 2 ++ 6 files changed, 78 insertions(+) create mode 100644 cmd/autobump/language.go create mode 100644 cmd/autobump/python.go diff --git a/CHANGELOG.md b/CHANGELOG.md index c852255..8041a87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,14 @@ Exceptions are acceptable depending on the circumstances (critical bug fixes tha ## [Unreleased] +### Added + +- added the feature to read project names from the language's configuration file + +### Changed + +- refactored the project to eliminate warnings from golangci-lint + ## [2.11.0] - 2024-01-23 ### Added diff --git a/cmd/autobump/language.go b/cmd/autobump/language.go new file mode 100644 index 0000000..cf7ab8f --- /dev/null +++ b/cmd/autobump/language.go @@ -0,0 +1,14 @@ +package main + +type Language interface { + GetProjectName() (string, error) +} + +func getLanguageInterface(projectConfig ProjectConfig) Language { + switch projectConfig.Language { + case "python": + return Python{ProjectConfig: projectConfig} + default: + return nil + } +} diff --git a/cmd/autobump/python.go b/cmd/autobump/python.go new file mode 100644 index 0000000..e9a7f2a --- /dev/null +++ b/cmd/autobump/python.go @@ -0,0 +1,41 @@ +package main + +import ( + "os" + "path/filepath" + + "github.com/BurntSushi/toml" +) + +type PyProject struct { + Project Project `toml:"project"` +} + +type Project struct { + Name string `toml:"name"` +} + +type Python struct { + ProjectConfig ProjectConfig +} + +func (p Python) GetProjectName() (string, error) { + return getPyprojectName(p.ProjectConfig) +} + +func getPyprojectName(projectConfig ProjectConfig) (string, error) { + pyprojectTomlPath := filepath.Join(projectConfig.Path, "pyproject.toml") + + _, err := os.Stat(pyprojectTomlPath) + if err != nil { + return "", err + } + + var pyProject PyProject + _, err = toml.DecodeFile(pyprojectTomlPath, &pyProject) + if err != nil { + return "", err + } + + return pyProject.Project.Name, nil +} diff --git a/cmd/autobump/versioning.go b/cmd/autobump/versioning.go index f05f85e..cb26c09 100644 --- a/cmd/autobump/versioning.go +++ b/cmd/autobump/versioning.go @@ -69,6 +69,18 @@ func getVersionFiles( projectName := strings.Replace(projectConfig.Name, "-", "_", -1) var versionFiles []VersionFile + // try to get the project name from the language interface + languageInterface := getLanguageInterface(*projectConfig) + if languageInterface != nil { + languageProjectName, err := languageInterface.GetProjectName() + if err == nil && languageProjectName != "" { + log.Infof("Using project name '%s' from language interface", languageProjectName) + projectName = languageProjectName + } + } else { + log.Infof("Language '%s' does not have a language interface", projectConfig.Language) + } + languageConfig, exists := globalConfig.LanguagesConfig[projectConfig.Language] if !exists { return nil, fmt.Errorf("Language %s not found in config", language) diff --git a/go.mod b/go.mod index 61ead26..939c88d 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect + github.com/BurntSushi/toml v1.3.2 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/cloudflare/circl v1.3.7 // indirect diff --git a/go.sum b/go.sum index 0c19ecb..48937c1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=