starter 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,10 @@ module Starter
16
16
 
17
17
  def confirm(string)
18
18
  print "#{string} [y/N] "
19
- true if STDIN.gets.chomp =~ /^y/i
19
+ if STDIN.gets.chomp =~ /^y/i
20
+ yield if block_given?
21
+ return true
22
+ end
20
23
  end
21
24
 
22
25
  end
@@ -4,41 +4,62 @@ desc "Create an issue on GitHub"
4
4
  task "github:issue" => "github_repo" do
5
5
 
6
6
  repo = $STARTER[:github_repo]
7
- options = {}
8
- $stdout.print "Title: "; $stdout.flush
9
- options[:title] = $stdin.readline.strip
10
- $stdout.print "Description: "; $stdout.flush
11
- options[:description] = $stdin.readline.strip
12
7
  labels = repo.labels.map { |label| label["name"] }.join(" ")
13
- $stdout.print "Labels (separate with spaces: [#{labels}]): "; $stdout.flush
14
- options[:labels] = $stdin.readline.strip.split(" ")
15
- $stdout.puts "Milestone:"
16
- repo.milestones.each do |milestone|
17
- $stdout.puts "#{milestone['number']} - #{milestone['title']}"
18
- end
19
- milestone = $stdin.readline.strip
20
- options[:milestone] = milestone unless milestone.empty?
21
-
22
- print "Issue details: "
23
- if Starter::Prompt.confirm("Create this issue?")
24
- result = repo.issues.create(options)
25
- if result["errors"]
26
- result["errors"].each do |error|
27
- $stderr.puts "#{error['resource']}: #{error['message']}"
8
+ milestones = repo.milestones
9
+
10
+ loop do
11
+ options = {}
12
+ $stdout.print "Title: "; $stdout.flush
13
+ options[:title] = $stdin.readline.strip
14
+ $stdout.print "Description: "; $stdout.flush
15
+ options[:body] = $stdin.readline.strip
16
+ $stdout.print "Labels (separate with spaces: [#{labels}]): "; $stdout.flush
17
+ options[:labels] = $stdin.readline.strip.split(" ")
18
+ if milestones.size > 0
19
+ $stdout.puts "Milestone:"
20
+ repo.milestones.each do |milestone|
21
+ $stdout.puts "#{milestone['number']} - #{milestone['title']}"
22
+ end
23
+ milestone = $stdin.readline.strip
24
+ options[:milestone] = milestone unless milestone.empty?
25
+ end
26
+
27
+ print "Issue details: "
28
+ Starter::Prompt.confirm("Create this issue?") do
29
+ result = repo.issues.create(options)
30
+ if result["errors"]
31
+ result["errors"].each do |error|
32
+ $stderr.puts "#{error['resource']}: #{error['message']}"
33
+ end
34
+ exit
35
+ elsif result["message"]
36
+ $stderr.puts "Problem creating issue:", result["message"]
37
+ exit
38
+ else
39
+ $stdout.puts "Issue ##{result['number']} created."
28
40
  end
29
- else
30
- $stdout.puts "Issue ##{result['number']} created."
31
41
  end
42
+
43
+ break unless Starter::Prompt.confirm("Create another?")
44
+
45
+ end
46
+ end
47
+
48
+ task "github:issues" => "github_repo" do
49
+ repo = $STARTER[:github_repo]
50
+ repo.issues.each do |issue|
51
+ line = "#%-6i %s" % issue.values_at(*%w[ number title ])
52
+ puts line
32
53
  end
33
54
  end
34
55
 
35
56
 
36
- task "github_repo" => %w[ github_settings github_password ] do
57
+ task "github_repo" => %w[ github_settings github_auth ] do
37
58
  require 'ghee'
38
59
 
39
60
  settings = $STARTER[:settings][:github]
40
- user, password, repo = settings.values_at(:user, :password, :repo)
41
- ghee = Ghee.basic_auth(user,password)
61
+ repo = settings[:repo]
62
+ ghee = Ghee.access_token(settings[:auth])
42
63
 
43
64
  repo = ghee.repos(repo[:owner], repo[:name])
44
65
  if repo["message"]
@@ -50,24 +71,37 @@ task "github_repo" => %w[ github_settings github_password ] do
50
71
 
51
72
  end
52
73
 
53
-
54
- task "github_password" => "github_settings" do
74
+ task "github_auth" => %w[ github_settings .starter ] do
55
75
  require "starter/password"
56
- if $STARTER[:settings][:github][:password] == nil
76
+ require 'ghee'
77
+ settings = $STARTER[:settings][:github]
78
+ if File.exists?(".starter/gh_auth") && auth = File.read(".starter/gh_auth")
79
+ settings[:auth] = auth.chomp
80
+ else
57
81
  password = Starter::Password.request("GitHub")
58
- $STARTER[:settings][:github][:password] = password
82
+ user = $STARTER[:settings][:github][:user]
83
+ auth = Ghee.create_token(user, password, ["user", "repo"])
84
+ if auth
85
+ settings[:auth] = auth
86
+ Starter::Prompt.confirm("Write auth token to .starter?") do
87
+ File.open(".starter/gh_auth", "w") { |f| f.print(auth) }
88
+ end
89
+ else
90
+ puts "Authentication failure"
91
+ exit
92
+ end
59
93
  end
60
94
  end
61
95
 
62
96
 
63
- task "read_settings" do
97
+ task "read_settings" => ".starter" do
64
98
  require "yaml"
65
99
  begin
66
- $STARTER[:settings] = YAML.load_file("settings.yml")
100
+ $STARTER[:settings] = YAML.load_file(".starter/settings.yml")
67
101
  rescue Errno::ENOENT
68
- $stderr.puts "You do not appear to have a settings.yml file."
102
+ $stderr.puts "You do not appear to have a .starter/settings.yml file."
69
103
  if Starter::Prompt.confirm("Create a stubbed settings file?")
70
- File.open("settings.yml", "w") do |f|
104
+ File.open(".starter/settings.yml", "w") do |f|
71
105
  settings = {
72
106
  :github => {
73
107
  :user => "YOURUSERNAME",
@@ -75,7 +109,7 @@ task "read_settings" do
75
109
  }
76
110
  }
77
111
  YAML.dump(settings, f)
78
- puts "Created settings.yml. Now go edit it and add it to .gitignore."
112
+ puts "Created .starter/settings.yml. Now go edit it."
79
113
  end
80
114
  end
81
115
  exit
@@ -85,7 +119,7 @@ end
85
119
 
86
120
  task "github_settings" => "read_settings" do
87
121
  if $STARTER[:settings][:github] == nil
88
- $stderr.puts "Looks like your settings.yml file isn't set up with a github stanza."
122
+ $stderr.puts "Looks like your .starter/settings.yml file isn't set up with a github stanza."
89
123
  exit
90
124
  end
91
125
  end
@@ -18,6 +18,11 @@ task "build"
18
18
  desc "Release the dogs that shoot bees from their mouths"
19
19
  task "release" => %w[ build ]
20
20
 
21
+ directory ".starter"
22
+
23
+ task ".starter" do
24
+ gitignore(".starter")
25
+ end
21
26
 
22
27
  task "determine_author" => %w[ read_git_config ] do
23
28
  if author = $STARTER[:git].config["user.name"]
@@ -42,4 +47,11 @@ def confirm_command(command)
42
47
  end
43
48
  end
44
49
 
50
+ def gitignore(string)
51
+ Starter::Prompt.confirm "Append #{string} to your .gitignore?" do
52
+ File.open(".gitignore", "a") do |f|
53
+ f.puts(string)
54
+ end
55
+ end
56
+ end
45
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: