Class: TodosExport::GithubIssues

Inherits:
Object
  • Object
show all
Defined in:
lib/todos_export/github_issues.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#mainObject

Returns the value of attribute main.



3
4
5
# File 'lib/todos_export/github_issues.rb', line 3

def main
  @main
end

#remote_repoObject

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

#authenticateObject



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 |menu|
    menu.prompt = "Choose authentication method: "

    menu.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
    menu.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



46
47
48
49
# File 'lib/todos_export/github_issues.rb', line 46

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_exportablesObject



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
# File 'lib/todos_export/github_issues.rb', line 51

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

#runObject



9
10
11
12
13
# File 'lib/todos_export/github_issues.rb', line 9

def run
  authenticate
  select_repo
  process_exportables
end

#select_repoObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/todos_export/github_issues.rb', line 35

def select_repo
  say("\n")
  choose do |menu|
    menu.prompt = "Choose a repository to add issues to:"

    @client.repos.each do |repo|
      menu.choice(repo.full_name) { @remote_repo = repo.full_name }
    end
  end
end