-
-
Save skvl/717898c02c4581e53536d35a9fec5ef0 to your computer and use it in GitHub Desktop.
Revisions
-
harlantwood revised this gist
Jun 17, 2012 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,15 @@ # Committing changes to a repo via the Github API is not entirely trivial. # The five-step process is outlined here: # http://developer.github.com/v3/git/ # # Matt Swanson wrote a blog post translating the above steps into actual API calls: # http://swanson.github.com/blog/2011/07/23/digging-around-the-github-api-take-2.html # # I was not able to find sample code for actually doing this in Ruby, # either via the HTTP API or any of the gems that wrap the API. # So in the hopes it will help others, here is a simple function to # commit a single file to github via the API. The code only handles # the case of committing a single file to the master branch, # but should be easy to modify for your own needs. # # Note also that we use HTTP basic auth, not OAuth, in this example. -
harlantwood revised this gist
Jun 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ def push_to_github(params) branch = github(:get, repo, "refs/heads/master") last_commit_sha = branch['object']['sha'] # get the last commit # see http://developer.github.com/v3/git/commits/ last_commit = github :get, repo, "commits/#{last_commit_sha}" last_tree_sha = last_commit['tree']['sha'] -
harlantwood revised this gist
Jun 15, 2012 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,13 +16,14 @@ # # Note also that we use HTTP basic auth, not OAuth, in this example. # # Prerequisites: # # $ gem install rest-client # $ export GH_USERNAME=xxxx # $ export GH_PASSWORD=yyyy # # Usage: # # push_to_github :path => "path/to/file.txt", :content => "hello commit", :repo => 'test' # # In the above example, the repo 'test' must be owned by GH_USERNAME, and have at least one commit. -
harlantwood revised this gist
Jun 15, 2012 . 1 changed file with 11 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,7 @@ def push_to_github(params) # get the head of the master branch # see http://developer.github.com/v3/git/refs/ branch = github(:get, repo, "refs/heads/master") last_commit_sha = branch['object']['sha'] # create the last commit @@ -62,21 +62,23 @@ def push_to_github(params) # create commit # see http://developer.github.com/v3/git/commits/ new_commit = github :post, repo, :commits, :parents => [last_commit_sha], :tree => new_content_tree_sha, :message => 'commit via api' new_commit_sha = new_commit['sha'] # update branch to point to new commit # see http://developer.github.com/v3/git/refs/ github :patch, repo, "refs/heads/master", :sha => new_commit_sha end def github(method, repo, resource, params={}) resource_url = "https://#{ENV['GITHUB_USER']}:#{ENV['GITHUB_PASS']}@api.github.com" + "/repos/#{ENV['GITHUB_USER']}/#{repo}/git/#{resource}" if params.empty? JSON.parse RestClient.send(method, resource_url) else JSON.parse RestClient.send(method, resource_url, params.to_json, :content_type => :json, :accept => :json) end end -
harlantwood revised this gist
Jun 15, 2012 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Committing changes to a repo via the Github API is not entirely trivial. # # The five-step process is outlined here: # http://developer.github.com/v3/git/ @@ -13,6 +13,8 @@ # commit a single file to github via the API. The code only handles # the simple case of committing a single file to the master branch, # but should be easy to modify for your own needs. # # Note also that we use HTTP basic auth, not OAuth, in this example. # # Usage: # @@ -39,9 +41,14 @@ def push_to_github(params) repo = params[:repo] # get the head of the master branch # see http://developer.github.com/v3/git/refs/ branch = github :get, repo, "refs/heads/master" last_commit_sha = branch['object']['sha'] # create the last commit # see http://developer.github.com/v3/git/commits/ last_commit = github :get, repo, "commits/#{last_commit_sha}" last_tree_sha = last_commit['tree']['sha'] -
harlantwood revised this gist
Jun 15, 2012 . 1 changed file with 20 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,32 @@ # Committing changes to a repo via the Github API is not so simple. # # The five-step process is outlined here: # http://developer.github.com/v3/git/ # # And Matt Swanson wrote a blog post translating this into actual API calls: # http://swanson.github.com/blog/2011/07/23/digging-around-the-github-api-take-2.html # # I was not able to find sample code for actually doing this in Ruby, # either via the HTTP API or any of the gems that wrap the API. # # So in the hopes it will help others, here is a simple function to # commit a single file to github via the API. The code only handles # the simple case of committing a single file to the master branch, # but should be easy to modify for your own needs. # # Usage: # # $ gem install rest-client # # $ export GH_USERNAME=xxxx # $ export GH_PASSWORD=yyyy # # push_to_github :path => "path/to/file.txt", :content => "hello commit", :repo => 'test' # # In the above example, the repo 'test' must be owned by GH_USERNAME, and have at least one commit. # # No news is good news. If you don't raise exceptions, you should see the commit in your repo. # # CC0 Public Domain Dedication # To the extent possible under law, Harlan T Wood # has waived all copyright and related or neighboring -
harlantwood revised this gist
Jun 15, 2012 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,11 @@ # # No news is good news. If you don't raise exceptions, you should see the commit in your repo. # # Inspirations: # - http://swanson.github.com/blog/2011/07/23/digging-around-the-github-api-take-2.html # - http://developer.github.com/v3/git/ # - http://news.ycombinator.com/item?id=2746877 # # CC0 Public Domain Dedication # To the extent possible under law, Harlan T Wood # has waived all copyright and related or neighboring -
harlantwood revised this gist
Jun 15, 2012 . 2 changed files with 7 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,12 @@ # # No news is good news. If you don't raise exceptions, you should see the commit in your repo. # # CC0 Public Domain Dedication # To the extent possible under law, Harlan T Wood # has waived all copyright and related or neighboring # rights to this work. # http://creativecommons.org/publicdomain/zero/1.0/ # require 'rest_client' require 'json' @@ -49,4 +55,4 @@ def github(method, repo, resource, params={}) "/repos/#{ENV['GITHUB_USER']}/#{repo}/git/#{resource}", params.to_json, :content_type => :json, :accept => :json ) end -
harlantwood revised this gist
Jun 15, 2012 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <p xmlns:dct="http://purl.org/dc/terms/"> <a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"> <img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" /> </a> <br /> To the extent possible under law, <span rel="dct:publisher" resource="[_:publisher]">the person who associated CC0</span> with this work has waived all copyright and related or neighboring rights to this work. </p> -
harlantwood created this gist
Jun 15, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ # gem install rest-client # # export GH_USERNAME=xxxx # export GH_PASSWORD=yyyy # # Usage: # push_to_github :path => "path/to/file.txt", :content => "hello commit", :repo => 'test' # # In the above example, the repo 'test' must be owned by GH_USERNAME, and have at least one commit. # # No news is good news. If you don't raise exceptions, you should see the commit in your repo. # require 'rest_client' require 'json' def push_to_github(params) repo = params[:repo] branch = github :get, repo, "refs/heads/master" last_commit_sha = branch['object']['sha'] last_commit = github :get, repo, "commits/#{last_commit_sha}" last_tree_sha = last_commit['tree']['sha'] # create tree object (also implicitly creates a blob based on content) # see http://developer.github.com/v3/git/trees/ new_content_tree = github :post, repo, :trees, :base_tree => last_tree_sha, :tree => [{:path => params[:path], :content => params[:content], :mode => '100644'}] new_content_tree_sha = new_content_tree['sha'] # create commit # see http://developer.github.com/v3/git/commits/ new_commit = github :post, repo, :commits, :parents => [last_commit], :tree => new_content_tree_sha, :message => 'commit via api' new_commit_sha = new_commit['sha'] # update branch to point to new commit # see http://developer.github.com/v3/git/refs/ github :patch, repo, "/refs/heads/master", :sha => new_commit_sha end def github(method, repo, resource, params={}) JSON.parse RestClient.send(method, "https://#{ENV['GITHUB_USER']}:#{ENV['GITHUB_PASS']}@api.github.com" + "/repos/#{ENV['GITHUB_USER']}/#{repo}/git/#{resource}", params.to_json, :content_type => :json, :accept => :json ) end