Skip to content

Commit

Permalink
Cloney Version 0.2.0 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSudbrackIbarra authored Oct 5, 2023
1 parent a2a5b52 commit 33628e3
Show file tree
Hide file tree
Showing 28 changed files with 248 additions and 547 deletions.
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Feature Description

A clear and concise description of the feature you would like to request.

## Use Case

Describe the use case or problem this feature would solve.

## Proposed Solution

If you have any ideas or suggestions on how this feature could be implemented, please describe them here.

## Additional Information

Add any additional information or context about the feature request.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Bug Description

A clear and concise description of the bug.

## Steps to Reproduce

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See the error.

## Expected Behavior

A clear and concise description of what you expected to happen.

## Actual Behavior

A clear and concise description of what actually happened.

## Screenshots or Additional Information

If applicable, add screenshots or additional information to help explain the problem.

## Environment

- **Operating System**: [e.g., Windows, macOS, Linux]
- **Cloney Version**: [e.g., 22]

## Additional Context

Add any other context about the problem here.
4 changes: 0 additions & 4 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ on:
branches:
- main

# Environment variables required when running the tests.
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

jobs:
test:
runs-on: ubuntu-22.04
Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Change Log

All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Cloney 0.2.0 (Latest) - 2023-10-05

### Added

- Added the `docs` command.

### Changed

- Changed the `dry-run` and `validate` commands to accept a path to a local template repository as the first argument. Before this change, you had to use the `-p, --path` flag to have the same effect.

```bash
# Before
$ cloney dry-run -p /path/to/template-repo

# After
$ cloney dry-run /path/to/template-repo
```

### Fixed

- Fixed a security issue that allowed users to create files and directories outside the scope of the template repository.
- Addressed an issue where the `CLONEY_GIT_TOKEN` environment variable was not being utilized when interacting with private Git repositories.

## Cloney 0.1.0 - 2023-10-01

This is the first release of Cloney.

### Added

- CLI commands: `clone`, `dry-run`, `info`, `start`, `validate`, `version`.

### Changed

- No changes.

### Fixed

- No fixes.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Arthur Sudbrack Ibarra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<br>
<p align="center">
<img src="images/cloney-logo.png">
<img src="images/cloney-logo-rounded.png">
</p>
<br>

Expand Down
7 changes: 2 additions & 5 deletions cli/commands/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func cloneCmdRun(cmd *cobra.Command, args []string) error {
}

// If a token is provided, authenticate with it.
if token == "" {
token = appConfig.GitToken
}
steps.AuthenticateToRepository(repository, token)

