-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathissue.erb
141 lines (114 loc) · 4 KB
/
issue.erb
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
<%
@fields=fields
# Used for comment date
def date_format(value)
begin
Date.parse(value).strftime('%Y-%m-%d')
rescue
value
end
end
# byte size to human-readable string
def number_format(d)
if d
d = d.to_i
e = Math.log10(d).to_i / 3
return '%.2f' % (d / 1000 ** e) + ['', ' k', ' M', ' G'][e]
end
return ''
end
def get_field(itemname, subitemname = nil)
result = ''
if @fields[itemname]
result = subitemname ? @fields[itemname][subitemname] : @fields[itemname]
end
result
end
# safely get a value from fields array and escape quotes for front matter
def sanitize_for_frontmatter(itemname, subitemname = nil)
result = get_field(itemname, subitemname)
if result and result.is_a? String
#result = result.gsub("\\", "\\\\\\").gsub('"', '\"') # escape quotes and backlashes
result = result.to_json(result) # json is valid yaml
end
result
end
# escape any markdown syntax and attempt to convert some things like {code}
def sanitize_for_markdown(value)
return nil if not value
# replace {code:lang}bla{code} blocks with {% highlight lang %}bla{% endhighlight %}
# result = value.gsub /{code(:([^}]*))?}((?!{code}).*){code}/m, '{% highlight \\2 %}\\3{% endhighlight %}'
@count = 0
result = value.gsub(/{code(:([^}]*))?}/) { |tag, lang|
# puts "I got #{tag} and #{lang}, count is #{@count}" ; @count +=1
@count += 1
if @count %2 == 1
# lang ? "{% highlight:#{lang} %}" : "{% highlight %}"
"\n```#{lang}"
else
#"{% endhighlight %}"
"```\n"
end
}
# for non-indented lines, escape markdown syntax
# also don't touch code blocks
in_block = false
result = result.lines.map{|line|
if line.start_with?('```')
in_block = !in_block
line # keep this line as-is
else
(line.start_with?(' ') or in_block) ?
line
:
line.gsub(/(\*|_|`|{|})/, '\\\\\1')
end
}.join
# escape markdown syntax and other liquid tags
#result = result.gsub /(\*|_|`|{|})/, '\\\\\1'
end
%>
title: <%= sanitize_for_frontmatter('summary') %>
layout: issue
tags: <%= sanitize_for_frontmatter('labels').join(',')%>
permalink: /browse/<%= key %>
issue_key: <%=key %>
issue_numeric_sort_key: <%=key.gsub(/^[^0-9]*([0-9]*)$/, '\\1') %>
issuetype: <%= sanitize_for_frontmatter('issuetype', 'name') %>
project: <%= sanitize_for_frontmatter('project', 'name') %>
project_key: <%= sanitize_for_frontmatter('project', 'key') %>
status: <%= sanitize_for_frontmatter('status', 'name') %>
resolution: <%= sanitize_for_frontmatter('resolution', 'name') %>
priority: <%= sanitize_for_frontmatter('priority', 'name') %>
components: "<%=fields['components'] ? fields['components'].collect{|c| c ? c['name'] : ''}.join(',') : ''%>"
labels: <%= sanitize_for_frontmatter('labels').join(',')%>
assignee: <%= sanitize_for_frontmatter('assignee', 'name') %>
reporter: <%= sanitize_for_frontmatter('reporter', 'name') %>
votes: <%= sanitize_for_frontmatter('votes', 'votes') %>
watchers: <%= sanitize_for_frontmatter('watches', 'watchCount') %>
created: <%= sanitize_for_frontmatter('created') %>
updated: <%= sanitize_for_frontmatter('updated') %>
resolved: <%= sanitize_for_frontmatter('resolutiondate') %>
<% if get_field('attachment') && get_field('attachment').length > 0 %>attachments:
<% get_field('attachment').each { |attachment| %>- filename: "<%=attachment['filename']%>"
author: "<%=attachment['author'] ? attachment['author']['name'] : '' %>"
size: <%=attachment['size'] ? number_format(attachment['size']) : '0'%>
mimeType: <%=attachment['mimeType'] %>
<% } %>
<% end %>
---
{% raw %}
## Description
<div markdown="1" class="description">
<%=sanitize_for_markdown fields['description']%>
</div>
## Comments
<% get_field('comment', 'comments').each do |comment| %>
{:.comment-heading}
### **<%=comment['author'] ? comment['author']['displayName'] : '?' %>** <span class="date"><%=date_format(comment['created'])%></span>
<div markdown="1" class="comment">
<%=sanitize_for_markdown comment['body']%>
</div>
<% end %>
{% endraw %}