Created
June 7, 2009 21:37
-
-
Save lennartkoopmann/125501 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
require File.join("/usr/lib/ruby/gems/1.8/gems/octopi-0.0.9/lib/octopi.rb") | |
include Octopi | |
require "mysql" | |
# Connect to database. | |
con = Mysql.real_connect "localhost", "user", "password", "database" | |
# Fetch all repos | |
fetch_repos_query_string = "SELECT repository_path FROM repos" | |
db_repos = con.query fetch_repos_query_string | |
db_repos.each do |db_repo| | |
from = db_repo[0].rindex '/' | |
to = (db_repo[0].rindex '.')-from | |
reponame = db_repo[0].slice from+1, to-1 | |
repo = Repository.find("lennartkoopmann", reponame) | |
message = repo.commits.first.message | |
author = repo.commits.first.author | |
date = Date.parse repo.commits.first.committed_date | |
url = repo.commits.first.url | |
# Check if this commit is already in the database. | |
check_query_string = "SELECT 1 FROM commits WHERE message = '#{con.escape_string message}'" | |
res = con.query check_query_string | |
next if res.num_rows != 0 | |
# Store in database. | |
query_string = "" | |
query_string << "INSERT INTO commits(message, date, committer, url, created_at, updated_at) " | |
query_string << "VALUES('#{con.escape_string message}', '#{date}', '#{con.escape_string author["name"]}', '#{con.escape_string url}', NOW(), NOW())" | |
con.query query_string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment