Module: GitHubCSV

Defined in:
lib/githubcsv/githubcsv.rb

Class Method Summary collapse

Class Method Details

.initialize(curr_username, curr_password, from_username, from_project, timezone) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/githubcsv/githubcsv.rb', line 15

def self.initialize(curr_username, curr_password, from_username, from_project, timezone) 
  @USERID = curr_username
  @PASSWORD = curr_password
  
  @USER = from_username
  @PROJECT = from_project
  @TIMEZONE_OFFSET = timezone
end

.run(is_verbose) ⇒ Object



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
# File 'lib/githubcsv/githubcsv.rb', line 24

def self.run(is_verbose) 
  Octokit.configure do |c|
    c.connection_options = { ssl: { verify: false } }
  end
  @VERBOSE = is_verbose
  
  client = Octokit::Client.new(:login => @USERID, :password => @PASSWORD)
  csv = CSV.new(File.open(File.dirname(__FILE__) + "/issues.csv", 'w'))
  
  if @VERBOSE == 1 
    puts "Initializing CSV file..."
  end
  
  #CSV Headers

  header = [
    "Summary",
    "Description",
    "Date created",
    "Date modified",
    "Issue type",
    "Milestone",
    "Priority",
    "Status",
    "Reporter"
  ]

csv << header
 
if @VERBOSE == 1
  puts "Downloading GitHub issues..."
end

temp_issues = []
issues = []
page = 0

begin
  page = page +1
  temp_issues = client.list_issues("#{@USER}/#{@PROJECT}", :state => "closed", :page => page)
  issues = issues + temp_issues;
end while not temp_issues.empty?

temp_issues = []
page = 0

begin
  page = page +1
  temp_issues = client.list_issues("#{@USER}/#{@PROJECT}", :state => "open", :page => page)
  issues = issues + temp_issues;
end while not temp_issues.empty?
 
if @VERBOSE == 1
  puts "Processing #{issues.size} issues..."
end

issues.each do |issue|

  if @VERBOSE == 1
    puts "Processing issue #{issue['number']}..."
  end
  
  #type matching

  case
    when issue['labels'].to_s =~ /Bug/i
      type = "Bug"
    when issue['labels'].to_s =~ /Feature/i
      type = "Feature"
    when issue['labels'].to_s =~ /Task/i
      type = "Task"
  end
 
  #priority matching

  case
    when issue['labels'].to_s =~ /HIGH/i
      priority = "Critical"
    when issue['labels'].to_s =~ /MEDIUM/i
      priority = "Major"
    when issue['labels'].to_s =~ /LOW/i
      priority = "Minor"
  end
  milestone = issue['milestone'] || "None"
  if (milestone != "None")
    milestone = milestone['title']
  end
 
  #get time and parse it for each issue

  row = [
    issue['title'],
    issue['body'],     
    #DateTime.parse(issue['created_at']).new_offset(TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"),

    #DateTime.parse(issue['updated_at']).new_offset(TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"),

    "this feature is broken as of gem v0.1.0",
    "this feature is broken as of gem v0.1.0",
    type,
    milestone,
    priority,
    issue['state'],
    issue['user']['login']
  ]
  csv << row
  end
end