// Calculate the clone path.
Expand Down Expand Up @@ -125,7 +122,7 @@ func CreateCloneCommand() *cobra.Command {
Long: fmt.Sprintf(`Clone a template repository.
The 'cloney clone' command will search for a file named '%s' in your current directory by default.
You can specify a different file using the '--variables' flag or pass the variables inline as YAML.`, appConfig.DefaultUserVariablesFileName),
You can specify a different file or pass the variables inline as YAML using the '--variables' flag.`, appConfig.DefaultUserVariablesFileName),
Example: strings.Join([]string{
" clone https://github.com/username/repository.git",
" clone https://github.com/username/repository.git -v variables.yaml",
Expand All @@ -141,7 +138,7 @@ You can specify a different file using the '--variables' flag or pass the variab
cloneCmd.Flags().StringP("branch", "b", "main", "Git branch")
cloneCmd.Flags().StringP("tag", "t", "", "Git tag")
cloneCmd.Flags().StringP("variables", "v", appConfig.DefaultUserVariablesFileName, "Path to a template variables file or raw YAML")
cloneCmd.Flags().StringP("token", "k", "", "Git token, if referencing a private Git repository")
cloneCmd.Flags().StringP("token", "k", "", "Git token, if referencing a private Git repository (not recommended)")

return cloneCmd
}
46 changes: 46 additions & 0 deletions cli/commands/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package commands

import (
"fmt"
"os/exec"
"runtime"

"github.com/ArthurSudbrackIbarra/cloney/terminal"
"github.com/spf13/cobra"
)

// docsCmd is the function that runs when the 'docs' command is called.
func docsCmdRun(cmd *cobra.Command, args []string) error {
// Variable to store errors.
var err error

// Open the Cloney documentation in the default browser.
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", appConfig.CloneyDocumentationURL).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", appConfig.CloneyDocumentationURL).Start()
case "darwin":
err = exec.Command("open", appConfig.CloneyDocumentationURL).Start()
default:
terminal.ErrorMessage("Compatibility error", fmt.Errorf("unsupported operating system"))
}
if err != nil {
terminal.ErrorMessage("Error opening Cloney documentation in default browser", err)
}

return nil
}

// CreateDocsCommand creates the 'docs' command.
func CreateDocsCommand() *cobra.Command {
docsCmd := &cobra.Command{
Use: "docs",
Short: "Open the Cloney documentation in your browser",
Long: "Open the Cloney documentation in your browser.",
PersistentPreRun: persistentPreRun,
RunE: docsCmdRun,
}

return docsCmd
}
3 changes: 3 additions & 0 deletions cli/commands/docs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package commands

// TODO: Add 'docs' command tests.
17 changes: 13 additions & 4 deletions cli/commands/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
// dryRunCmdRun is the function that runs when the 'dry-run' command is called.
func dryRunCmdRun(cmd *cobra.Command, args []string) error {
// Get command-line arguments.
path, _ := cmd.Flags().GetString("path")
var repositorySource string
if len(args) >= 1 {
repositorySource = args[0]
}
output, _ := cmd.Flags().GetString("output")
outputInTerminal, _ := cmd.Flags().GetBool("output-in-terminal")
variables, _ := cmd.Flags().GetString("variables")
Expand All @@ -35,7 +38,7 @@ func dryRunCmdRun(cmd *cobra.Command, args []string) error {
}

// Calculate the directory paths.
sourcePath, _ := steps.CalculatePath(path, "")
sourcePath, _ := steps.CalculatePath(repositorySource, "")
outputPath, _ := steps.CalculatePath(output, "")

// Read the repository metadata file.
Expand Down Expand Up @@ -95,6 +98,13 @@ func dryRunCmdRun(cmd *cobra.Command, args []string) error {
return nil
}

// ResetDryRunFlags resets the flags of the 'dry-run' command.
func ResetDryRunFlags(dryRunCmd *cobra.Command) {
dryRunCmd.Flags().Set("output", appConfig.DefaultDryRunDirectoryName)
dryRunCmd.Flags().Set("output-in-terminal", "false")
dryRunCmd.Flags().Set("variables", appConfig.DefaultUserVariablesFileName)
}

// CreateDryRunCommand creates the 'dry-run' command and its respective flags.
func CreateDryRunCommand() *cobra.Command {
// dryrunCmd represents the dryrun command.
Expand All @@ -109,7 +119,7 @@ The 'cloney dry-run' command is for debugging purposes.
With this command, you can check the output your template repository will generate with the given variables.
By default, 'cloney dry-run' searches for a file named '%s' in your current directory.
You can specify a different file using the '--variables' flag or pass the variables inline as YAML.`, appConfig.DefaultUserVariablesFileName),
You can specify a different file or pass the variables inline as YAML using the '--variables' flag.`, appConfig.DefaultUserVariablesFileName),
Example: strings.Join([]string{
" dry-run",
" dry-run ./path/to/my/template",
Expand All @@ -122,7 +132,6 @@ You can specify a different file using the '--variables' flag or pass the variab
}

// Define command-line flags for the 'dryrun' command.
dryRunCmd.Flags().StringP("path", "p", "", "Path to your local template repository")
dryRunCmd.Flags().StringP("output", "o", appConfig.DefaultDryRunDirectoryName, "Path to output the filled template files")
dryRunCmd.Flags().BoolP("output-in-terminal", "i", false, "Output the filled template file contents in the terminal instead of creating the files")
dryRunCmd.Flags().StringP("variables", "v", appConfig.DefaultUserVariablesFileName, "Path to a template variables file or raw YAML")
Expand Down
5 changes: 1 addition & 4 deletions cli/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ func infoCmdRun(cmd *cobra.Command, args []string) error {
}

// If a token is provided, authenticate with it.
if token == "" {
token = appConfig.GitToken
}
steps.AuthenticateToRepository(repository, token)

// Get the metadata file content.
Expand Down Expand Up @@ -115,7 +112,7 @@ By default, it will get information from the current directory, assuming it is a
// Define command-line flags for the 'info' command.
infoCmd.Flags().StringP("branch", "b", "main", "Git branch, if referencing a git repository")
infoCmd.Flags().StringP("tag", "t", "", "Git tag, if referencing a git repository")
infoCmd.Flags().StringP("token", "k", "", "Git token, if referencing a private git repository")
infoCmd.Flags().StringP("token", "k", "", "Git token, if referencing a private git repository (not recommended)")

return infoCmd
}
5 changes: 4 additions & 1 deletion cli/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ func CreateStartCommand() *cobra.Command {
Long: `Start a new Cloney template repository.
The 'cloney start' command will create a directory with the necessary files to start a new cloney template repository.`,
Example: " cloney start",
Example: strings.Join([]string{
" cloney start",
" cloney start -y",
}, "\n"),
PersistentPreRun: persistentPreRun,
RunE: startCmdRun,
}
Expand Down
6 changes: 5 additions & 1 deletion cli/commands/steps/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func CreateAndValidateRepository(repositoryURL, branch, tag string) (*git.GitRep

// AuthenticateToRepository authenticates to the repository if a token is provided.
func AuthenticateToRepository(repository *git.GitRepository, gitToken string) {
// If a token is provided, authenticate with it.
// If the token is empty, try to get it from the environment variable.
if gitToken == "" {
gitToken = os.Getenv("CLONEY_GIT_TOKEN")
}
// Only if the token is not empty, authenticate to the repository.
if gitToken != "" {
repository.AuthenticateWithToken(gitToken)
}
Expand Down
20 changes: 10 additions & 10 deletions cli/commands/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"path/filepath"
"strings"

"github.com/ArthurSudbrackIbarra/cloney/cli/commands/steps"

Expand All @@ -11,13 +12,16 @@ import (
// validateCmd is the function that runs when the 'validate' command is called.
func validateCmdRun(cmd *cobra.Command, args []string) error {
// Get command-line arguments.
path, _ := cmd.Flags().GetString("path")
var repositorySource string
if len(args) >= 1 {
repositorySource = args[0]
}

// Variable to store errors.
var err error

// Calculate the template directory path.
sourcePath, err := steps.CalculatePath(path, "")
sourcePath, err := steps.CalculatePath(repositorySource, "")
if err != nil {
return err
}
Expand All @@ -41,11 +45,6 @@ func validateCmdRun(cmd *cobra.Command, args []string) error {
return nil
}

// ResetValidateCommandFlags resets the flags of the 'validate' command.
func ResetValidateCommandFlags(cmd *cobra.Command) {
cmd.Flags().Set("path", "")
}

// CreateValidateCommand creates the 'validate' command.
func CreateValidateCommand() *cobra.Command {
validateCmd := &cobra.Command{
Expand All @@ -56,12 +55,13 @@ func CreateValidateCommand() *cobra.Command {
The 'cloney validate' command validates if your Cloney template repository is valid.
It checks if the repository has a metadata file, and if it has the required fields in it.
`,
Example: strings.Join([]string{
" validate",
" validate ./path/to/my/template",
}, "\n"),
PersistentPreRun: persistentPreRun,
RunE: validateCmdRun,
}

// Define command-line flags for the 'validate' command.
validateCmd.Flags().StringP("path", "p", "", "Path to your local template repository")

return validateCmd
}
3 changes: 3 additions & 0 deletions cli/commands/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package commands

// TODO: Add 'validate' command tests.
1 change: 1 addition & 0 deletions cli/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func CreateVersionCommand() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Get the current version of Cloney",
Long: "Get the current version of Cloney.",
PersistentPreRun: persistentPreRun,
Run: versionCmdRun,
}
Expand Down
Loading

0 comments on commit 33628e3

Please sign in to comment.