diff --git a/Gemfile b/Gemfile index c3c6e63892a..4b8f7752186 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,7 @@ gem "uglifier", :git => "https://github.com/lautis/uglifier.git" group :development do gem "rack" - gem "rest-client" - gem "github_api" + gem "github_downloads" gem "ember-docs", :git => "https://github.com/emberjs/docs-generator.git" gem "kicker" end diff --git a/Gemfile.lock b/Gemfile.lock index 9de13de359f..a68bde2ecef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,25 +38,32 @@ GEM multi_json (~> 1.0) faraday (0.8.1) multipart-post (~> 1.1) - github_api (0.5.4) - faraday (~> 0.8.0) + github_api (0.6.1) + faraday (~> 0.8.1) hashie (~> 1.2.0) multi_json (~> 1.3) nokogiri (~> 1.5.2) - oauth2 (~> 0.7) + oauth2 + github_downloads (0.1.1) + github_api (~> 0.6.0) + rest-client (~> 1.6.7) hashie (1.2.0) httpauth (0.1) + json (1.7.3) + jwt (0.1.4) + json (>= 1.2.4) kicker (2.5.0) rb-fsevent - mime-types (1.18) + mime-types (1.19) multi_json (1.3.6) multipart-post (1.1.5) - nokogiri (1.5.3) - oauth2 (0.7.1) + nokogiri (1.5.5) + oauth2 (0.8.0) faraday (~> 0.8) httpauth (~> 0.1) + jwt (~> 0.1.4) multi_json (~> 1.0) - rack (~> 1.4) + rack (~> 1.2) rack (1.4.1) rake (0.9.2.2) rb-fsevent (0.9.1) @@ -70,10 +77,9 @@ PLATFORMS DEPENDENCIES colored ember-docs! - github_api + github_downloads kicker rack rake-pipeline! rake-pipeline-web-filters! - rest-client uglifier! diff --git a/Rakefile b/Rakefile index 2a5d018f6bf..2c93ced37c1 100644 --- a/Rakefile +++ b/Rakefile @@ -8,32 +8,9 @@ def pipeline end def setup_uploader(root=Dir.pwd) - require './lib/github_uploader' - - login = origin = nil - - Dir.chdir(root) do - # get the github user name - login = `git config github.user`.chomp - - # get repo from git config's origin url - origin = `git config remote.origin.url`.chomp # url to origin - # extract USERNAME/REPO_NAME - # sample urls: https://github.com/emberjs/ember.js.git - # git://github.com/emberjs/ember.js.git - # git@github.com:emberjs/ember.js.git - # git@github.com:emberjs/ember.js - end - - repoUrl = origin.match(/github\.com[\/:]((.+?)\/(.+?))(\.git)?$/) - username = ENV['GH_USERNAME'] || repoUrl[2] # username part of origin url - repo = ENV['GH_REPO'] || repoUrl[3] # repository name part of origin url - - token = ENV["GH_OAUTH_TOKEN"] - - uploader = GithubUploader.new(login, username, repo, token) + require 'github_downloads' + uploader = GithubDownloads::Uploader.new uploader.authorize - uploader end diff --git a/lib/github_uploader.rb b/lib/github_uploader.rb deleted file mode 100644 index ccd1ab437a6..00000000000 --- a/lib/github_uploader.rb +++ /dev/null @@ -1,88 +0,0 @@ -require "rest-client" -require "github_api" - -class GithubUploader - - def initialize(login, username, repo, token=nil, root=Dir.pwd) - @login = login - @username = username - @repo = repo - @root = root - @token = token || check_token - end - - def authorized? - !!@token - end - - def token_path - File.expand_path(".github-upload-token", @root) - end - - def check_token - File.exist?(token_path) ? File.open(token_path, "rb").read : nil - end - - def authorize - return if authorized? - - require 'cgi' - - puts "There is no file named .github-upload-token in this folder. This file holds the OAuth token needed to communicate with GitHub." - puts "You will be asked to enter your GitHub password so a new OAuth token will be created." - print "GitHub Password: " - system "stty -echo" # disable echoing of entered chars so password is not shown on console - pw = STDIN.gets.chomp - system "stty echo" # enable echoing of entered chars - puts "" - - # check if the user already granted access for Ember.js Uploader by checking the available authorizations - response = RestClient.get "https://#{CGI.escape(@login)}:#{CGI.escape(pw)}@api.github.com/authorizations" - JSON.parse(response.to_str).each do |auth| - if auth["note"] == "Ember.js Uploader" - # user already granted access, so we reuse the existing token - @token = auth["token"] - end - end - - ## we need to create a new token - unless @token - payload = { - :scopes => ["public_repo"], - :note => "Ember.js Uploader", - :note_url => "https://github.com/#{@username}/#{@repo}" - } - response = RestClient.post "https://#{@login}:#{pw}@api.github.com/authorizations", payload.to_json, :content_type => :json - @token = JSON.parse(response.to_str)["token"] - end - - # finally save the token into .github-upload-token - File.open(".github-upload-token", 'w') {|f| f.write(@token)} - end - - def upload_file(filename, description, file) - return false unless authorized? - - gh = Github.new :user => @username, :repo => @repo, :oauth_token => @token - - # remvove previous download with the same name - gh.repos.downloads.list @username, @repo do |download| - if filename == download.name - gh.repos.downloads.delete @username, @repo, download.id - break - end - end - - # step 1 - hash = gh.repos.downloads.create @username, @repo, - "name" => filename, - "size" => File.size(file), - "description" => description - - # step 2 - gh.repos.downloads.upload hash, file - - return true - end - -end