Class: TodosExport::GithubIssues
- Inherits:
-
Object
- Object
- TodosExport::GithubIssues
- Defined in:
- lib/todos_export/github_issues.rb
Instance Attribute Summary collapse
-
#main ⇒ Object
Returns the value of attribute main.
-
#remote_repo ⇒ Object
Returns the value of attribute remote_repo.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #github_line_url(file, line) ⇒ Object
-
#initialize(main) ⇒ GithubIssues
constructor
A new instance of GithubIssues.
- #process_exportables ⇒ Object
- #run ⇒ Object
- #select_repo ⇒ Object
Constructor Details
#initialize(main) ⇒ GithubIssues
Returns a new instance of GithubIssues.
5 6 7 |
# File 'lib/todos_export/github_issues.rb', line 5 def initialize(main) @main = main end |
Instance Attribute Details
#main ⇒ Object
Returns the value of attribute main.
3 4 5 |
# File 'lib/todos_export/github_issues.rb', line 3 def main @main end |
#remote_repo ⇒ Object
Returns the value of attribute remote_repo.
3 4 5 |
# File 'lib/todos_export/github_issues.rb', line 3 def remote_repo @remote_repo end |
Instance Method Details
#authenticate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/todos_export/github_issues.rb', line 15 def authenticate say("\n") choose do || .prompt = "Choose authentication method: " .choice('Username / Password') do say("\n") username = ask("Github Username:") password = ask("Github Password:") { |q| q.echo = false } @client = ::Octokit::Client.new(:login => username, :password => password) end .choice('Personal Access Token (https://github.com/settings/applications)') do say("\n") token = ask("Github token:") @client = ::Octokit::Client.new(:oauth_token => token) end end end |
#github_line_url(file, line) ⇒ Object
52 53 54 55 |
# File 'lib/todos_export/github_issues.rb', line 52 def github_line_url(file, line) sha = self.main.git_head_sha || 'master' "https://github.com/#{@remote_repo}/blob/#{sha}/#{file}#L#{line}" end |
#process_exportables ⇒ Object
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 |
# File 'lib/todos_export/github_issues.rb', line 57 def process_exportables say("\n") self.main.exportables.each do |ex| say("Create a new Issue") say("==================") say("<%= color('Name:', :green) %>\n#{ex[:content]}") say("<%= color('Description:', :green) %>\n#{ex[:content]}\n\n#{self.github_line_url(ex[:file], ex[:line])}") say("<%= color('Tags:', :green) %>\n'#{ex[:type].downcase}'") say("\n") create = agree("Create this issue? [y]es, [n]o") if create && @client.create_issue(@remote_repo, ex[:content], "#{ex[:content]}\n\n#{self.github_line_url(ex[:file], ex[:line])}", { :labels => ex[:type].downcase } ) say("\n<%= color('Created!', :green) %>\n\n") say("Delete the comment and save the file?" \ "\n\nFile: #{ex[:file]}" \ "\nLine: #{ex[:line]}" \ "\nComment: #{ex[:original_content]}\n\n") delete = agree("[y]es, [n]") if delete self.main.delete_exportable(ex[:file], ex[:line]) say("\n<%= color('Deleted the line', :green) %>\n\n") end else say("\n<%= color('Not created!', :red) %>\n\n") end end end |
#run ⇒ Object
9 10 11 12 13 |
# File 'lib/todos_export/github_issues.rb', line 9 def run authenticate select_repo process_exportables end |
#select_repo ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/todos_export/github_issues.rb', line 35 def select_repo say("\n") choose do || .prompt = "Choose a repository to add issues to:" @client.repos.each do |repo| .choice(repo.full_name) { @remote_repo = repo.full_name } end @client.organizations.each do |org| @client.org_repos(org['login']).each do |repo| .choice(repo.full_name) { @remote_repo = repo.full_name } end end end end |