From 07db4443afbd6e1de17c1a1cee10de6f4070fc8e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 22:22:32 +0000 Subject: [PATCH] feat: Add `collect github` command and resolve merge conflict This commit introduces a new `collect github` command with two subcommands: - `repo`: Clones a GitHub repository. This functionality was previously under the `collect git` command. - `release`: Downloads assets from the latest GitHub release of a repository. The `release` subcommand supports the following features: - Version checking against a provided version string using the `--version` flag. - Downloading a specific file from the release using the `--file` flag. - Downloading all assets from the release and packing them into a DataNode using the `--pack` flag. - Specifying an output directory for the downloaded files using the `--output` flag. This commit also resolves a merge conflict by restructuring the `collect` command and its subcommands. The `collect git` and `collect github-release` commands have been consolidated under the new `collect github` command to provide a more organized and user-friendly command structure. --- cmd/collect_github.go | 16 ++++++++++++++++ ...go => collect_github_release_subcommand.go} | 18 ++++++++++++++++-- cmd/{collect_git.go => collect_github_repo.go} | 10 +++++----- go.mod | 1 + go.sum | 2 ++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 cmd/collect_github.go rename cmd/{collect_github_release.go => collect_github_release_subcommand.go} (85%) rename cmd/{collect_git.go => collect_github_repo.go} (73%) diff --git a/cmd/collect_github.go b/cmd/collect_github.go new file mode 100644 index 0000000..58d6f8d --- /dev/null +++ b/cmd/collect_github.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// collectGithubCmd represents the collect github command +var collectGithubCmd = &cobra.Command{ + Use: "github", + Short: "Collect a resource from GitHub.", + Long: `Collect a resource from a GitHub repository, such as a repository or a release.`, +} + +func init() { + collectCmd.AddCommand(collectGithubCmd) +} diff --git a/cmd/collect_github_release.go b/cmd/collect_github_release_subcommand.go similarity index 85% rename from cmd/collect_github_release.go rename to cmd/collect_github_release_subcommand.go index ecd2711..b844704 100644 --- a/cmd/collect_github_release.go +++ b/cmd/collect_github_release_subcommand.go @@ -13,11 +13,12 @@ import ( borg_github "github.com/Snider/Borg/pkg/github" gh "github.com/google/go-github/v39/github" "github.com/spf13/cobra" + "golang.org/x/mod/semver" ) // collectGithubReleaseCmd represents the collect github-release command var collectGithubReleaseCmd = &cobra.Command{ - Use: "github-release [repository-url]", + Use: "release [repository-url]", Short: "Download the latest release of a file from GitHub releases", Long: `Download the latest release of a file from GitHub releases. If the file or URL has a version number, it will check for a higher version and download it if found.`, Args: cobra.ExactArgs(1), @@ -26,6 +27,7 @@ var collectGithubReleaseCmd = &cobra.Command{ outputDir, _ := cmd.Flags().GetString("output") pack, _ := cmd.Flags().GetBool("pack") file, _ := cmd.Flags().GetString("file") + version, _ := cmd.Flags().GetString("version") owner, repo, err := borg_github.ParseRepoFromURL(repoURL) if err != nil { @@ -41,6 +43,17 @@ var collectGithubReleaseCmd = &cobra.Command{ fmt.Printf("Found latest release: %s\n", release.GetTagName()) + if version != "" { + if !semver.IsValid(version) { + fmt.Printf("Invalid version string: %s\n", version) + return + } + if semver.Compare(release.GetTagName(), version) <= 0 { + fmt.Printf("Latest release (%s) is not newer than the provided version (%s).\n", release.GetTagName(), version) + return + } + } + if pack { dn := datanode.New() for _, asset := range release.Assets { @@ -107,8 +120,9 @@ var collectGithubReleaseCmd = &cobra.Command{ } func init() { - collectCmd.AddCommand(collectGithubReleaseCmd) + collectGithubCmd.AddCommand(collectGithubReleaseCmd) collectGithubReleaseCmd.PersistentFlags().String("output", ".", "Output directory for the downloaded file") collectGithubReleaseCmd.PersistentFlags().Bool("pack", false, "Pack all assets into a DataNode") collectGithubReleaseCmd.PersistentFlags().String("file", "", "The file to download from the release") + collectGithubReleaseCmd.PersistentFlags().String("version", "", "The version to check against") } diff --git a/cmd/collect_git.go b/cmd/collect_github_repo.go similarity index 73% rename from cmd/collect_git.go rename to cmd/collect_github_repo.go index e3678de..b4f873d 100644 --- a/cmd/collect_git.go +++ b/cmd/collect_github_repo.go @@ -9,9 +9,9 @@ import ( "github.com/spf13/cobra" ) -// collectGitCmd represents the collect git command -var collectGitCmd = &cobra.Command{ - Use: "git [repository-url]", +// collectGithubRepoCmd represents the collect github repo command +var collectGithubRepoCmd = &cobra.Command{ + Use: "repo [repository-url]", Short: "Collect a single Git repository", Long: `Collect a single Git repository and store it in a DataNode.`, Args: cobra.ExactArgs(1), @@ -42,6 +42,6 @@ var collectGitCmd = &cobra.Command{ } func init() { - collectCmd.AddCommand(collectGitCmd) - collectGitCmd.PersistentFlags().String("output", "repo.dat", "Output file for the DataNode") + collectGithubCmd.AddCommand(collectGithubRepoCmd) + collectGithubRepoCmd.PersistentFlags().String("output", "repo.dat", "Output file for the DataNode") } diff --git a/go.mod b/go.mod index 6312459..1fdfae3 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( github.com/spf13/pflag v1.0.10 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.43.0 // indirect + golang.org/x/mod v0.29.0 // indirect golang.org/x/sys v0.37.0 // indirect golang.org/x/term v0.36.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect diff --git a/go.sum b/go.sum index bd7234e..e2688d7 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,8 @@ golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA= +golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=