smdev 1.0.0 → 1.1.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 +4 -4
- data/lib/smdev/pr_critic.rb +161 -0
- data/lib/smdev.rb +20 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765960984178bcccda8cdb11c0d9b8f78c93ce5f2069400f5d2ad166835d8492
|
4
|
+
data.tar.gz: 45ae90448f47e62b4e764c5c25c822b076ed8ac1ec46fb910bd4e16aaf21744c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7fb1786959261799c89e00bb2ea1d047a657ef4f71a231916ab0f95cbe898f118d8015ec57302ae037b26b00597801d4193274f099110e588b86e989f64c4f1
|
7
|
+
data.tar.gz: da73eeeb86d44b9d82efe0646bd5c4ec6139109252072ae1d8a7404f096d10f8f39187f63cb2b17060775074272578b9bc6314de68a6a2ce26cc675d7682f8da
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'dotenv/load'
|
2
|
+
require 'octokit'
|
3
|
+
require 'clipboard'
|
4
|
+
require 'base64'
|
5
|
+
require 'io/console'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
module Smdev
|
9
|
+
module PrCritic
|
10
|
+
def self.analyze(options = {})
|
11
|
+
|
12
|
+
welcome_message
|
13
|
+
|
14
|
+
github_owner = ENV['GITHUB_OWNER']
|
15
|
+
github_repo = ENV['GITHUB_REPO']
|
16
|
+
|
17
|
+
if github_owner.nil? || github_repo.nil?
|
18
|
+
error 'Please set GITHUB_OWNER and GITHUB_REPO in your .env file.'
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
token = ENV['GITHUB_TOKEN']
|
23
|
+
if token.nil?
|
24
|
+
print "GitHub personal access token: "
|
25
|
+
token = STDIN.noecho(&:gets).chomp
|
26
|
+
puts ""
|
27
|
+
end
|
28
|
+
|
29
|
+
client = Octokit::Client.new(access_token: token)
|
30
|
+
|
31
|
+
begin
|
32
|
+
state = options[:pr_state] || 'open'
|
33
|
+
puts "Fetching #{state} pull requests...".bold.green
|
34
|
+
prs = client.pull_requests("#{github_owner}/#{github_repo}", state: state)
|
35
|
+
|
36
|
+
if prs.empty?
|
37
|
+
puts "No #{state} pull requests found."
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
header 'Select a Pull Request from the list below:'
|
42
|
+
divider
|
43
|
+
prs.each_with_index do |pr, index|
|
44
|
+
puts "[#{index + 1}] ##{pr.number}: #{pr.title}"
|
45
|
+
end
|
46
|
+
|
47
|
+
divider
|
48
|
+
print 'Enter the number corresponding to the Pull Request: '
|
49
|
+
pr_index = gets.chomp.to_i - 1
|
50
|
+
|
51
|
+
if pr_index < 0 || pr_index >= prs.size
|
52
|
+
error 'Invalid selection. Exiting.'
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
56
|
+
pr = prs[pr_index]
|
57
|
+
pr_number = pr.number
|
58
|
+
|
59
|
+
files = client.pull_request_files("#{github_owner}/#{github_repo}", pr_number)
|
60
|
+
|
61
|
+
pr_content = "Pull Request Name: #{pr.title}\n\nDescription:\n#{pr.body}\n\nFiles Changed:\n"
|
62
|
+
files.each do |file|
|
63
|
+
pr_content += "- #{file.filename}\nChanges:\n#{file.patch}\n\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
Clipboard.copy(pr_content)
|
67
|
+
divider
|
68
|
+
header 'Pull Request details and changes have been copied to the clipboard!'
|
69
|
+
header 'Visit the following link to analyze it:'
|
70
|
+
link 'https://chatgpt.com/g/g-67918801886081919bebf4848a94fe29-rails-pr-reviewer'
|
71
|
+
divider
|
72
|
+
|
73
|
+
loop do
|
74
|
+
header 'Additional options:'
|
75
|
+
divider
|
76
|
+
puts '1. Copy the entire content of the changed files to clipboard.'
|
77
|
+
puts '2. Copy the content of db/schema.rb to the clipboard.'
|
78
|
+
puts '3. Exit'
|
79
|
+
print 'Enter your choice: '
|
80
|
+
choice = gets.chomp.to_i
|
81
|
+
|
82
|
+
case choice
|
83
|
+
when 1
|
84
|
+
file_contents = ""
|
85
|
+
files.each do |file|
|
86
|
+
content = client.contents("#{github_owner}/#{github_repo}", path: file.filename, ref: pr.head.sha).content
|
87
|
+
decoded_content = Base64.decode64(content)
|
88
|
+
file_contents += "File: #{file.filename}\n\n#{decoded_content}\n\n"
|
89
|
+
end
|
90
|
+
Clipboard.copy(file_contents)
|
91
|
+
|
92
|
+
divider
|
93
|
+
status 'The content of the changed files has been copied to the clipboard!'
|
94
|
+
divider
|
95
|
+
when 2
|
96
|
+
schema_content = client.contents("#{github_owner}/#{github_repo}", path: 'db/schema.rb', ref: pr.head.sha).content
|
97
|
+
decoded_schema_content = Base64.decode64(schema_content)
|
98
|
+
Clipboard.copy(decoded_schema_content)
|
99
|
+
|
100
|
+
divider
|
101
|
+
status 'The content of db/schema.rb has been copied to the clipboard!'
|
102
|
+
divider
|
103
|
+
when 3
|
104
|
+
divider
|
105
|
+
header 'Exiting. Goodbye!'
|
106
|
+
break
|
107
|
+
else
|
108
|
+
error 'Invalid choice. Please try again.'
|
109
|
+
divider
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
rescue Octokit::NotFound
|
114
|
+
puts 'Pull Request not found. Please ensure the PR number is correct.'
|
115
|
+
rescue Octokit::Unauthorized
|
116
|
+
puts 'Unauthorized! Please check your GitHub token in the .env file.'
|
117
|
+
rescue StandardError => e
|
118
|
+
puts "An error occurred: #{e.message}"
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.header(message)
|
124
|
+
puts message.bold
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.status(message)
|
128
|
+
puts message.green.bold
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.link(message)
|
132
|
+
puts message.blue.underline.bold
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.error(message)
|
136
|
+
puts message.red.bold
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.divider
|
140
|
+
puts '---------------------------------------------------------------------------------------------'
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.welcome_message
|
144
|
+
puts ' ██▓███ ██▀███ ▄████▄ ██▀███ ██▄▄▄█████▓██▓▄████▄ '.red
|
145
|
+
puts ' ▓██░ ██▓██ ▒ ██▒ ▒██▀ ▀█ ▓██ ▒ ██▓██▓ ██▒ ▓▓██▒██▀ ▀█ '.red
|
146
|
+
puts ' ▓██░ ██▓▓██ ░▄█ ▒ ▒▓█ ▄▓██ ░▄█ ▒██▒ ▓██░ ▒▒██▒▓█ ▄ '.red
|
147
|
+
puts ' ▒██▄█▓▒ ▒██▀▀█▄ ▒▓▓▄ ▄██▒██▀▀█▄ ░██░ ▓██▓ ░░██▒▓▓▄ ▄██▒'.red
|
148
|
+
puts ' ▒██▒ ░ ░██▓ ▒██▒ ▒ ▓███▀ ░██▓ ▒██░██░ ▒██▒ ░░██▒ ▓███▀ ░'.red
|
149
|
+
puts ' ▒▓▒░ ░ ░ ▒▓ ░▒▓░ ░ ░▒ ▒ ░ ▒▓ ░▒▓░▓ ▒ ░░ ░▓ ░ ░▒ ▒ ░'.red
|
150
|
+
puts ' ░▒ ░ ░▒ ░ ▒░ ░ ▒ ░▒ ░ ▒░▒ ░ ░ ▒ ░ ░ ▒ '.red
|
151
|
+
puts ' ░░ ░░ ░ ░ ░░ ░ ▒ ░ ░ ▒ ░ '.red
|
152
|
+
puts ' ░ ░ ░ ░ ░ ░ ░ ░ '.red
|
153
|
+
puts ' ░ ░ '.red
|
154
|
+
puts ' '
|
155
|
+
puts '---------------------------------------------------------------------------------------------'.yellow
|
156
|
+
puts 'This tool can help you analyze your pull request, point out issues and recommend improvements'.bold.yellow
|
157
|
+
puts '---------------------------------------------------------------------------------------------'.yellow
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
data/lib/smdev.rb
CHANGED
@@ -3,6 +3,7 @@ require 'io/console'
|
|
3
3
|
require 'octokit'
|
4
4
|
require 'optparse'
|
5
5
|
require 'smdev/ecs_exec'
|
6
|
+
require 'smdev/pr_critic'
|
6
7
|
|
7
8
|
module Smdev
|
8
9
|
class CLI
|
@@ -39,6 +40,18 @@ module Smdev
|
|
39
40
|
options[:command] = ecs_command
|
40
41
|
end
|
41
42
|
|
43
|
+
opts.on("-p", "--pr", "Run PR Critic to analyze GitHub pull requests.") do
|
44
|
+
options[:pr_critic] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("--open", "Filter to show only open pull requests. (default)") do
|
48
|
+
options[:pr_state] = 'open'
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("--closed", "Filter to show only closed pull requests.") do
|
52
|
+
options[:pr_state] = 'closed'
|
53
|
+
end
|
54
|
+
|
42
55
|
opts.on("-h", "--help", "Prints this help message") do
|
43
56
|
puts opts
|
44
57
|
puts "\nCommands:"
|
@@ -48,6 +61,13 @@ module Smdev
|
|
48
61
|
|
49
62
|
end.parse!
|
50
63
|
|
64
|
+
# Check for pr_critic flag before command processing
|
65
|
+
if options[:pr_critic]
|
66
|
+
options[:pr_state] ||= 'open' # Set default state if none specified
|
67
|
+
Smdev::PrCritic.analyze(options)
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
51
71
|
command = args.shift
|
52
72
|
|
53
73
|
case command
|
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: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Neighbors
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: StrongMind Development Tool
|
14
14
|
email: derek.neighbors@strongmind.com
|
@@ -20,11 +20,12 @@ files:
|
|
20
20
|
- bin/smdev
|
21
21
|
- lib/smdev.rb
|
22
22
|
- lib/smdev/ecs_exec.rb
|
23
|
+
- lib/smdev/pr_critic.rb
|
23
24
|
homepage: https://github.com/StrongMind/Helpers/tree/main/smdev
|
24
25
|
licenses:
|
25
26
|
- MIT
|
26
27
|
metadata: {}
|
27
|
-
post_install_message:
|
28
|
+
post_install_message:
|
28
29
|
rdoc_options: []
|
29
30
|
require_paths:
|
30
31
|
- lib
|
@@ -39,8 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
42
|
requirements: []
|
42
|
-
rubygems_version: 3.
|
43
|
-
signing_key:
|
43
|
+
rubygems_version: 3.4.20
|
44
|
+
signing_key:
|
44
45
|
specification_version: 4
|
45
46
|
summary: StrongMind Development Tool
|
46
47
|
test_files: []
|