Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rspec_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
example_id | status | run_time |
------------------------------ | ------ | --------------- |
./spec/prreview_spec.rb[1:1] | passed | 0.00059 seconds |
./spec/prreview_spec.rb[2:1:1] | passed | 0.01083 seconds |
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
```
ruby pr-review.rb https://github.com/evmorov/pr-review-prompt/pull/2
```
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 0 additions & 81 deletions pr-review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,4 @@ def initialize
@pr_url = ARGV[0]
raise "No Github URL is provided" if @pr_url.nil? || @pr_url.empty?
end

def run
prompt = []

prompt << @pr_url

readme = request_gh("gh repo view #{repo_url}")
prompt << wrap_content('README.md', remove_markdown(readme))

details_with_comments = request_gh("gh pr view --comments #{@pr_url}")
prompt << wrap_content('PR description and comments', remove_markdown(details_with_comments))

commits = request_gh(%{gh pr view --json commits #{@pr_url} | jq -r '.commits[] | "\\(.authors[0].name) (\\(.authors[0].login)) – \\(.messageHeadline)"'})
prompt << wrap_content('PR commits', commits)

prompt << files

diff = request_gh("gh pr diff #{@pr_url}")
prompt << wrap_content('PR diff', diff)

task = "Check the PR. Do you see any problems there?"
prompt << wrap_content('Your task', task)

IO.popen('pbcopy', 'w') { |io| io.puts(prompt) }
end

private

def files
result = []
file_paths = request_gh("gh pr diff --name-only #{@pr_url}")

file_paths.split("\n").each do |file_path|
content = request_gh("gh api #{api_contents_path}/#{file_path}?ref=#{branch} | jq -r '.content' | base64 --decode")
next unless content

result << wrap_content(file_path, content)
end

result
end

def api_contents_path
@api_contents_path ||= "repos/#{repo_url.split('github.com/')[1]}/contents"
end

def repo_url
Comment thread
evmorov marked this conversation as resolved.
@repo_url ||= @pr_url.split('/pull')[0]
end

def branch
@branch ||= request_gh("gh pr view #{@pr_url} --json headRefName -q .headRefName").strip
end
Comment on lines -58 to -60

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not resolved with a link evmorov/lang-compare#1


def wrap_content(file_name, content)
r = []
r << "\n"
r << "## #{file_name}"
r << "\n"
r << "```"
r << content
r << "```"
end

def request_gh(cmd)
puts cmd
stdout, stderr, status = Open3.capture3(cmd)

unless stderr.empty?
puts stderr
return
end

stdout
end

def remove_markdown(content)
content.delete("`").delete("#")
end
end

PrReview.new.run
4 changes: 4 additions & 0 deletions sample.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.