Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Volkov committed Mar 21, 2024
1 parent cf000a8 commit db886bd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ Currently we are supporting GitLab and Community Registry as a terraform modules

## Installation

### MacOS via homebrew

```bash
brew tap netvolart/tap
brew install joven
```
### Linux and MacOS from binary

To install Joven, you can download the latest release from the [Releases](https://github.com/yourusername/joven/releases) page. Choose the binary that matches your operating system and architecture, download it, and place it in your system's PATH.

For example:

```sh
wget https://github.com/netvolart/joven/releases/download/v0.0.1/joven_0.0.1_linux_amd64.tar.gz
tar -xvzf joven_0.0.1_linux_amd64.tar.gz
chmod +x joven
sudo mv joven /usr/local/bin/
```

## Configuration

Joven uses a configuration file to store settings.
Expand Down
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "joven",

Use: "joven",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
4 changes: 1 addition & 3 deletions terraform/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net/http"
"net/url"
"strings"

"github.com/netvolart/joven/config"
)

func getModuleVersionsFromRegistry(url string, localModule LocalModule) (module TerraformModule, Error error) {
Expand Down Expand Up @@ -41,7 +39,7 @@ func getModuleVersionsFromRegistry(url string, localModule LocalModule) (module

}

func CreateModuleGitlabUrl(c *config.Config, moduleName string) (string, error) {
func createModuleCommunityUrl(moduleName string) (string, error) {
if moduleName == "" {
return "", ErrorPageNumberEmpty
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/community_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func createRegistryMockServer(t *testing.T) *httptest.Server {
func TestCreateModuleCommunityUrl(t *testing.T) {
t.Run("Test First page", func(t *testing.T) {
config := generateMockConfig(t)
url, err := CreateModuleGitlabUrl(config, "registry.terraform.io/terraform-aws-modules/vpc/aws")
url, err := createModuleGitlabUrl(config, "registry.terraform.io/terraform-aws-modules/vpc/aws")
if err != nil {
t.Errorf("Unable to generate URL %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions terraform/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func findOutdated(modules []*TerraformModule) ([]*TerraformModule, error) {

func CompareGitLabModules(c *config.Config, localModulesData []byte) ([]*TerraformModule, error) {
// parse local modules
localModulesResult, err := GetLocalModules(localModulesData)
localModulesResult, err := getLocalModules(localModulesData)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -65,15 +65,14 @@ func CompareGitLabModules(c *config.Config, localModulesData []byte) ([]*Terrafo

} else if localModule.Type == "community" {

url, err := CreateModuleGitlabUrl(c, localModule.Source)
url, err := createModuleCommunityUrl(localModule.Source)
if err != nil {
return nil, err
}
communityModule, err := getModuleVersionsFromRegistry(url, localModule)
if err != nil {
return nil, err
}
// log.Println(communityModule)
resultModules = append(resultModules, &communityModule)
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/gitlab_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func downloadModulesMetadata(c *config.Config) ([]Response, error) {
return fullResponses, nil
}

func GetModulesFromGitlab(c *config.Config) ([]*TerraformModule, error) {
func getModulesFromGitlab(c *config.Config) ([]*TerraformModule, error) {

Check failure on line 101 in terraform/gitlab_batch.go

View workflow job for this annotation

GitHub Actions / lint

func `getModulesFromGitlab` is unused (unused)
responses, err := downloadModulesMetadata(c)
if err != nil {
log.Printf("Error getting modules from GitLab: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion terraform/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type LocalModules struct {
Modules []LocalModule `json:"Modules"`
}

func GetLocalModules(data []byte) (*LocalModules, error) {
func getLocalModules(data []byte) (*LocalModules, error) {
var localModules LocalModules
err := json.Unmarshal(data, &localModules)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion terraform/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestGetLocalModules(t *testing.T) {
]
}`

localModules, err := GetLocalModules([]byte(data))
localModules, err := getLocalModules([]byte(data))
if err != nil {
t.Errorf(err.Error())
}
Expand Down

0 comments on commit db886bd

Please sign in to comment.