gem-clone 0.2.0
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 +7 -0
- data/README.md +74 -0
- data/lib/rubygems/commands/clone_command.rb +114 -0
- data/lib/rubygems_plugin.rb +4 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf92769fcccbfc24afb0301081e3c935d02b47d1136b4afebd9ffc8c61f4564c
|
4
|
+
data.tar.gz: db3c451de56900a6629346e40168bbb7914c1c45005215012646a5e3842b3011
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bc582e2011a9396d1c47c5cad7da4705b068b650bf482c017104e19c412eb5953e98f8e84e2db110ec0aa3a9c0dc0b50af220deb718a5b733c4d80d338a05d5
|
7
|
+
data.tar.gz: 60186bc4c5e5420bfe8cf585c7edf2ce43aa1692c63c7deafbda4aac6224181918a99d6f2c35e6b2f4e74db89fcb467cfa1ea302aa074ef8c11412699658f194
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# RubyGems Clone Plugin
|
2
|
+
|
3
|
+
A RubyGems plugin that allows you to clone gem repositories using `ghq` based on gem metadata.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install rubygems-clone
|
9
|
+
```
|
10
|
+
|
11
|
+
Or build and install locally:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem build rubygems-clone.gemspec
|
15
|
+
gem install rubygems-clone-0.1.0.gem
|
16
|
+
```
|
17
|
+
|
18
|
+
## Prerequisites
|
19
|
+
|
20
|
+
This plugin requires `ghq` to be installed and available in your PATH.
|
21
|
+
|
22
|
+
```bash
|
23
|
+
# Install ghq (example for macOS)
|
24
|
+
brew install ghq
|
25
|
+
|
26
|
+
# Or install via Go
|
27
|
+
go install github.com/x-motemen/ghq@latest
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```bash
|
33
|
+
# Clone a gem repository
|
34
|
+
gem clone sinatra
|
35
|
+
|
36
|
+
# Clone with verbose output
|
37
|
+
gem clone rails --verbose
|
38
|
+
```
|
39
|
+
|
40
|
+
The command will:
|
41
|
+
|
42
|
+
1. Fetch gem metadata from RubyGems.org API
|
43
|
+
2. Extract repository URL from:
|
44
|
+
- `source_code_uri` metadata
|
45
|
+
- `homepage_uri` (if it looks like a repository URL)
|
46
|
+
- `project_uri` (if it looks like a repository URL)
|
47
|
+
3. Use `ghq get` to clone the repository
|
48
|
+
|
49
|
+
## Examples
|
50
|
+
|
51
|
+
```bash
|
52
|
+
$ gem clone sinatra
|
53
|
+
Executing: ghq get https://github.com/sinatra/sinatra
|
54
|
+
Successfully cloned repository: https://github.com/sinatra/sinatra
|
55
|
+
|
56
|
+
$ gem clone rails --verbose
|
57
|
+
Fetching gem metadata for 'rails'...
|
58
|
+
Found repository URL: https://github.com/rails/rails
|
59
|
+
Executing: ghq get https://github.com/rails/rails
|
60
|
+
Successfully cloned repository: https://github.com/rails/rails
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run tests and build the gem:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
gem build rubygems-clone.gemspec
|
69
|
+
gem install rubygems-clone-0.1.0.gem
|
70
|
+
```
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the MIT License.
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rubygems/command'
|
2
|
+
require 'rubygems/remote_fetcher'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
class Gem::Commands::CloneCommand < Gem::Command
|
8
|
+
def initialize
|
9
|
+
super 'clone', 'Clone a gem repository using ghq'
|
10
|
+
|
11
|
+
add_option('-v', '--verbose', 'Show verbose output') do |value, options|
|
12
|
+
options[:verbose] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def arguments # :nodoc:
|
17
|
+
"GEM_NAME name of gem to clone"
|
18
|
+
end
|
19
|
+
|
20
|
+
def description # :nodoc:
|
21
|
+
<<-EOF
|
22
|
+
The clone command fetches gem metadata from RubyGems.org and clones
|
23
|
+
the gem's source repository using ghq based on the homepage or
|
24
|
+
source_code_uri from the gem's metadata.
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
gem clone sinatra
|
28
|
+
gem clone rails --verbose
|
29
|
+
EOF
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute
|
33
|
+
gem_name = get_one_gem_name
|
34
|
+
|
35
|
+
say "Fetching gem metadata for '#{gem_name}'..." if options[:verbose]
|
36
|
+
|
37
|
+
gem_info = fetch_gem_info(gem_name)
|
38
|
+
|
39
|
+
if gem_info.nil?
|
40
|
+
alert_error "Could not find gem '#{gem_name}'"
|
41
|
+
terminate_interaction 1
|
42
|
+
end
|
43
|
+
|
44
|
+
repository_url = extract_repository_url(gem_info)
|
45
|
+
|
46
|
+
if repository_url.nil?
|
47
|
+
alert_error "Could not find repository URL for gem '#{gem_name}'"
|
48
|
+
terminate_interaction 1
|
49
|
+
end
|
50
|
+
|
51
|
+
say "Found repository URL: #{repository_url}" if options[:verbose]
|
52
|
+
|
53
|
+
clone_repository(repository_url)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def fetch_gem_info(gem_name)
|
59
|
+
uri = URI("https://rubygems.org/api/v1/gems/#{gem_name}.json")
|
60
|
+
|
61
|
+
begin
|
62
|
+
response = Net::HTTP.get_response(uri)
|
63
|
+
|
64
|
+
if response.code == '200'
|
65
|
+
JSON.parse(response.body)
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
rescue => e
|
70
|
+
say "Error fetching gem info: #{e.message}" if options[:verbose]
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def extract_repository_url(gem_info)
|
76
|
+
if gem_info['source_code_uri'] && !gem_info['source_code_uri'].empty?
|
77
|
+
return normalize_repository_url(gem_info['source_code_uri'])
|
78
|
+
end
|
79
|
+
|
80
|
+
if gem_info['homepage_uri'] && is_repository_url?(gem_info['homepage_uri'])
|
81
|
+
return normalize_repository_url(gem_info['homepage_uri'])
|
82
|
+
end
|
83
|
+
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def is_repository_url?(url)
|
88
|
+
return false if url.nil? || url.empty?
|
89
|
+
|
90
|
+
url.match?(/github\.com|gitlab\.com|bitbucket\.org|codeberg\.org|sourcehut\.org/)
|
91
|
+
end
|
92
|
+
|
93
|
+
def normalize_repository_url(url)
|
94
|
+
return url if url.nil? || url.empty?
|
95
|
+
|
96
|
+
normalized_url = url.gsub(%r{/(tree|blob|commits|releases|issues|pull|tags|branches)/.*$}, '')
|
97
|
+
|
98
|
+
normalized_url.chomp('/')
|
99
|
+
end
|
100
|
+
|
101
|
+
def clone_repository(url)
|
102
|
+
command = "ghq get #{url}"
|
103
|
+
say "Executing: #{command}" if options[:verbose]
|
104
|
+
|
105
|
+
system(command)
|
106
|
+
|
107
|
+
if $?.success?
|
108
|
+
say "Successfully cloned repository: #{url}"
|
109
|
+
else
|
110
|
+
alert_error "Failed to clone repository. Make sure 'ghq' is installed and available in your PATH."
|
111
|
+
terminate_interaction 1
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-clone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi SHIBATA
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: Clone gem repositories by fetching source code URLs from gem metadata
|
13
|
+
email:
|
14
|
+
- hsbt@ruby-lang.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/rubygems/commands/clone_command.rb
|
21
|
+
- lib/rubygems_plugin.rb
|
22
|
+
homepage: https://github.com/hsbt/gem-clone
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.0
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.7.0.dev
|
41
|
+
specification_version: 4
|
42
|
+
summary: A RubyGems plugin to clone gem repositories
|
43
|
+
test_files: []
|