Skip to content

Instantly share code, notes, and snippets.

@chrishunt
Last active December 18, 2015 01:08
Show Gist options
  • Save chrishunt/5701243 to your computer and use it in GitHub Desktop.
Save chrishunt/5701243 to your computer and use it in GitHub Desktop.
What's was your first pull request?

What's was your first pull request?

$ gem install ruby-progressbar octokit
$ ruby first_pull_request.rb <github-username> <github-password>
require 'ruby-progressbar'
require 'octokit'
FirstPullRequest = Struct.new(:username, :password) do
def url
first_pull_request.html_url
end
private
def first_pull_request
sorted_closed_issues.find { |issue| issue.pull_request.html_url }
end
def sorted_closed_issues
closed_issues.select(&:created_at).sort do |l, r|
l.created_at <=> r.created_at
end
end
def closed_issues
with_progress_bar 'Fetching Issues', parent_repo_names.count do |bar|
parent_repo_names.map do |name|
bar.progress += 1
begin
github.issues name, state: 'closed', creator: username
rescue Octokit::NotFound
[] # repo no longer exists
end
end.flatten
end
end
def parent_repo_names
@parent_repo_names ||= forked_repos.map { |repo| repo.parent.full_name }
end
def forked_repos
with_progress_bar('Fetching Repos', forked_repo_names.size) do |bar|
forked_repo_names.map do |name|
bar.progress += 1
github.repository name
end
end
end
def forked_repo_names
@forked_repo_names ||= begin
with_count('were forked') { repos.select(&:fork).map(&:full_name) }
end
end
def repos
with_count('repositories') { github.repositories }
end
def github
Octokit::Client.new(
login: username,
password: password,
auto_traversal: true
)
end
def with_count(message)
yield.tap do |response|
puts %{#{"%02d" % response.count} #{message}}
end
end
def with_progress_bar(title, size)
yield(
ProgressBar.create(
title: title,
format: '%t: |%B| %p%%',
total: size
)
)
end
end
FirstPullRequest.new(ARGV.shift, ARGV.shift).url.tap do |first_pr_url|
puts "First pull request: #{first_pr_url}"
`open #{first_pr_url}`
end
@chrishunt
Copy link
Author

Please let me know if there's a better way to do this! This seems like a lot of work for finding my first pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment