smdev 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smdev.rb +87 -83
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa67f8f3b47f335c23ec5e74776cf587c3ab7657f7aed988bcb0c704c7d8611e
4
- data.tar.gz: 9e7f2552a2c211fca3fa46835135913dcaa9bf48462b22d1284f5ad5cc88d52a
3
+ metadata.gz: 74b463faf28bf0f34c9bfc7ab00726862bf4763bcb70ca3ebe7f77d6673f2052
4
+ data.tar.gz: ae57a1b92b6686b953867d803f3f213db31b970275587541ef19c735c2e1bb3b
5
5
  SHA512:
6
- metadata.gz: 5c4ec298b2832ce60e47ae7ba634e943e0365df7560d49c559ab13d51713819b71b57ab13d5dd67a0cba23594eca31813b732ede754ec69a2702415b98808e89
7
- data.tar.gz: 2e5c8397d2f75b8e1060471524d927a30e6f465182c7badcb2c0d0e6eeec1ebe8ac75bd6f15279369dea7903f988c1d5c00a9a089a691e7f87a303bdc4c886d0
6
+ metadata.gz: b1a91f538de100ccdfcf5601d448107a8afd027ed774d62b0404b72e907eeaacb052b6e56eea11c3a028f36ea2fef68683dc20fa09afd358e8c96836ee5665f2
7
+ data.tar.gz: 2907d1be5ad5c1fea1d3b0a404ba4ef6f4d198b3045c3ac232a1d84d1efc3332d79afa01fe100e59eb7cf03f894f142d9c7f88f474e20df18ad45aac85f156e8
data/lib/smdev.rb CHANGED
@@ -2,15 +2,17 @@
2
2
  require 'io/console'
3
3
  require 'octokit'
4
4
  require 'optparse'
5
- require_relative 'smdev/cli'
6
-
7
5
 
8
6
  module Smdev
9
7
  class CLI
10
- def run
8
+ def run(args = ARGV)
11
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
+
12
14
  OptionParser.new do |opts|
13
- opts.banner = "Usage: smdev.rb [options]"
15
+ opts.banner = "Usage: smdev.rb [options] <command>"
14
16
 
15
17
  opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
16
18
  options[:team] = team_name
@@ -22,35 +24,14 @@ module Smdev
22
24
 
23
25
  opts.on("-h", "--help", "Prints this help message") do
24
26
  puts opts
27
+ puts "\nCommands:"
28
+ commands.each { |cmd| puts " #{cmd}" }
25
29
  exit
26
30
  end
27
31
 
28
- opts.on("-l", "--local-app-install", "Setup this local application") do
29
- options[:local_install] = true
30
- end
31
-
32
- opts.on("-i", "--install", "Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails") do
33
- options[:install] = true
34
- end
35
32
  end.parse!
36
33
 
37
- if options[:local_install]
38
- puts "Running Bundle Install"
39
- system('bundle', 'install')
40
-
41
- puts "Copying env file"
42
- system('cp', '.env.example', '.env')
43
-
44
- puts "Create database"
45
- system('bin/rails', 'db:create')
46
-
47
- puts "Run database migrations"
48
- system('rails', 'db:migrate')
49
-
50
- end
51
-
52
- if options[:install]
53
- # Install Homebrew
34
+ def system_install
54
35
  puts "Installing Homebrew..."
55
36
  system({ 'SHELL' => '/bin/bash' }, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
56
37
  # system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
@@ -107,68 +88,91 @@ module Smdev
107
88
  # Install Ruby on Rails
108
89
  puts "Installing Ruby on Rails..."
109
90
  system('sudo', 'gem', 'install', 'rails')
110
-
111
- # If install option is provided, exit the script
112
- exit if options[:install]
113
91
  end
114
-
115
- token = ENV['GITHUB_TOKEN']
116
- if token.nil?
117
- # Prompt the user for their GitHub personal access token
118
- print "GitHub personal access token: "
119
- token = STDIN.noecho(&:gets).chomp
120
- puts ""
121
- end
122
- # Authenticate with the GitHub API using the user's credentials
123
- client = Octokit::Client.new(access_token: token)
124
-
125
- # Specify the organization name
126
- org_name = "StrongMind"
127
-
128
- if options[:team]
129
- # A team name was provided as a command-line argument
130
- team_name = options[:team]
131
- # Get a list of all teams in the organization
132
- teams = client.organization_teams(org_name)
133
- # Find the team with the specified name
134
- team = teams.find { |t| t.name == team_name }
135
- if team.nil?
136
- puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
137
- 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 ""
138
99
  end
139
- # Get a list of all repositories in the organization that are assigned to the specified team
140
- #
141
- repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
142
- puts "Team Name #{team_name} - Team ID: #{team.id}"
143
- else
144
- repos = []
145
- page_number = 1
146
- per_page = 100
147
- loop do
148
- repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
149
- repos.concat(repos_page)
150
- break if repos_page.length < per_page
151
- page_number += 1
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}`
152
149
  end
153
150
 
154
- # # No team name was provided, so get a list of all teams in the organization
155
- # teams = client.organization_teams(org_name)
156
- # # Get a list of all repositories in the organization that are assigned to each team
157
- # repos = []
158
- # teams.each do |team|
159
- # team_repos = client.team_repos(team.id)
160
- # repos.concat(team_repos)
161
- # end
162
151
  end
163
152
 
164
- # Clone each repository to a local directory
165
- repos.each do |repo|
166
- clone_url = repo.clone_url
167
- ssh_url = repo.ssh_url
168
- repo_name = repo.name
169
- url = options[:https] ? clone_url : ssh_url
170
- `git clone #{url} #{repo_name}`
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(options)
170
+ when "checkout_repos"
171
+ checkout_repos(options)
172
+ else
173
+ puts "Invalid command: #{command}. Use --help for a list of commands."
171
174
  end
175
+
172
176
  end
173
177
  end
174
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.1.1
4
+ version: 0.2.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-06-01 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: StrongMind Development Tool
14
14
  email: derek.neighbors@strongmind.com