Class: Github::Pusher
- Inherits:
-
Object
- Object
- Github::Pusher
- Defined in:
- lib/github/pusher.rb
Constant Summary collapse
- TREE_QUERY =
%w( SELECT q.id as query_id, blob_sha FROM queries q JOIN ( SELECT qv2.query_id, qv2.blob_sha FROM query_versions qv2 JOIN ( SELECT query_id, max(version) max FROM query_versions group by 1 ) qv3 ON qv2.query_id=qv3.query_id AND qv2.version = qv3.max ) qv ON q.id = qv.query_id AND coalesce(qv.blob_sha, '') != '' ).join(' ')
- LAST_SHAS =
%w( SELECT tree_sha, commit_sha FROM query_versions WHERE coalesce(tree_sha, '') != '' AND coalesce(commit_sha, '') != '' ORDER BY id DESC LIMIT 1 ).join(' ')
Instance Method Summary collapse
- #create_blob(body) ⇒ Object
- #create_commit(query_id, tree_sha, parent_commit_sha, version, author, email) ⇒ Object
- #create_tree(query_id, blob_sha, base_tree) ⇒ Object
- #git_push(query_id, body, version, author, email) ⇒ Object
Instance Method Details
#create_blob(body) ⇒ Object
31 32 33 34 35 |
# File 'lib/github/pusher.rb', line 31 def create_blob(body) blob_sha = Blob.create(body) raise "Error: invalid blob_sha #{blob_sha}" unless valid_sha?(blob_sha) blob_sha end |
#create_commit(query_id, tree_sha, parent_commit_sha, version, author, email) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/github/pusher.rb', line 49 def create_commit(query_id, tree_sha, parent_commit_sha, version, , email) = { 'name' => , 'email' => email, 'date' => DateTime.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ') } parents = parent_commit_sha.nil? ? [] : [parent_commit_sha] commit_sha = Commit.create("Version #{version} for query #{query_id}", tree_sha, parents, ) raise "Error: invalid commit_sha #{commit_sha}" unless valid_sha?(commit_sha) commit_sha end |
#create_tree(query_id, blob_sha, base_tree) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/github/pusher.rb', line 37 def create_tree(query_id, blob_sha, base_tree) tree = {} ActiveRecord::Base.connection.execute(TREE_QUERY).each do |query| tree[query['query_id'].to_s] = to_tree_hash(query['query_id'], query['blob_sha']) end tree[query_id.to_s] = to_tree_hash(query_id, blob_sha) tree_sha = Tree.create(tree.values, base_tree) raise "Error: invalid tree_sha #{tree_sha}" unless valid_sha?(tree_sha) tree_sha end |
#git_push(query_id, body, version, author, email) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/github/pusher.rb', line 62 def git_push(query_id, body, version, , email) last_shas = ActiveRecord::Base.connection.execute(LAST_SHAS).first base_tree = nil parent_commit_sha = nil if last_shas base_tree = last_shas['tree_sha'] parent_commit_sha = last_shas['commit_sha'] end blob_sha = create_blob(body) tree_sha = create_tree(query_id, blob_sha, base_tree) commit_sha = create_commit(query_id, tree_sha, parent_commit_sha, version, , email) Refs.update(APP_CONFIG['github_ref'], commit_sha) [blob_sha, commit_sha, tree_sha] end |