smdev 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/smdev.rb +167 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9ea4b1a2ca72ac19992ee2fee4a209639bf2696ed360f6bcd9a13c503e033552
|
4
|
+
data.tar.gz: 8fe4db4697ea31c611d8e6865c05528938bd21ded79da7ad16320d3d6d826ae6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f22503f3d6716f1c5d2b6d2d12cd8f38e9ae3d5122a7b38493cee9b7e4045f224f15b487930f46857a40e1e7314da4d693480f4c29863cbf8fcb760df0c60479
|
7
|
+
data.tar.gz: 89a378d151f58eadabf5854a0eec8c78342210231b6672ebcb7db9041154be5cdcbb44ff742d176242210d67ccc3fdae730ba863aac0b4ee6d2f397f180f19a5
|
data/lib/smdev.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'io/console'
|
3
|
+
require 'octokit'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: smdev.rb [options]"
|
9
|
+
|
10
|
+
opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
|
11
|
+
options[:team] = team_name
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on("-s", "--https", "Use HTTPS to pull repos") do
|
15
|
+
options[:https] = true
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Prints this help message") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("-l", "--local-app-install", "Setup this local application") do
|
24
|
+
options[:local_install] = true
|
25
|
+
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smdev
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Derek Neighbors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: StrongMind Development Tool
|
14
|
+
email: derek.neighbors@strongmind.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/smdev.rb
|
20
|
+
homepage: https://github.com/StrongMind/Helpers/tree/main/smdev
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.4.13
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: StrongMind Development Tool
|
43
|
+
test_files: []
|