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
- #labels ⇒ 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
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/problem_child/helpers.rb', line 53 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
41 42 43 44 |
# File 'lib/problem_child/helpers.rb', line 41 def create_issue issue = client.create_issue(repo, form_data["title"], issue_body, :labels => labels) 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? || key == "labels" }.map { |key,value| "* **#{key.humanize}**: #{value}"}.join("\n") end |
#labels ⇒ Object
37 38 39 |
# File 'lib/problem_child/helpers.rb', line 37 def labels form_data["labels"].join(",") if form_data["labels"] 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
46 47 48 49 50 51 |
# File 'lib/problem_child/helpers.rb', line 46 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 |