Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

utilize dotenv #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export GH_USER="myuser"
export GH_PASSWORD="mygithubpassword"
export BASIC_USER="admin"
export BASIC_PASSWORD="password"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ pkg
#

.rvmrc

.env
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ group :development do
gem "simplecov", "~> 0.8.2"
gem "rack-test"
gem "pry"
gem 'dotenv'
end

group :default do
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -95,6 +96,7 @@ PLATFORMS
ruby

DEPENDENCIES
dotenv
gh-pivotal!
jeweler (~> 2.0.0)
nokogiri (~> 1.6.0)
Expand Down
18 changes: 12 additions & 6 deletions lib/gh-pivotal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down