Created
April 10, 2010 10:30
-
-
Save namelessjon/361957 to your computer and use it in GitHub Desktop.
Split and re-write dm-more history
This file contains 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
#!/usr/bin/ruby | |
# Jonathan D. Stott <[email protected]> | |
require 'fileutils' | |
require 'octopi' | |
include Octopi | |
def sh(command) | |
system command || abort(command) | |
end | |
repos = %w{ | |
dm-constraints | |
dm-is-list | |
dm-is-nested_set | |
dm-is-remixable | |
dm-is-searchable | |
dm-is-state_machine | |
dm-is-tree | |
dm-is-versioned | |
dm-migrations | |
dm-observer | |
dm-serializer | |
dm-sweatshop | |
dm-tags | |
dm-timestamps | |
dm-types | |
dm-validations | |
} | |
HOME = File.expand_path('~') | |
def dir(repository) | |
# tmp is a ramdrive, for speed. | |
File.join("#{HOME}/tmp/", repository) | |
end | |
def rewrite_history(repository) | |
# create a clone | |
sh "git clone --quiet --no-hardlinks dm-more #{dir(repository)}" | |
FileUtils.cd dir(repository) do | |
# rewrite to subdir | |
# --all and --tag-name-filter 'cat' ensure we also re-write tags. | |
sh "git filter-branch --prune-empty --subdirectory-filter #{repository} --tag-name-filter 'cat' -- --all" | |
# clean up after our butchery! | |
# not all these steps are needed (I think gc does some pruning, frex) | |
sh "git reset --hard" | |
sh "git prune" | |
sh "git gc --aggressive" | |
sh "git fsck" | |
end | |
end | |
def create_github_repository(repository, users=%w{dkubb snusnu solnic dbussink myabc namelessjon}) | |
authenticated_with :login => "datamapper", :token => "API_TOKEN" do | |
tries = 0 | |
begin | |
Repository.create(:name => repository, :homepage => "http://datamapper.org/", :description => description_for(repository)) | |
rescue APICache::TimeoutError => e | |
raise e if tries > 2 | |
tries += 1 | |
sleep (10*tries*tries) | |
retry | |
end | |
users.each do |user| | |
tries = 0 | |
begin | |
Api.api.post("/repos/collaborators/#{repository}/add/#{user}") | |
rescue APICache::TimeoutError => e | |
raise e if tries > 2 | |
tries += 1 | |
sleep (10*tries*tries) | |
retry | |
end | |
end | |
end | |
end | |
def push_to_github(repository) | |
FileUtils.cd dir(repository) do | |
sh "git remote rm origin" | |
sh "git remote add origin [email protected]:datamapper/#{repository}.git" | |
sh "git push origin master" | |
sh "git push --tags" | |
end | |
end | |
def description_for(repository) | |
spec = nil | |
FileUtils.cd dir(repository) do | |
gemspec = "#{repository}.gemspec" | |
spec = eval(File.read(gemspec)) | |
end | |
raise "Empty summary for '#{repository}'" if spec.summary.empty? | |
spec.summary | |
end | |
new_home = "#{HOME}/src/dm/dm-more-rewrite" | |
FileUtils.mkdir_p new_home | |
repos.each do |repo| | |
sleep(300) # avoid API rate limiting. | |
rewrite_history(repo) | |
create_github_repository(repo) | |
push_to_github(repo) | |
FileUtils.mv dir(repo), new_home | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment