smdev 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smdev.rb +87 -81
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb7ef8e326aefb0cec817caef086d1079b26404c1cc6d04ebc91c8db5ccf7b5
|
4
|
+
data.tar.gz: 12b8cc2b5899723602ae6347c31f5cffb9ecf6026ebc39f595d7bc670abe0346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8e0db249fa4c0f91eee94c4ba0408ee6ea7517a58d6c0b8e91b12f700786ee0a8e504b0fe05bf25b4ba76f7a03b4f5297d755648ae429ee071cc73c221967b7
|
7
|
+
data.tar.gz: 0d31f663ac690004e11f3a3a05c45f995dc4f7c9cf51e5f193b08e73398dddfc36f5718c4602f3a053ed320a0c4892a82bae2be1a0434edc4e43c7cd68c4b105
|
data/lib/smdev.rb
CHANGED
@@ -5,10 +5,14 @@ require 'optparse'
|
|
5
5
|
|
6
6
|
module Smdev
|
7
7
|
class CLI
|
8
|
-
def run
|
8
|
+
def run(args = ARGV)
|
9
9
|
options = {}
|
10
|
+
commands = ["local_app_setup : Install local requirements for application. (Rails Only Currently)\n",
|
11
|
+
"system_install : Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails\n",
|
12
|
+
"checkout_repos : Checkout all repositories for StrongMind\n"]
|
13
|
+
|
10
14
|
OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage: smdev.rb [options]"
|
15
|
+
opts.banner = "Usage: smdev.rb [options] <command>"
|
12
16
|
|
13
17
|
opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
|
14
18
|
options[:team] = team_name
|
@@ -20,35 +24,14 @@ module Smdev
|
|
20
24
|
|
21
25
|
opts.on("-h", "--help", "Prints this help message") do
|
22
26
|
puts opts
|
27
|
+
puts "\nCommands:"
|
28
|
+
commands.each { |cmd| puts " #{cmd}" }
|
23
29
|
exit
|
24
30
|
end
|
25
31
|
|
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
32
|
end.parse!
|
34
33
|
|
35
|
-
|
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
|
34
|
+
def system_install
|
52
35
|
puts "Installing Homebrew..."
|
53
36
|
system({ 'SHELL' => '/bin/bash' }, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
|
54
37
|
# system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
|
@@ -105,68 +88,91 @@ module Smdev
|
|
105
88
|
# Install Ruby on Rails
|
106
89
|
puts "Installing Ruby on Rails..."
|
107
90
|
system('sudo', 'gem', 'install', 'rails')
|
108
|
-
|
109
|
-
# If install option is provided, exit the script
|
110
|
-
exit if options[:install]
|
111
91
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
92
|
+
def checkout_repos(options)
|
93
|
+
token = ENV['GITHUB_TOKEN']
|
94
|
+
if token.nil?
|
95
|
+
# Prompt the user for their GitHub personal access token
|
96
|
+
print "GitHub personal access token: "
|
97
|
+
token = STDIN.noecho(&:gets).chomp
|
98
|
+
puts ""
|
136
99
|
end
|
137
|
-
#
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
100
|
+
# Authenticate with the GitHub API using the user's credentials
|
101
|
+
client = Octokit::Client.new(access_token: token)
|
102
|
+
|
103
|
+
# Specify the organization name
|
104
|
+
org_name = "StrongMind"
|
105
|
+
|
106
|
+
if options[:team]
|
107
|
+
# A team name was provided as a command-line argument
|
108
|
+
team_name = options[:team]
|
109
|
+
# Get a list of all teams in the organization
|
110
|
+
teams = client.organization_teams(org_name)
|
111
|
+
# Find the team with the specified name
|
112
|
+
team = teams.find { |t| t.name == team_name }
|
113
|
+
if team.nil?
|
114
|
+
puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
|
115
|
+
exit
|
116
|
+
end
|
117
|
+
# Get a list of all repositories in the organization that are assigned to the specified team
|
118
|
+
#
|
119
|
+
repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
|
120
|
+
puts "Team Name #{team_name} - Team ID: #{team.id}"
|
121
|
+
else
|
122
|
+
repos = []
|
123
|
+
page_number = 1
|
124
|
+
per_page = 100
|
125
|
+
loop do
|
126
|
+
repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
|
127
|
+
repos.concat(repos_page)
|
128
|
+
break if repos_page.length < per_page
|
129
|
+
page_number += 1
|
130
|
+
end
|
131
|
+
|
132
|
+
# # No team name was provided, so get a list of all teams in the organization
|
133
|
+
# teams = client.organization_teams(org_name)
|
134
|
+
# # Get a list of all repositories in the organization that are assigned to each team
|
135
|
+
# repos = []
|
136
|
+
# teams.each do |team|
|
137
|
+
# team_repos = client.team_repos(team.id)
|
138
|
+
# repos.concat(team_repos)
|
139
|
+
# end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Clone each repository to a local directory
|
143
|
+
repos.each do |repo|
|
144
|
+
clone_url = repo.clone_url
|
145
|
+
ssh_url = repo.ssh_url
|
146
|
+
repo_name = repo.name
|
147
|
+
url = options[:https] ? clone_url : ssh_url
|
148
|
+
`git clone #{url} #{repo_name}`
|
150
149
|
end
|
151
150
|
|
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
151
|
end
|
161
152
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
153
|
+
command = args.shift
|
154
|
+
|
155
|
+
case command
|
156
|
+
when "local_app_setup"
|
157
|
+
puts "Running Bundle Install"
|
158
|
+
system('bundle', 'install')
|
159
|
+
|
160
|
+
puts "Copying env file"
|
161
|
+
system('cp', '.env.example', '.env')
|
162
|
+
|
163
|
+
puts "Create database"
|
164
|
+
system('bin/rails', 'db:create')
|
165
|
+
|
166
|
+
puts "Run database migrations"
|
167
|
+
system('rails', 'db:migrate')
|
168
|
+
when "system_install"
|
169
|
+
system_install
|
170
|
+
when "checkout_repos"
|
171
|
+
checkout_repos(options)
|
172
|
+
else
|
173
|
+
puts "Invalid command: #{command}. Use --help for a list of commands."
|
169
174
|
end
|
175
|
+
|
170
176
|
end
|
171
177
|
end
|
172
178
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smdev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Neighbors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: StrongMind Development Tool
|
14
14
|
email: derek.neighbors@strongmind.com
|