Skip to content

Instantly share code, notes, and snippets.

@yihyang
Last active March 30, 2020 06:06
Show Gist options
  • Select an option

  • Save yihyang/afe43a8884f36def4aead4f5552f1708 to your computer and use it in GitHub Desktop.

Select an option

Save yihyang/afe43a8884f36def4aead4f5552f1708 to your computer and use it in GitHub Desktop.
Small PR script to get all the PRs information and Notion Ticket URL between 2 different branches
source 'https://rubygems.org'
gem "octokit", "~> 4.0"
require 'octokit'
require 'json'
require 'progress_bar'
# CONFIG HERE
token = '<YOUR_TOKEN_HERE>'
old_branch = '<OLD_BRANCH_NAME>'
new_branch = '<NEW_BRANCH_NAME>'
folder_path = '<FOLDER_PATH>'
repo_name = '<REPO_NAME>'
command = "git log --oneline #{new_branch}...#{old_branch} | grep '#'"
pr_number_pattern = /(?:\#)(\d+)/
pr_regex_pattern = /(?:[\/\:\.\w\-])+notion(?:[\/\.\w\-])+/
diff = `cd #{folder_path} && #{command}`
pr_numbers = diff.scan(pr_number_pattern)
progress_bar = ProgressBar.new(pr_numbers.length)
client = Octokit::Client.new(:access_token => token)
result = pr_numbers.map do |pr_number|
pr_number = pr_number.first
response = client.pull_request(repo_name, pr_number).to_hash
title = response[:title]
github_url = response[:html_url]
notion_url = response[:body].match(pr_regex_pattern)
progress_bar.increment!
{
title: title,
github_url: github_url,
notion_url: notion_url,
}
end.sort_by do |item|
item[:notion_url] ? 0 : 1
end
result.each do |item|
puts item[:title]
puts item[:github_url]
puts item[:notion_url] if item[:notion_url]
puts ''
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment