Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Add commit sha to repo #40

Merged
merged 1 commit into from
Nov 23, 2015
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ parser.process
parser.store(repo)
# DocFile.destroy_all repo = Repo.last
doc = repo.methods_missing_docs.first
GithubUrlFromBasePathLine.new(doc.repo.github_url, doc.doc_file.path, doc.line).to_github
doc.to_github


repo = Repo.where(full_name: "rails/rails").first_or_create
Expand Down
5 changes: 5 additions & 0 deletions app/models/doc_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ def file
absolute, match, relative = raw_file.partition(/(\/|^)#{repo.name}\//)
return relative
end

# converts a doc method to a github path
def to_github
GithubUrlFromBasePathLine.new(repo.github_url, repo.commit_sha, file, line).to_github
end
end
4 changes: 4 additions & 0 deletions app/models/github_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def clone
return dir
end

def commit_sha
::GitHubBub.get(File.join(repo_path, 'commits', repo_json['default_branch'])).json_body['sha']
end

def dir
@dir ||= Dir.mktmpdir
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/github_url_from_base_path_line.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class GithubUrlFromBasePathLine

def initialize(base, path, line)
def initialize(base, commit_sha, path, line)
@base = base
@commit_sha = commit_sha
@line = line
@path = path
end

# https://github.com/rails/rails/blob/master/actionmailer/lib/action_mailer/collector.rb#L10
# https://github.com/codetriage/docs_doctor/blob/f5dd91595d5cdad0a2348515c6f715ef19c51070/app/models/github_url_from_base_path_line.rb#L10
def to_github
File.join(@base, "blob/master", @path, "#L#{@line}")
File.join(@base, 'blob', @commit_sha, @path, "#L#{@line}")
end
end
1 change: 1 addition & 0 deletions app/models/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Repo < ActiveRecord::Base

def process!
fetcher = GithubFetcher.new(full_name)
self.update!(commit_sha: fetcher.commit_sha)
parser = DocsDoctor::Parsers::Ruby::Yard.new(fetcher.clone)
parser.process
parser.store(self)
Expand Down
4 changes: 2 additions & 2 deletions app/views/doc_methods/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2><%= link_to @doc.path, GithubUrlFromBasePathLine.new(@doc.repo.github_url, @doc.file, @doc.line).to_github %></h2>
<h2><%= link_to @doc.path, @doc.to_github %></h2>
<p><%= link_to @doc.repo.full_name, @doc.repo %></p>

<h3>Docs:</h3>
Expand All @@ -11,7 +11,7 @@
<% end %>
</p>
<p>
<%= link_to "Source", GithubUrlFromBasePathLine.new(@doc.repo.github_url, @doc.file, @doc.line).to_github %> |
<%= link_to "Source", @doc.to_github %> |
<%= link_to "Google", "https://www.google.com/search?q=#{URI.encode(@doc.path)}" %> |
<%= link_to "Stack overflow", "http://stackoverflow.com/search?q=#{URI.encode(@doc.path)}" %>
</p>
Expand Down
4 changes: 2 additions & 2 deletions app/views/user_mailer/daily_docs.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Hi @<%= @user.github %>,
## Write Docs

<% @write_docs.sort_by {|d| d.repo.full_name }.each do |doc| %>
**<%= doc.repo.full_name %>** ([source](<%= GithubUrlFromBasePathLine.new(doc.repo.github_url, doc.file, doc.line).to_github %>)): [<%= doc.path %>](<%= doc_method_url doc %>)
**<%= doc.repo.full_name %>** ([source](<%= doc.to_github %>)): [<%= doc.path %>](<%= doc_method_url doc %>)

<% end %>
<% end %>
Expand All @@ -15,7 +15,7 @@ Hi @<%= @user.github %>,
## Read Docs

<% @read_docs.sort_by {|d| d.repo.full_name }.each do |doc| %>
**<%= doc.repo.full_name %>** ([source](<%= GithubUrlFromBasePathLine.new(doc.repo.github_url, doc.file, doc.line).to_github %>)): [<%= doc.path %>](<%= doc_method_url doc %>)
**<%= doc.repo.full_name %>** ([source](<%= doc.to_github %>)): [<%= doc.path %>](<%= doc_method_url doc %>)

<pre>
<%= doc.doc_comments.first.try(:comment) %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20151123190940_add_commit_sha_to_repo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCommitShaToRepo < ActiveRecord::Migration
def change
add_column :repos, :commit_sha, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20141202022842) do
ActiveRecord::Schema.define(version: 20151123190940) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -97,6 +97,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.string "excluded"
t.string "commit_sha"
end

create_table "users", force: true do |t|
Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ issue_triage_sandbox:
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1
commit_sha: e01441fedcf95651acc6b7690e1f35857a74b449

rails_rails:
id: 2
Expand All @@ -17,6 +18,7 @@ rails_rails:
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 0
commit_sha: 14314ca18302f18c3d8bb7a63e9f71ac4c2290c2

sinatra_sinatra:
id: 3
Expand All @@ -27,6 +29,7 @@ sinatra_sinatra:
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1
commit_sha: fabf8efc451f361c444b288eb94292593f340f77

node:
id: 4
Expand All @@ -37,6 +40,7 @@ node:
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 0
commit_sha: ed0d1c384cd4578f7168633c838f1252bddb260e

groovebasin:
id: 5
Expand All @@ -47,8 +51,7 @@ groovebasin:
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1


commit_sha: 3a61986931d95ab1d1d2080e678907f029750573

threaded:
id: 6
Expand All @@ -59,3 +62,4 @@ threaded:
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1
commit_sha: c55e2cd91c038ef6924988ed6f53e8c77eb59246