Class: Git2Pdf
- Inherits:
-
Object
- Object
- Git2Pdf
- Defined in:
- lib/git2pdf.rb
Instance Attribute Summary collapse
-
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
-
#repos ⇒ Object
Returns the value of attribute repos.
Instance Method Summary collapse
- #execute ⇒ Object
- #get_issues ⇒ Object
-
#initialize(options = {}) ⇒ Git2Pdf
constructor
A new instance of Git2Pdf.
- #pdf(batch) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Git2Pdf
Returns a new instance of Git2Pdf.
9 10 11 12 13 |
# File 'lib/git2pdf.rb', line 9 def initialize(={}) @repos = [:repos] || [] @basic_auth = [:basic_auth] || nil @org = [:org] || nil end |
Instance Attribute Details
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
7 8 9 |
# File 'lib/git2pdf.rb', line 7 def basic_auth @basic_auth end |
#repos ⇒ Object
Returns the value of attribute repos.
6 7 8 |
# File 'lib/git2pdf.rb', line 6 def repos @repos end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 |
# File 'lib/git2pdf.rb', line 15 def execute batch = get_issues pdf(batch) end |
#get_issues ⇒ Object
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 |
# File 'lib/git2pdf.rb', line 20 def get_issues batch = [] self.repos.each do |repo| #json = `curl -u#{auth} https://api.github.com/repos/pocketworks/repo/issues?per_page=100 | jq '.[] | {state: .state, milestone: .milestone.title, created_at: .created_at, title: .title, number: .number, labels: [.labels[].name]}'` json = "" if @org json = open("https://api.github.com/repos/#{@org}/#{repo}/issues?per_page=200&state=open", :http_basic_authentication => basic_auth).read else # for stuff like bob/stuff json = open("https://api.github.com/repos/#{repo}/issues?per_page=200&state=open", :http_basic_authentication => basic_auth).read end hash = JSON.parse(json) hash.each do |val| labels = val["labels"].collect { |l| l["name"].upcase }.join(', ') type = "" type = "BUG" if labels =~ /bug/i #not billable type = "FEATURE" if labels =~ /feature/i #billable type = "ENHANCEMENT" if labels =~ /enhancement/i #billable type = "AMEND" if labels =~ /amend/i #not billable type = "TASK" if labels =~ /task/i #not billable milestone = val["milestone"] ? val["milestone"]["title"] : "" #labels.include?(['BUG','FEATURE','ENHANCEMENT','QUESTION']) hash = {short_title: repo, ref: "#{val["number"]}", long_title: "#{val["title"]}", type: type, due: "", labels: labels, milestone: "#{milestone}"} batch << hash end end batch end |
#pdf(batch) ⇒ Object
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/git2pdf.rb', line 54 def pdf(batch) require 'prawn' row = 0 col = 0 margin = 20 Prawn::Document.generate("issues.pdf", :page_size => "A7", :margin => 0, :page_layout => :landscape) do dir = File.dirname(__FILE__) font_families.update( "Lato" => {:bold => "#{dir}/assets/fonts/Lato-Bold.ttf", :italic => "#{dir}/assets/fonts/Lato-LightItalic.ttf", :bold_italic => "#{dir}/assets/fonts/Lato-BoldItalic.ttf", :normal => "#{dir}/assets/fonts/Lato-Light.ttf"}) font 'Lato' batch = batch.sort { |a, b| a["ref"]<=>b["ref"] and a["project"]<=>b["project"] } #logo = open("http://www.pocketworks.co.uk/images/logo.png") logo = open("#{dir}/assets/images/pocketworks.png") batch.each do |issue| ## ## If needed, define a new grid ## #if row >= 5 # start_new_page # row = 0 # col = 0 #end # #if row == 0 # define_grid(:columns => 2, :rows => 4, :gutter => 0) #end # # Load json to use on the first card # #puts issue #grid(row,col).bounding_box do #transparent(0.1) { stroke_bounds } y_offset = 195 #Ref font 'Lato', :style => :bold, size: 28 text_box "##{issue[:ref]}" || "", :at => [185, y_offset], :width => 100, :overflow => :shrink_to_fit, :align => :right # image watermark image logo, :at=>[240,60], :width=>50 #Short title short_title = issue[:short_title] short_title = short_title.split('/')[1] if short_title =~ /\// font 'Lato', :style => :bold, size: 20 text_box short_title, :at => [margin, y_offset], :width => 210-margin, :overflow => :shrink_to_fit if issue[:milestone] and issue[:milestone] != "" y_offset = y_offset - 30 # Milestone font 'Lato', :style => :normal, size: 16 text_box issue[:milestone].upcase, :at => [margin, y_offset], :width => 280, :overflow => :shrink_to_fit #text_box fields["due"] || "", :at=>[120,20], :width=>60, :overflow=>:shrink_to_fit y_offset = y_offset + 20 end fill_color "EEEEEE" fill_color "D0021B" if issue[:type] == "BUG" fill_color "1D8FCE" if issue[:type] == "TASK" fill_color "FBF937" if issue[:type] == "FEATURE" fill_color "F5B383" if issue[:type] == "AMEND" fill_color "FBF937" if issue[:type] == "ENHANCEMENT" if issue[:type] and issue[:type] != "" fill{rectangle([0,220], margin-10, 220)} else fill{rectangle([0,220], margin-10, 220)} end fill_color "000000" # if issue[:type] and issue[:type] != "" # y_offset = y_offset - 20 # # Type # font 'Lato', :style => :bold, size: 16, :color => '888888' # text_box issue[:type], :at => [margin, y_offset], :width => 280-margin, :overflow => :shrink_to_fit # end if issue[:long_title] y_offset = y_offset - 50 # Long title font 'Lato', :style => :normal, size: 18 text_box issue[:long_title] ? issue[:long_title][0..120] : "NO DESCRIPTION", :at => [margin, y_offset], :width => 280-margin, :overflow => :shrink_to_fit end # Labels font 'Lato', :style => :bold, size: 12 text_box issue[:labels].length == 0 ? "NO LABELS!" : issue[:labels], :at => [margin, 20], :width => 220-margin, :overflow => :shrink_to_fit #text_box fields[:due] || "", :at=>[120,20], :width=>60, :overflow=>:shrink_to_fit #end #if col == 1 # row = row + 1 # col = 0 #else # col = col + 1 #end start_new_page unless issue == batch[batch.length-1] end end batch.length end |