Created
March 4, 2016 19:30
-
-
Save jkantarek/d620367a0c280f42f745 to your computer and use it in GitHub Desktop.
Get github links for all projects in a folder at a given point in time
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
| # This script will look in all sub-directories to find any git project with a `deployed` branch | |
| # It will print out direct links to git repositories at the provided date to help triage | |
| # repositories at a certain point in time. | |
| date = ARGV[0] | |
| directories = Dir['./*'] | |
| git_projects = directories.select{|dir| Dir.exists?(dir+'/.git')} | |
| project_to_url = {} | |
| puts 'Building list' | |
| git_projects.each_with_index do |proj, i| | |
| print ['|', '/', '-', '\\'][(i % 4)-1] + "\r" | |
| next if %x[git -C #{proj} ls-remote ./ origin/deployed].empty? | |
| sha = %x[git -C #{proj} rev-list -1 --before="#{date}" origin/deployed].strip | |
| next if sha.empty? | |
| git_path = %x[git -C #{proj} config --get remote.origin.url].split(':')[-1] | |
| next if git_path.nil? | |
| url_path = git_path.strip.gsub('.git', "/tree/#{sha}") | |
| project_to_url[proj[2..-1]] = "github.com/#{url_path}" | |
| end | |
| padding = project_to_url.keys.max_by(&:length).length | |
| project_to_url.each do |name, url| | |
| rel_padding = ' ' | |
| (padding - name.length).times { |_| rel_padding << ' ' } | |
| puts [name, rel_padding, ':', url].join(' ') | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment