diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0d4fc8d --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +export GH_USER="myuser" +export GH_PASSWORD="mygithubpassword" +export BASIC_USER="admin" +export BASIC_PASSWORD="password" diff --git a/.gitignore b/.gitignore index 34c8a44..18ae901 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ pkg # .rvmrc + +.env diff --git a/Gemfile b/Gemfile index f9e6818..49fe070 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ group :development do gem "simplecov", "~> 0.8.2" gem "rack-test" gem "pry" + gem 'dotenv' end group :default do diff --git a/Gemfile.lock b/Gemfile.lock index 4b384d1..82e5f86 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,7 @@ GEM descendants_tracker (0.0.3) diff-lcs (1.2.5) docile (1.1.2) + dotenv (1.0.2) faraday (0.9.0) multipart-post (>= 1.2, < 3) git (1.2.6) @@ -95,6 +96,7 @@ PLATFORMS ruby DEPENDENCIES + dotenv gh-pivotal! jeweler (~> 2.0.0) nokogiri (~> 1.6.0) diff --git a/lib/gh-pivotal.rb b/lib/gh-pivotal.rb index 2e10d2b..09d2ba3 100644 --- a/lib/gh-pivotal.rb +++ b/lib/gh-pivotal.rb @@ -2,6 +2,12 @@ require 'sinatra' require 'nokogiri' +begin + require 'dotenv' + Dotenv.load +rescue +end + configure do set :gh_user, ENV["GH_USER"] || "admin" set :gh_password, ENV["GH_PASSWORD"] || "admin" @@ -25,29 +31,29 @@ def fetch_issues(reponame, labels) end until issues[-1].length == 0 issues.flatten end - + def close_issue(issue_xml) issue_uri = issue_xml.xpath('//other_id').text.split("/issues/") - + return if issue_uri.nil? - + issue_base_path = issue_uri[0] issue_number = issue_uri[1] $ghcli.close_issue(issue_base_path, issue_number) end - + def protected! unless authorized? response['WWW-Authenticate'] = %(Basic realm="Restricted Area") throw(:halt, [401, "Not authorized\n"]) end end - + def authorized? @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? && @auth.basic? && @auth.credentials == [settings.basic_user, settings.basic_password] end - + end # Sinatra Routes