Module: ProblemChild::Helpers
- Included in:
- App
- Defined in:
- lib/problem_child/helpers.rb
Instance Method Summary collapse
- #anonymous_submissions? ⇒ Boolean
- #auth! ⇒ Object
- #client ⇒ Object
- #create_issue ⇒ Object
-
#form_data ⇒ Object
abstraction to allow cached form data to be used in place of default params.
- #issue_body ⇒ Object
- #render_template(template, locals = {}) ⇒ Object
- #repo ⇒ Object
- #repo_access? ⇒ Boolean
- #token ⇒ Object
Instance Method Details
#anonymous_submissions? ⇒ Boolean
8 9 10 |
# File 'lib/problem_child/helpers.rb', line 8 def anonymous_submissions? !!(ENV["GITHUB_TOKEN"] && !ENV["GITHUB_TOKEN"].to_s.empty?) end |
#auth! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/problem_child/helpers.rb', line 49 def auth! if anonymous_submissions? true elsif ENV['GITHUB_TEAM_ID'] github_team_authenticate!(ENV['GITHUB_TEAM_ID']) elsif ENV['GITHUB_ORG_ID'] github_organization_authenticate!(ENV['GITHUB_ORG_ID']) else raise "Must define GITHUB_TEAM_ID, GITHUB_ORG_ID, OR GITHUB_TOKEN" halt 401 end end |
#client ⇒ Object
20 21 22 |
# File 'lib/problem_child/helpers.rb', line 20 def client @client ||= Octokit::Client.new :access_token => token end |
#create_issue ⇒ Object
37 38 39 40 |
# File 'lib/problem_child/helpers.rb', line 37 def create_issue issue = client.create_issue(repo, form_data["title"], issue_body) issue["number"] if issue end |
#form_data ⇒ Object
abstraction to allow cached form data to be used in place of default params
33 34 35 |
# File 'lib/problem_child/helpers.rb', line 33 def form_data session["form_data"].nil? ? params : JSON.parse(session["form_data"]) end |
#issue_body ⇒ Object
28 29 30 |
# File 'lib/problem_child/helpers.rb', line 28 def issue_body form_data.reject { |key, value| key == "title" || value.empty? }.map { |key,value| "* **#{key.humanize}**: #{value}"}.join("\n") end |
#render_template(template, locals = {}) ⇒ Object
24 25 26 |
# File 'lib/problem_child/helpers.rb', line 24 def render_template(template, locals={}) halt erb template, :layout => :layout, :locals => locals.merge({ :template => template }) end |
#repo ⇒ Object
4 5 6 |
# File 'lib/problem_child/helpers.rb', line 4 def repo ENV["GITHUB_REPO"] end |
#repo_access? ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/problem_child/helpers.rb', line 42 def repo_access? return true unless anonymous_submissions? !client.repository(repo)["private"] rescue false end |
#token ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/problem_child/helpers.rb', line 12 def token if anonymous_submissions? ENV["GITHUB_TOKEN"] elsif !github_user.nil? github_user.token end end |