-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathdoc_methods_controller.rb
More file actions
62 lines (54 loc) · 2.31 KB
/
doc_methods_controller.rb
File metadata and controls
62 lines (54 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
class DocMethodsController < ApplicationController
def show
@doc = DocMethod.where(id: params[:id])
.select(:id, :repo_id, :path, :line, :file, :doc_comments_count)
.includes(:repo)
.first!
@comment = @doc.doc_comments.select(:comment).first
@repo = @doc.repo
@username = current_user.present? ? current_user.github : "<your name>"
@branch = GitBranchnameGenerator.new(username: @username, doc_path: @doc.path).branchname
set_title("Help Writing docs #{@doc.path} - #{@repo.full_name} #{@repo.language}")
set_description("#{@doc.missing_docs? ? "Write" : "Read"} docs for #{@repo.name} starting with #{@doc.path}.")
end
def click_method_redirect
doc = DocMethod.find(params[:id])
sub = RepoSubscription.where(user_id: params[:user_id], repo: doc.repo).first
assignment = DocAssignment.where(doc_method_id: doc.id, repo_subscription_id: sub.id).first
if assignment&.user&.id.to_s == params[:user_id]
assignment.user.record_click!
assignment.update(clicked: true)
assignment.user.update(last_clicked_at: Time.now)
redirect_to doc_method_url(doc), allow_other_host: true
else
flash[:notice] = "Bad url, if this problem persists please open an issue github.com/codetriage/codetriage"
redirect_to :root
end
rescue => e
handle_development_click(error: e, url: doc_method_url(doc))
end
def click_source_redirect
doc = DocMethod.find(params[:id])
sub = RepoSubscription.where(user_id: params[:user_id], repo: doc.repo).first
assignment = DocAssignment.where(doc_method_id: doc.id, repo_subscription_id: sub.id).first
if assignment&.user&.id.to_s == params[:user_id]
assignment.user.record_click!
assignment.update(clicked: true)
assignment.user.update(last_clicked_at: Time.now)
redirect_to doc.to_github, allow_other_host: true
else
flash[:notice] = "Bad url, if this problem persists please open an issue github.com/codetriage/codetriage"
redirect_to :root
end
rescue => e
handle_development_click(error: e, url: doc.to_github)
end
private def handle_development_click(error:, url:)
raise error unless Rails.env.development?
flash[:error] = error.inspect
puts error.message
puts error.backtrace
redirect_to url
end
end