smdev 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/smdev +3 -0
- data/lib/smdev.rb +165 -160
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ee5c9e422aae48b90084d189278e78c33178f57948ce6ef99635e9d6ecad21f
|
4
|
+
data.tar.gz: 8935b9ce2448eac97832cb02f9321b70e46f6b7a7913b58c3e7dfce28d530f18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df56102c08ba43782f61a10a9d868ae8ead1d3c792ef4c898dd16641c1248b0c5144ef316558ff35875e319144a933d4bec6e47e7d29704e898d47b71ada80d
|
7
|
+
data.tar.gz: 0a1672ee3c0bd427711ee208b92a0e690cc0579ea5845056df97af0b7c99964e412ab0578440089abd7713487ea21a876a8a1383e69981848349dd67fe193ff1
|
data/bin/smdev
ADDED
data/lib/smdev.rb
CHANGED
@@ -3,165 +3,170 @@ require 'io/console'
|
|
3
3
|
require 'octokit'
|
4
4
|
require 'optparse'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
6
|
+
module Smdev
|
7
|
+
class CLI
|
8
|
+
def run
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: smdev.rb [options]"
|
12
|
+
|
13
|
+
opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
|
14
|
+
options[:team] = team_name
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("-s", "--https", "Use HTTPS to pull repos") do
|
18
|
+
options[:https] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-h", "--help", "Prints this help message") do
|
22
|
+
puts opts
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-l", "--local-app-install", "Setup this local application") do
|
27
|
+
options[:local_install] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-i", "--install", "Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails") do
|
31
|
+
options[:install] = true
|
32
|
+
end
|
33
|
+
end.parse!
|
34
|
+
|
35
|
+
if options[:local_install]
|
36
|
+
puts "Running Bundle Install"
|
37
|
+
system('bundle', 'install')
|
38
|
+
|
39
|
+
puts "Copying env file"
|
40
|
+
system('cp', '.env.example', '.env')
|
41
|
+
|
42
|
+
puts "Create database"
|
43
|
+
system('bin/rails', 'db:create')
|
44
|
+
|
45
|
+
puts "Run database migrations"
|
46
|
+
system('rails', 'db:migrate')
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
if options[:install]
|
51
|
+
# Install Homebrew
|
52
|
+
puts "Installing Homebrew..."
|
53
|
+
system({ 'SHELL' => '/bin/bash' }, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
|
54
|
+
# system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
|
55
|
+
|
56
|
+
# Add Homebrew to PATH and run initialization script
|
57
|
+
puts "adding homebrew to .zshrc"
|
58
|
+
File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
|
59
|
+
file.write("\n")
|
60
|
+
file.write('eval "$(/opt/homebrew/bin/brew shellenv)"')
|
61
|
+
end
|
62
|
+
|
63
|
+
# Update PATH to include Homebrew
|
64
|
+
ENV['PATH'] = "#{ENV['HOME']}/.homebrew/bin:#{ENV['HOME']}/.homebrew/sbin:#{ENV['PATH']}"
|
65
|
+
|
66
|
+
# Install PostgreSQL
|
67
|
+
puts "Installing PostgreSQL..."
|
68
|
+
system('brew', 'install', 'libpq')
|
69
|
+
|
70
|
+
puts "Installing lib-pq..."
|
71
|
+
system('brew', 'install', 'postgresql@15')
|
72
|
+
|
73
|
+
# Install Code Climate
|
74
|
+
puts "Preparing Code Climate Formulae..."
|
75
|
+
system('brew', 'tap', 'codeclimate/formulae')
|
76
|
+
|
77
|
+
puts "Installing Code Climate..."
|
78
|
+
system('brew', 'install', 'codeclimate')
|
79
|
+
|
80
|
+
# TODO: need to add the path & compiler flags
|
81
|
+
# echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
|
82
|
+
# export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
|
83
|
+
# export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
|
84
|
+
|
85
|
+
# Install RBenv
|
86
|
+
puts "Installing RBenv..."
|
87
|
+
system('brew', 'install', 'rbenv')
|
88
|
+
puts "Initialize RBenv..."
|
89
|
+
File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
|
90
|
+
file.write("\n")
|
91
|
+
file.write('eval "$(rbenv init - zsh)"')
|
92
|
+
end
|
93
|
+
# Load the contents of .zshrc into a string
|
94
|
+
zshrc_contents = File.read(File.expand_path('~/.zshrc'))
|
95
|
+
|
96
|
+
# Execute a new shell session with the .zshrc contents
|
97
|
+
exec('zsh', '-c', zshrc_contents)
|
98
|
+
|
99
|
+
# Install Ruby
|
100
|
+
puts "Installing Ruby via RBenv..."
|
101
|
+
system('rbenv', 'install', '3.2.2')
|
102
|
+
puts "Making ruby 3.2.2 global ..."
|
103
|
+
system('rbenv', 'global', '3.2.2')
|
104
|
+
|
105
|
+
# Install Ruby on Rails
|
106
|
+
puts "Installing Ruby on Rails..."
|
107
|
+
system('sudo', 'gem', 'install', 'rails')
|
108
|
+
|
109
|
+
# If install option is provided, exit the script
|
110
|
+
exit if options[:install]
|
111
|
+
end
|
112
|
+
|
113
|
+
token = ENV['GITHUB_TOKEN']
|
114
|
+
if token.nil?
|
115
|
+
# Prompt the user for their GitHub personal access token
|
116
|
+
print "GitHub personal access token: "
|
117
|
+
token = STDIN.noecho(&:gets).chomp
|
118
|
+
puts ""
|
119
|
+
end
|
120
|
+
# Authenticate with the GitHub API using the user's credentials
|
121
|
+
client = Octokit::Client.new(access_token: token)
|
122
|
+
|
123
|
+
# Specify the organization name
|
124
|
+
org_name = "StrongMind"
|
125
|
+
|
126
|
+
if options[:team]
|
127
|
+
# A team name was provided as a command-line argument
|
128
|
+
team_name = options[:team]
|
129
|
+
# Get a list of all teams in the organization
|
130
|
+
teams = client.organization_teams(org_name)
|
131
|
+
# Find the team with the specified name
|
132
|
+
team = teams.find { |t| t.name == team_name }
|
133
|
+
if team.nil?
|
134
|
+
puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
|
135
|
+
exit
|
136
|
+
end
|
137
|
+
# Get a list of all repositories in the organization that are assigned to the specified team
|
138
|
+
#
|
139
|
+
repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
|
140
|
+
puts "Team Name #{team_name} - Team ID: #{team.id}"
|
141
|
+
else
|
142
|
+
repos = []
|
143
|
+
page_number = 1
|
144
|
+
per_page = 100
|
145
|
+
loop do
|
146
|
+
repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
|
147
|
+
repos.concat(repos_page)
|
148
|
+
break if repos_page.length < per_page
|
149
|
+
page_number += 1
|
150
|
+
end
|
151
|
+
|
152
|
+
# # No team name was provided, so get a list of all teams in the organization
|
153
|
+
# teams = client.organization_teams(org_name)
|
154
|
+
# # Get a list of all repositories in the organization that are assigned to each team
|
155
|
+
# repos = []
|
156
|
+
# teams.each do |team|
|
157
|
+
# team_repos = client.team_repos(team.id)
|
158
|
+
# repos.concat(team_repos)
|
159
|
+
# end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Clone each repository to a local directory
|
163
|
+
repos.each do |repo|
|
164
|
+
clone_url = repo.clone_url
|
165
|
+
ssh_url = repo.ssh_url
|
166
|
+
repo_name = repo.name
|
167
|
+
url = options[:https] ? clone_url : ssh_url
|
168
|
+
`git clone #{url} #{repo_name}`
|
169
|
+
end
|
170
|
+
end
|
25
171
|
end
|
26
|
-
|
27
|
-
opts.on("-i", "--install", "Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails") do
|
28
|
-
options[:install] = true
|
29
|
-
end
|
30
|
-
end.parse!
|
31
|
-
|
32
|
-
if options[:local_install]
|
33
|
-
puts "Running Bundle Install"
|
34
|
-
system('bundle', 'install')
|
35
|
-
|
36
|
-
puts "Copying env file"
|
37
|
-
system('cp', '.env.example', '.env')
|
38
|
-
|
39
|
-
puts "Create database"
|
40
|
-
system('bin/rails', 'db:create')
|
41
|
-
|
42
|
-
puts "Run database migrations"
|
43
|
-
system('rails', 'db:migrate')
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
if options[:install]
|
48
|
-
# Install Homebrew
|
49
|
-
puts "Installing Homebrew..."
|
50
|
-
system({'SHELL' => '/bin/bash'}, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
|
51
|
-
#system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
|
52
|
-
|
53
|
-
# Add Homebrew to PATH and run initialization script
|
54
|
-
puts "adding homebrew to .zshrc"
|
55
|
-
File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
|
56
|
-
file.write("\n")
|
57
|
-
file.write('eval "$(/opt/homebrew/bin/brew shellenv)"')
|
58
|
-
end
|
59
|
-
|
60
|
-
# Update PATH to include Homebrew
|
61
|
-
ENV['PATH'] = "#{ENV['HOME']}/.homebrew/bin:#{ENV['HOME']}/.homebrew/sbin:#{ENV['PATH']}"
|
62
|
-
|
63
|
-
# Install PostgreSQL
|
64
|
-
puts "Installing PostgreSQL..."
|
65
|
-
system('brew', 'install', 'libpq')
|
66
|
-
|
67
|
-
puts "Installing lib-pq..."
|
68
|
-
system('brew', 'install', 'postgresql@15')
|
69
|
-
|
70
|
-
# Install Code Climate
|
71
|
-
puts "Preparing Code Climate Formulae..."
|
72
|
-
system('brew', 'tap', 'codeclimate/formulae')
|
73
|
-
|
74
|
-
puts "Installing Code Climate..."
|
75
|
-
system('brew', 'install', 'codeclimate')
|
76
|
-
|
77
|
-
# TODO: need to add the path & compiler flags
|
78
|
-
# echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
|
79
|
-
# export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
|
80
|
-
# export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
|
81
|
-
|
82
|
-
|
83
|
-
# Install RBenv
|
84
|
-
puts "Installing RBenv..."
|
85
|
-
system('brew', 'install', 'rbenv')
|
86
|
-
puts "Initialize RBenv..."
|
87
|
-
File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
|
88
|
-
file.write("\n")
|
89
|
-
file.write('eval "$(rbenv init - zsh)"')
|
90
|
-
end
|
91
|
-
# Load the contents of .zshrc into a string
|
92
|
-
zshrc_contents = File.read(File.expand_path('~/.zshrc'))
|
93
|
-
|
94
|
-
# Execute a new shell session with the .zshrc contents
|
95
|
-
exec('zsh', '-c', zshrc_contents)
|
96
|
-
|
97
|
-
# Install Ruby
|
98
|
-
puts "Installing Ruby via RBenv..."
|
99
|
-
system('rbenv', 'install', '3.2.2')
|
100
|
-
puts "Making ruby 3.2.2 global ..."
|
101
|
-
system('rbenv', 'global', '3.2.2')
|
102
|
-
|
103
|
-
# Install Ruby on Rails
|
104
|
-
puts "Installing Ruby on Rails..."
|
105
|
-
system('sudo', 'gem', 'install', 'rails')
|
106
|
-
|
107
|
-
# If install option is provided, exit the script
|
108
|
-
exit if options[:install]
|
109
|
-
end
|
110
|
-
|
111
|
-
token = ENV['GITHUB_TOKEN']
|
112
|
-
if token.nil?
|
113
|
-
# Prompt the user for their GitHub personal access token
|
114
|
-
print "GitHub personal access token: "
|
115
|
-
token = STDIN.noecho(&:gets).chomp
|
116
|
-
puts ""
|
117
|
-
end
|
118
|
-
# Authenticate with the GitHub API using the user's credentials
|
119
|
-
client = Octokit::Client.new(access_token: token)
|
120
|
-
|
121
|
-
# Specify the organization name
|
122
|
-
org_name = "StrongMind"
|
123
|
-
|
124
|
-
if options[:team]
|
125
|
-
# A team name was provided as a command-line argument
|
126
|
-
team_name = options[:team]
|
127
|
-
# Get a list of all teams in the organization
|
128
|
-
teams = client.organization_teams(org_name)
|
129
|
-
# Find the team with the specified name
|
130
|
-
team = teams.find { |t| t.name == team_name }
|
131
|
-
if team.nil?
|
132
|
-
puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
|
133
|
-
exit
|
134
|
-
end
|
135
|
-
# Get a list of all repositories in the organization that are assigned to the specified team
|
136
|
-
#
|
137
|
-
repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
|
138
|
-
puts "Team Name #{team_name} - Team ID: #{team.id}"
|
139
|
-
else
|
140
|
-
repos = []
|
141
|
-
page_number = 1
|
142
|
-
per_page = 100
|
143
|
-
loop do
|
144
|
-
repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
|
145
|
-
repos.concat(repos_page)
|
146
|
-
break if repos_page.length < per_page
|
147
|
-
page_number += 1
|
148
|
-
end
|
149
|
-
|
150
|
-
# # No team name was provided, so get a list of all teams in the organization
|
151
|
-
# teams = client.organization_teams(org_name)
|
152
|
-
# # Get a list of all repositories in the organization that are assigned to each team
|
153
|
-
# repos = []
|
154
|
-
# teams.each do |team|
|
155
|
-
# team_repos = client.team_repos(team.id)
|
156
|
-
# repos.concat(team_repos)
|
157
|
-
# end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Clone each repository to a local directory
|
161
|
-
repos.each do |repo|
|
162
|
-
clone_url = repo.clone_url
|
163
|
-
ssh_url = repo.ssh_url
|
164
|
-
repo_name = repo.name
|
165
|
-
url = options[:https] ? clone_url : ssh_url
|
166
|
-
`git clone #{url} #{repo_name}`
|
167
172
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smdev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Neighbors
|
@@ -12,10 +12,12 @@ date: 2023-06-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: StrongMind Development Tool
|
14
14
|
email: derek.neighbors@strongmind.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- smdev
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- bin/smdev
|
19
21
|
- lib/smdev.rb
|
20
22
|
homepage: https://github.com/StrongMind/Helpers/tree/main/smdev
|
21
23
|
licenses:
|