repohub 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8928d830616a9e2d7c88de13230abaa61b53882601c8b865935cb54b7dbd6b47
4
+ data.tar.gz: 63d4250030e9066e754138372e5f6c3438b53ba096271a2215a30cfc08722335
5
+ SHA512:
6
+ metadata.gz: 961deeb141da67490c7a6538e0d1bd67a0482131dc9de14301fce78b7b2fe1181c1af5a0d33092ef8b9d27056b7b326547163b0239a5ca89366c48a0dc6e2135
7
+ data.tar.gz: 67a24b773266ea7a0b71f5731ffc3d647ad2ad366c0a7332429706880808ef6b9dc2085fd87c1ef5d79a5fd541956ef2fd228f68a42f42968e21e4b3871bbb8e
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # RepoMate 🧉
2
+
3
+ A command-line tool to manage and synchronize multiple git repositories. This tool helps you maintain a list of git repositories and keep them up to date with their remote sources.
4
+
5
+ ## Features
6
+
7
+ - Maintain a list of repositories to sync
8
+ - Add and remove repositories from the sync list
9
+ - Automatically clone new repositories
10
+ - Update existing repositories
11
+ - Configurable paths for code and configuration storage
12
+
13
+ ## Installation
14
+
15
+ 1. Ensure you have Ruby installed on your system
16
+ 2. Copy `repomate.rb` to `~/.local/bin/`:
17
+ ```bash
18
+ mkdir -p ~/.local/bin
19
+ cp repomate.rb ~/.local/bin/
20
+ chmod +x ~/.local/bin/repomate.rb
21
+ ```
22
+
23
+ 3. Add the fish function to your fish config:
24
+ ```bash
25
+ mkdir -p ~/.config/fish/functions
26
+ cp repomate.fish ~/.config/fish/functions/
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ The tool can be used either directly through Ruby or via the fish shell function.
32
+
33
+ ### Basic Commands
34
+
35
+ ```bash
36
+ # Sync all repositories
37
+ repomate sync
38
+
39
+ # Add a repository to the sync list
40
+ repomate add https://github.com/user/repo.git
41
+
42
+ # Remove a repository from the sync list
43
+ repomate remove https://github.com/user/repo.git
44
+
45
+ # List all repositories in the sync list
46
+ repomate list
47
+ ```
48
+
49
+ ### Configuration Options
50
+
51
+ You can customize the following paths:
52
+
53
+ ```bash
54
+ # Set custom home directory
55
+ repomate --home-path /custom/home
56
+
57
+ # Set custom code directory
58
+ repomate --code-path /custom/code
59
+
60
+ # Set custom config file location
61
+ repomate --config-file /custom/config.txt
62
+ ```
63
+
64
+ ### Default Paths
65
+
66
+ - Home Path: `$HOME`
67
+ - Code Path: `$HOME/code`
68
+ - Config File: `$HOME/.config/alex-scripts/repomate/subscribed.txt`
69
+
70
+ ## Configuration File
71
+
72
+ The configuration file is a simple text file with one repository URL per line. For example:
73
+
74
+ ```text
75
+ https://github.com/user/repo1.git
76
+ https://github.com/user/repo2.git
77
+ https://github.com/organization/repo3.git
78
+ ```
79
+
80
+ The file will be automatically created at `~/.config/alex-scripts/repomate/subscribed.txt` if it doesn't exist.
81
+
82
+ ## Behavior
83
+
84
+ - When syncing repositories:
85
+ - If a repository doesn't exist locally, it will be cloned
86
+ - If a repository exists locally, it will be updated (git pull)
87
+ - Updates are performed on the 'main' branch
88
+
89
+ - When adding repositories:
90
+ - Duplicate repositories are not allowed
91
+ - The URL is validated before adding
92
+
93
+ - When removing repositories:
94
+ - Only the repository URL is removed from the sync list
95
+ - The local repository files are not deleted
96
+
97
+ ## Requirements
98
+
99
+ - Ruby
100
+ - Git
101
+ - Fish shell (for fish function integration)
102
+
103
+ ## Error Handling
104
+
105
+ The tool includes error handling for common scenarios:
106
+
107
+ - Missing directories are automatically created
108
+ - Invalid repository URLs are reported
109
+ - Network issues during sync are handled gracefully
110
+ - Duplicate repository additions are prevented
111
+
112
+ ## Help
113
+
114
+ To see all available options and commands:
115
+
116
+ ```bash
117
+ repomate --help
118
+ ```
data/bin/repomate ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # bin/repomate
3
+
4
+ require 'repomate/cli'
5
+
6
+ Repomate::CLI.start
@@ -0,0 +1,9 @@
1
+ module Repomate
2
+ class CLI
3
+ def self.start
4
+ config = Config.new
5
+ manager = Manager.new(config)
6
+ manager.run
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,77 @@
1
+ # lib/repomate/config.rb
2
+ require 'fileutils'
3
+ require 'optparse'
4
+
5
+ module Repomate
6
+ class Config
7
+ attr_reader :home_path, :code_path, :config_file_path, :command, :repo_url
8
+
9
+ def initialize
10
+ # Set defaults
11
+ @home_path = ENV['HOME']
12
+ @code_path = "#{@home_path}/code"
13
+ @config_file_path = "#{@home_path}/.config/repomate/repos.txt"
14
+ @command = 'sync'
15
+ @repo_url = nil
16
+
17
+ parse_options
18
+ ensure_directories
19
+ end
20
+
21
+ private
22
+
23
+ def parse_options
24
+ OptionParser.new do |opts|
25
+ opts.banner = "Usage: repomate [options] [command]"
26
+ opts.separator("\nCommands:")
27
+ opts.separator(" sync Sync all repositories (default)")
28
+ opts.separator(" add REPO_URL Add repository to sync list")
29
+ opts.separator(" remove REPO_URL Remove repository from sync list")
30
+ opts.separator(" list Show all repositories in sync list")
31
+ opts.separator("\nOptions:")
32
+
33
+ opts.on('--home-path PATH', 'Set home directory path') do |path|
34
+ @home_path = path
35
+ end
36
+
37
+ opts.on('--code-path PATH', 'Set code directory path') do |path|
38
+ @code_path = path
39
+ end
40
+
41
+ opts.on('--config-file PATH', 'Set config file path') do |path|
42
+ @config_file_path = path
43
+ end
44
+
45
+ opts.on('-h', '--help', 'Display this help message') do
46
+ puts opts
47
+ exit
48
+ end
49
+
50
+ opts.on('-v', '--version', 'Display version') do
51
+ puts "repomate #{Repomate::VERSION}"
52
+ exit
53
+ end
54
+ end.parse!
55
+
56
+ # Parse command and repository URL if provided
57
+ if ARGV.any?
58
+ @command = ARGV[0]
59
+ @repo_url = ARGV[1] if ARGV[1]
60
+ end
61
+ end
62
+
63
+ def ensure_directories
64
+ FileUtils.mkdir_p(@code_path)
65
+ config_dir = File.dirname(@config_file_path)
66
+ FileUtils.mkdir_p(config_dir)
67
+
68
+ unless File.exist?(@config_file_path)
69
+ puts "Creating config file at #{@config_file_path}"
70
+ FileUtils.touch(@config_file_path)
71
+ end
72
+ rescue StandardError => e
73
+ puts "Error creating directories: #{e.message}"
74
+ exit 1
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,113 @@
1
+ # lib/repomate/manager.rb
2
+ module Repomate
3
+ class Manager
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def run
9
+ case @config.command
10
+ when 'sync'
11
+ sync_all_repos
12
+ when 'add'
13
+ add_repo
14
+ when 'remove'
15
+ remove_repo
16
+ when 'list'
17
+ list_repos
18
+ else
19
+ puts "Unknown command: #{@config.command}"
20
+ exit 1
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def update_repo(url)
27
+ repo_name = url.split('/').last.gsub('.git', '')
28
+ repo_path = "#{@config.code_path}/#{repo_name}"
29
+
30
+ if Dir.exist?(repo_path)
31
+ update_existing_repo(repo_path, repo_name)
32
+ else
33
+ clone_new_repo(url, repo_path, repo_name)
34
+ end
35
+ end
36
+
37
+ def sync_all_repos
38
+ if File.zero?(@config.config_file_path)
39
+ puts "No repositories configured. Add some with 'add' command."
40
+ return
41
+ end
42
+
43
+ File.readlines(@config.config_file_path).each do |line|
44
+ url = line.strip
45
+ next if url.empty?
46
+ update_repo(url)
47
+ end
48
+ end
49
+
50
+ def add_repo
51
+ unless @config.repo_url
52
+ puts "Error: Repository URL is required"
53
+ exit 1
54
+ end
55
+
56
+ repos = File.exist?(@config.config_file_path) ? File.readlines(@config.config_file_path).map(&:strip) : []
57
+
58
+ if repos.include?(@config.repo_url)
59
+ puts "Repository already in sync list"
60
+ return
61
+ end
62
+
63
+ File.open(@config.config_file_path, 'a') do |file|
64
+ file.puts @config.repo_url
65
+ end
66
+ puts "Added #{@config.repo_url} to sync list"
67
+ end
68
+
69
+ def remove_repo
70
+ unless @config.repo_url
71
+ puts "Error: Repository URL is required"
72
+ exit 1
73
+ end
74
+
75
+ repos = File.exist?(@config.config_file_path) ? File.readlines(@config.config_file_path).map(&:strip) : []
76
+
77
+ unless repos.include?(@config.repo_url)
78
+ puts "Repository not found in sync list"
79
+ return
80
+ end
81
+
82
+ repos.delete(@config.repo_url)
83
+ File.write(@config.config_file_path, repos.join("\n") + "\n")
84
+ puts "Removed #{@config.repo_url} from sync list"
85
+ end
86
+
87
+ def list_repos
88
+ if File.zero?(@config.config_file_path)
89
+ puts "No repositories configured. Add some with 'add' command."
90
+ return
91
+ end
92
+
93
+ puts "Repositories in sync list:"
94
+ File.readlines(@config.config_file_path).each do |line|
95
+ url = line.strip
96
+ next if url.empty?
97
+ puts "- #{url}"
98
+ end
99
+ end
100
+
101
+ def update_existing_repo(repo_path, repo_name)
102
+ Dir.chdir(repo_path) do
103
+ puts "Pulling latest changes for #{repo_name}..."
104
+ system("git checkout main && git pull")
105
+ end
106
+ end
107
+
108
+ def clone_new_repo(url, repo_path, repo_name)
109
+ puts "Cloning repository #{repo_name} into #{repo_path}..."
110
+ system("git clone #{url} #{repo_path}")
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,4 @@
1
+ # lib/repomate/version.rb
2
+ module Repomate
3
+ VERSION = "0.1.1"
4
+ end
data/lib/repomate.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Repomate
2
+ require_relative 'lib/repomate/version'
3
+ require_relative 'lib/repomate/config'
4
+ require_relative 'lib/repomate/manager'
5
+ end
@@ -0,0 +1,4 @@
1
+ # shell/zsh/repomate.zsh
2
+ function repomate() {
3
+ ruby ~/.local/bin/sync-repos.rb "$@"
4
+ }
@@ -0,0 +1,10 @@
1
+ # shell/fish/repomate.fish
2
+ function repomate
3
+ ruby ~/.local/bin/repomate.rb $argv
4
+ end
5
+
6
+ # Add completions for the commands
7
+ complete -c repomate -f -a "sync" -d "Synchronize all repositories"
8
+ complete -c repomate -f -a "add" -d "Add repository to sync list"
9
+ complete -c repomate -f -a "remove" -d "Remove repository from sync list"
10
+ complete -c repomate -f -a "list" -d "Show all repositories in sync list"
@@ -0,0 +1,4 @@
1
+ # shell/zsh/repomate.zsh
2
+ function repomate() {
3
+ ruby ~/.local/bin/sync-repos.rb "$@"
4
+ }
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repohub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Quiterio
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-02-07 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: optparse
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.7'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.7'
26
+ - !ruby/object:Gem::Dependency
27
+ name: fileutils
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.4'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.4'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '13.0'
68
+ description: Repomate helps you maintain a list of git repositories and keep them
69
+ up to date with their remote sources
70
+ executables:
71
+ - repomate
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - README.md
76
+ - bin/repomate
77
+ - lib/repomate.rb
78
+ - lib/repomate/cli.rb
79
+ - lib/repomate/config.rb
80
+ - lib/repomate/manager.rb
81
+ - lib/repomate/version.rb
82
+ - shell/bash/repomate.bash
83
+ - shell/fish/repomate.fish
84
+ - shell/zshell/repomate.zshell
85
+ homepage: https://github.com/alex-quiterio/repomate
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ homepage_uri: https://github.com/alex-quiterio/repomate
90
+ changelog_uri: https://github.com/alex-quiterio/repomate/blob/main/CHANGELOG.md
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.6.0
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.6.2
106
+ specification_version: 4
107
+ summary: A tool to manage and synchronize multiple git repositories
108
+ test_files: []