Last active
March 30, 2020 06:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source 'https://rubygems.org' | |
| gem "octokit", "~> 4.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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