Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub issue link filter #81

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions Rules
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env ruby

ignore '/github/**/*'

preprocess do
hide_items_from_sitemap
end

compile '/**/*.{html,md}' do
filter :erb
filter :github_issues
filter :kramdown, auto_ids: false if item.identifier =~ '/**/*.md'
filter :colorize_syntax, :default_colorizer => :rouge
layout '/default.*'
Expand Down
27 changes: 27 additions & 0 deletions lib/github_issues_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class GitHubIssuesFilter < Nanoc::Filter
identifier :github_issues
type :text

def run(content, params={})
liblcf_issues = @items.find_all('/github/liblcf/issues/*')
player_issues = @items.find_all('/github/player/issues/*')

content.scan(/player#\d+/).each { |x|
n = (x.match /\d+/)[0].to_i
issue = player_issues[n]
type = issue[:is_pr] ? "pulls" : "issues"
url = "https://github.com/EasyRPG/Player/#{type}/#{n}"
content = content.gsub(x, "[\##{n}](#{url} \"Player: #{issue[:title]}\")")
}

content.scan(/liblcf#\d+/).each { |x|
n = (x.match /\d+/)[0].to_i
issue = liblcf_issues[n]
type = issue[:is_pr] ? "pulls" : "issues"
url = "https://github.com/EasyRPG/liblcf/#{type}/#{n}"
content = content.gsub(x, "[\##{n}](#{url} \"liblcf: #{issue[:title]}\")")
}

content
end
end
11 changes: 11 additions & 0 deletions lib/github_liblcf_datasource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'json'

class GithubLibLcfDataSource < Nanoc::DataSource
identifier :github_liblcf

def items
JSON.parse(open(".cache/liblcf_issues.json").read()).map do |x|
new_item(x["title"], x, "/liblcf/issues/#{x["number"]}")
end
end
end
11 changes: 11 additions & 0 deletions lib/github_player_datasource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'json'

class GithubPlayerDataSource < Nanoc::DataSource
identifier :github_player

def items
JSON.parse(open(".cache/player_issues.json").read()).map do |x|
new_item(x["title"], x, "/player/issues/#{x["number"]}")
end
end
end
33 changes: 33 additions & 0 deletions make_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

require "json"
require "open-uri"

def fetch(repo)
i = 1
res = []

loop do
j = JSON.parse(URI.open("https://api.github.com/repos/easyrpg/#{repo}/issues?per_page=100&page=#{i}&filter=all&state=all&sort=created").read())
return res if j.length == 0
j.each { |item|
res.push({
title: item["title"],
number: item["number"],
is_pr: item.key?("pull_request")
})
}
i += 1
end
end

liblcf = fetch("liblcf")
player = fetch("player")

File.open(".cache/liblcf_issues.json", "w") do |f|
f.write(JSON.pretty_generate(liblcf))
end

File.open(".cache/player_issues.json", "w") do |f|
f.write(JSON.pretty_generate(player))
end
6 changes: 6 additions & 0 deletions nanoc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ data_sources:
# UTF-8 (which they should be!), change this.
encoding: utf-8

- type: github_player
items_root: /github

- type: github_liblcf
items_root: /github

# Configuration for the “check” command, which run unit tests on the site.
checks:
# Configuration for the “internal_links” checker, which checks whether all
Expand Down