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

Use env to lookup ruby executable and conceal password #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 11 additions & 9 deletions csv_issues_to_github.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby

# See the README for how to use this.

Expand All @@ -11,31 +11,34 @@
# Comment out this section (from here down to where the end is marked) if you want to use this interactively

puts "Username:"
username = gets.chomp
username = gets.chomp
if username == ""
abort("You need to supply a username. Thank you, come again.")
end

`stty -echo`
puts "Password:"
password = gets.chomp
password = gets.chomp
`stty echo`

if password == ""
abort("You need to supply a password. Thank you, come again.")
end

puts "Path for the CSV file you want to use?"
input_file = gets.chomp
input_file = gets.chomp
if input_file == ""
abort("You need to supply a CSV file. Thank you, come again.")
end

puts "Organization?"
org = gets.chomp
org = gets.chomp
if org == ""
abort("You need to supply an organization. Thank you, come again.")
end

puts "Repository?"
repo = gets.chomp
repo = gets.chomp
if repo == ""
abort("You need to supply a repository. Thank you, come again.")
end
Expand All @@ -50,7 +53,7 @@
input_file = ""
username = ""
password = ""
org = ""
org = ""
repo = ""
=end # END HARD-CODED SECTION

Expand All @@ -63,8 +66,7 @@

csv.each do |row|
client.create_issue(org_repo, row['title'], row['description'], options = {
:assignee => row['assignee_username'],
:assignee => row['assignee_username'],
:labels => [row['label1'],row['label2'],row['label3']]}) #Add or remove label columns here.
puts "Imported issue: #{row['title']}"
end

37 changes: 19 additions & 18 deletions github_issues_to_csv.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
#!/usr/bin/ruby
#!/usr/bin/env ruby

require 'octokit'
require 'csv'
require 'date'


# BEGIN INTERACTIVE SECTION
# Comment out this section (from here down to where the end is marked) if you want to use this interactively

puts "Username:"
USERNAME = gets.chomp
USERNAME = gets.chomp
if USERNAME == ""
abort("You need to supply a username. Thank you, come again.")
end

`stty -echo`
puts "Password:"
PASSWORD = gets.chomp
PASSWORD = gets.chomp
`stty echo`
if PASSWORD == ""
abort("You need to supply a password. Thank you, come again.")
end

puts "Name of the file you want to create? (.csv will be appended automatically)"
OUTPUT_FILE = gets.chomp
OUTPUT_FILE = gets.chomp
if OUTPUT_FILE == ""
abort("You need to supply a CSV file. Thank you, come again.")
end

puts "Organization?"
ORG = gets.chomp
ORG = gets.chomp
if ORG == ""
abort("You need to supply an organization. Thank you, come again.")
end

puts "Repository?"
REPO = gets.chomp
REPO = gets.chomp
if REPO == ""
abort("You need to supply a repository. Thank you, come again.")
end

puts "Do you want just one Milestone? If so, enter it now. Leave this blank to get the entire repo."
TARGET_MILESTONE = gets.chomp
TARGET_MILESTONE = gets.chomp

# END INTERACTIVE SECTION

Expand All @@ -50,7 +51,7 @@
=begin
OUTPUT_FILE = ""
USERNAME = "" # Put your GitHub username inside the quotes
PASSWORD = "" # Put your GitHub password inside the quotes
PASSWORD = "" # Put your GitHub password inside the quotes
ORG = "" # Put your organization (or username if you have no org) name here
REPO = "" # Put the repository name here
# Want to only get a single milestone? Put the milestone name in here:
Expand All @@ -60,11 +61,11 @@

# Your local timezone offset to convert times
TIMEZONE_OFFSET="-4"

client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)

csv = CSV.new(File.open(File.dirname(__FILE__) + "/" + OUTPUT_FILE + ".csv", 'w'))

puts "Initialising CSV file..."
#CSV Headers
header = [
Expand All @@ -81,7 +82,7 @@
]

csv << header

puts "Getting issues from Github..."
temp_issues = []
issues = []
Expand All @@ -98,29 +99,29 @@
temp_issues = client.list_issues("#{ORG}/#{REPO}", :state => "open", :page => page)
issues = issues + temp_issues;
end while not temp_issues.empty?

puts "Processing #{issues.size} issues..."
issues.each do |issue|

labels = ""
label = issue['labels'] || "None"
if (label != "None")
label.each do |item|
labels += item['name'] + " "
end
labels += item['name'] + " "
end
end

assignee = ""
assignee = issue['assignee'] || "None"
if (assignee != "None")
assignee = assignee['login']
end
end

milestone = issue['milestone'] || "None"
if (milestone != "None")
milestone = milestone['title']
end

if ((TARGET_MILESTONE == "") || (milestone == TARGET_MILESTONE))
# Needs to match the header order above, date format are based on Jira default
row = [
Expand Down