idonethis-cli 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +11 -11
- data/.travis.yml +4 -4
- data/Gemfile +3 -3
- data/LICENSE.txt +21 -21
- data/README.md +99 -99
- data/Rakefile +7 -7
- data/bin/console +14 -14
- data/bin/idonethis +13 -13
- data/bin/setup +7 -7
- data/idonethis-cli.gemspec +36 -35
- data/lib/adapters/cli.rb +92 -87
- data/lib/adapters/git_adapter.rb +18 -0
- data/lib/adapters/internet.rb +14 -14
- data/lib/adapters/io/directory_info.rb +33 -0
- data/lib/adapters/settings.rb +19 -19
- data/lib/adapters/views/cli.rb +36 -36
- data/lib/idonethis.rb +10 -10
- data/lib/idonethis/cli/version.rb +5 -5
- data/lib/idonethis/index.rb +26 -26
- data/lib/idonethis/settings_file.rb +11 -11
- data/lib/idonethis/use_cases/config.rb +40 -40
- data/lib/idonethis/use_cases/git.rb +48 -74
- data/lib/idonethis/use_cases/list.rb +65 -65
- data/lib/idonethis/use_cases/new.rb +28 -28
- data/lib/idonethis/use_cases/teams.rb +49 -49
- metadata +32 -16
@@ -1,11 +1,11 @@
|
|
1
|
-
module Idonethis
|
2
|
-
class SettingsFile
|
3
|
-
class << self
|
4
|
-
def exists?; File.exists?(path); end
|
5
|
-
|
6
|
-
def path
|
7
|
-
@@path ||= File.expand_path("~/.idonethis.settings")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module Idonethis
|
2
|
+
class SettingsFile
|
3
|
+
class << self
|
4
|
+
def exists?; File.exists?(path); end
|
5
|
+
|
6
|
+
def path
|
7
|
+
@@path ||= File.expand_path("~/.idonethis.settings")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
module Idonethis::UseCases
|
2
|
-
module Config
|
3
|
-
class << self
|
4
|
-
def apply(_, args={})
|
5
|
-
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
-
|
7
|
-
log.call "args: #{args}"
|
8
|
-
|
9
|
-
require 'yaml'
|
10
|
-
|
11
|
-
settings = File.exists?(filename) ? YAML.load_file(filename) : {}
|
12
|
-
|
13
|
-
token = (args[:opts].map{|it| it.match /user.token=(.+)/}.compact || []).first
|
14
|
-
|
15
|
-
if token
|
16
|
-
File.open filename, "w+" do |f|
|
17
|
-
f.puts(settings.merge({token: token[1]}).to_yaml)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
team = (args[:opts].map{|it| it.match /user.team=(.+)/}.compact || []).first
|
22
|
-
|
23
|
-
if team
|
24
|
-
File.open filename, "w+" do |f|
|
25
|
-
f.puts(settings.merge({team: team[1]}).to_yaml)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
puts "Settings saved to <#{filename}>"
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def filename
|
35
|
-
require 'settings_file'
|
36
|
-
Idonethis::SettingsFile.path
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
1
|
+
module Idonethis::UseCases
|
2
|
+
module Config
|
3
|
+
class << self
|
4
|
+
def apply(_, args={})
|
5
|
+
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
+
|
7
|
+
log.call "args: #{args}"
|
8
|
+
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
settings = File.exists?(filename) ? YAML.load_file(filename) : {}
|
12
|
+
|
13
|
+
token = (args[:opts].map{|it| it.match /user.token=(.+)/}.compact || []).first
|
14
|
+
|
15
|
+
if token
|
16
|
+
File.open filename, "w+" do |f|
|
17
|
+
f.puts(settings.merge({token: token[1]}).to_yaml)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
team = (args[:opts].map{|it| it.match /user.team=(.+)/}.compact || []).first
|
22
|
+
|
23
|
+
if team
|
24
|
+
File.open filename, "w+" do |f|
|
25
|
+
f.puts(settings.merge({team: team[1]}).to_yaml)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
puts "Settings saved to <#{filename}>"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def filename
|
35
|
+
require 'settings_file'
|
36
|
+
Idonethis::SettingsFile.path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,74 +1,48 @@
|
|
1
|
-
module Idonethis::UseCases
|
2
|
-
module Git
|
3
|
-
class << self
|
4
|
-
def apply(
|
5
|
-
log
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def summarise(*dirs)
|
32
|
-
dirs.
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
any_file_changed_today?(dir, time, now, log).tap do |result|
|
50
|
-
log.call "[#{dir}] Comparing mtime <#{time}> to today <#{now}>. Today? <#{result}>"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def any_file_changed_today?(dir, time, now, log)
|
55
|
-
Dir["#{dir}/**/**"].select do |file|
|
56
|
-
mtime = File.ctime(file)
|
57
|
-
log.call "File <#{file}> has mtime <#{mtime}>"
|
58
|
-
return true if today?(mtime, now)
|
59
|
-
end
|
60
|
-
return false
|
61
|
-
end
|
62
|
-
|
63
|
-
def today?(time, now)
|
64
|
-
time.year == now.year && time.month == now.month && time.day == now.day
|
65
|
-
end
|
66
|
-
|
67
|
-
def commit_summary(dir)
|
68
|
-
require 'git'
|
69
|
-
git = ::Git.open(dir)
|
70
|
-
git.log.since('1am').map{|it| %Q{[#{it.date.strftime("%H:%M")}] #{it.message}}}
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
module Idonethis::UseCases
|
2
|
+
module Git
|
3
|
+
class << self
|
4
|
+
def apply(_, args={})
|
5
|
+
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
+
git = args[:git] || fail("You need to supply :git adapter")
|
7
|
+
view = args[:view] || fail("You need to supply :view adapter")
|
8
|
+
fs = args[:fs] || fail("You need to supply :fs adapter")
|
9
|
+
since = args[:since] || 'today'
|
10
|
+
|
11
|
+
log.call args
|
12
|
+
|
13
|
+
opts = args[:opts] || []
|
14
|
+
|
15
|
+
dir = opts.any? ? File.expand_path(opts.first) : File.expand_path(".")
|
16
|
+
|
17
|
+
dirs = dir
|
18
|
+
|
19
|
+
if dir == FileUtils.pwd
|
20
|
+
view.call "Scanning the current directory <#{dir}>\n\n"
|
21
|
+
else
|
22
|
+
dirs = fs.modified_today?(dir)
|
23
|
+
|
24
|
+
view.call "Scanning dir <#{dir}>, which has <#{dirs_that_have_changed_today.size}> repositories that have changed today\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
view.call summarise(git, view, since, *dirs)
|
28
|
+
view.call ""
|
29
|
+
end
|
30
|
+
|
31
|
+
def summarise(git, view, since, *dirs)
|
32
|
+
dirs.map do |dir|
|
33
|
+
commits = git.commits(dir, since).map{|it| %Q{[#{date_from(it)}] #{it.message}}}
|
34
|
+
%Q{#{Pathname.new(dir).basename} (#{commits.size}):\n\n-- #{commits.join("\n-- ")}}
|
35
|
+
end.join "\n\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def date_from(commit)
|
39
|
+
return commit.date.strftime("%d %b, %H:%M") unless today?(commit.date, Time.now)
|
40
|
+
commit.date.strftime("%H:%M")
|
41
|
+
end
|
42
|
+
|
43
|
+
def today?(time, now)
|
44
|
+
time.year == now.year && time.month == now.month && time.day == now.day
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
module Idonethis::UseCases
|
2
|
-
module List
|
3
|
-
class << self
|
4
|
-
def apply(credential, args={})
|
5
|
-
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
-
view = args[:view] || fail("You need to supply :view adapter")
|
7
|
-
|
8
|
-
list = get(credential, log, args).tap{|result| log.call(result)}
|
9
|
-
|
10
|
-
view.call list
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def get(credential, log, args)
|
16
|
-
result = []
|
17
|
-
page = 1
|
18
|
-
|
19
|
-
loop do
|
20
|
-
reply = get_page(page, credential, log, args)
|
21
|
-
|
22
|
-
result += reply["results"]
|
23
|
-
|
24
|
-
page += 1
|
25
|
-
|
26
|
-
break if reply["next"].nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
result
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_page(page, credential, log, args) # https://idonethis.com/api/v0.1/dones/
|
33
|
-
params = {"order_by" => "-created", "page_size" => 100, "page" => page}.
|
34
|
-
merge(done_date_from(args)).
|
35
|
-
merge({team: (args[:team] || credential[:team])})
|
36
|
-
|
37
|
-
url = Idonethis::Index.dones(params)
|
38
|
-
|
39
|
-
log.call "url: #{url}"
|
40
|
-
|
41
|
-
internet = args[:internet] || fail("You need to supply :internet adapter")
|
42
|
-
|
43
|
-
parse internet.get(url, { "Authorization" => "Token #{credential[:token]}", accept: "application/json"})
|
44
|
-
end
|
45
|
-
|
46
|
-
def done_date_from(args)
|
47
|
-
opts = args[:opts] || []
|
48
|
-
|
49
|
-
if opts.include?("week")
|
50
|
-
return { done_date_after: (Time.now - (7*24*60*60)).strftime("%F") }
|
51
|
-
end
|
52
|
-
|
53
|
-
intersection = opts & %W{ today yesterday }
|
54
|
-
|
55
|
-
return intersection.empty? ? { done_date: 'today' } : { done_date: intersection.first }
|
56
|
-
end
|
57
|
-
|
58
|
-
def parse(reply)
|
59
|
-
require 'json'
|
60
|
-
|
61
|
-
JSON.parse(reply.body)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
module Idonethis::UseCases
|
2
|
+
module List
|
3
|
+
class << self
|
4
|
+
def apply(credential, args={})
|
5
|
+
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
+
view = args[:view] || fail("You need to supply :view adapter")
|
7
|
+
|
8
|
+
list = get(credential, log, args).tap{|result| log.call(result)}
|
9
|
+
|
10
|
+
view.call list
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get(credential, log, args)
|
16
|
+
result = []
|
17
|
+
page = 1
|
18
|
+
|
19
|
+
loop do
|
20
|
+
reply = get_page(page, credential, log, args)
|
21
|
+
|
22
|
+
result += reply["results"]
|
23
|
+
|
24
|
+
page += 1
|
25
|
+
|
26
|
+
break if reply["next"].nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_page(page, credential, log, args) # https://idonethis.com/api/v0.1/dones/
|
33
|
+
params = {"order_by" => "-created", "page_size" => 100, "page" => page}.
|
34
|
+
merge(done_date_from(args)).
|
35
|
+
merge({team: (args[:team] || credential[:team])})
|
36
|
+
|
37
|
+
url = Idonethis::Index.dones(params)
|
38
|
+
|
39
|
+
log.call "url: #{url}"
|
40
|
+
|
41
|
+
internet = args[:internet] || fail("You need to supply :internet adapter")
|
42
|
+
|
43
|
+
parse internet.get(url, { "Authorization" => "Token #{credential[:token]}", accept: "application/json"})
|
44
|
+
end
|
45
|
+
|
46
|
+
def done_date_from(args)
|
47
|
+
opts = args[:opts] || []
|
48
|
+
|
49
|
+
if opts.include?("week")
|
50
|
+
return { done_date_after: (Time.now - (7*24*60*60)).strftime("%F") }
|
51
|
+
end
|
52
|
+
|
53
|
+
intersection = opts & %W{ today yesterday }
|
54
|
+
|
55
|
+
return intersection.empty? ? { done_date: 'today' } : { done_date: intersection.first }
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse(reply)
|
59
|
+
require 'json'
|
60
|
+
|
61
|
+
JSON.parse(reply.body)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
module Idonethis::UseCases
|
2
|
-
module New
|
3
|
-
class << self
|
4
|
-
def apply(credential, args={})
|
5
|
-
log = args[:log] || fail("You need to supply :internet adapter")
|
6
|
-
internet = args[:internet] || fail("You need to supply :internet adapter")
|
7
|
-
team = args[:team]
|
8
|
-
|
9
|
-
log.call "args: #{args}"
|
10
|
-
log.call "overriding team <#{credential[:team]}> with <#{team}>"
|
11
|
-
|
12
|
-
parse internet.post(
|
13
|
-
Idonethis::Index.dones,
|
14
|
-
{ "Authorization" => "Token #{credential[:token]}", accept: "application/json"},
|
15
|
-
{
|
16
|
-
"raw_text" => args[:message],
|
17
|
-
"team" => (team || credential[:team])})
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def parse(reply)
|
23
|
-
require 'json'
|
24
|
-
|
25
|
-
JSON.parse(reply.body)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Idonethis::UseCases
|
2
|
+
module New
|
3
|
+
class << self
|
4
|
+
def apply(credential, args={})
|
5
|
+
log = args[:log] || fail("You need to supply :internet adapter")
|
6
|
+
internet = args[:internet] || fail("You need to supply :internet adapter")
|
7
|
+
team = args[:team]
|
8
|
+
|
9
|
+
log.call "args: #{args}"
|
10
|
+
log.call "overriding team <#{credential[:team]}> with <#{team}>"
|
11
|
+
|
12
|
+
parse internet.post(
|
13
|
+
Idonethis::Index.dones,
|
14
|
+
{ "Authorization" => "Token #{credential[:token]}", accept: "application/json"},
|
15
|
+
{
|
16
|
+
"raw_text" => args[:message],
|
17
|
+
"team" => (team || credential[:team])})
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parse(reply)
|
23
|
+
require 'json'
|
24
|
+
|
25
|
+
JSON.parse(reply.body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
29
|
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
module Idonethis::UseCases
|
2
|
-
module Teams
|
3
|
-
class << self
|
4
|
-
def apply(credential, args={})
|
5
|
-
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
-
view = args[:view] || fail("You need to supply :view adapter")
|
7
|
-
|
8
|
-
list = get(credential, log, args).tap{|result| log.call(result)}
|
9
|
-
|
10
|
-
view.call list
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def get(credential, log, args)
|
16
|
-
result = []
|
17
|
-
page = 1
|
18
|
-
|
19
|
-
loop do
|
20
|
-
reply = get_page(page, credential, log, args)
|
21
|
-
|
22
|
-
result += reply["results"]
|
23
|
-
|
24
|
-
page += 1
|
25
|
-
|
26
|
-
break if reply["next"].nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
result
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_page(page, credential, log, args) # https://idonethis.com/api/v0.1/teams/
|
33
|
-
url = Idonethis::Index.teams
|
34
|
-
|
35
|
-
log.call "url: #{url}"
|
36
|
-
|
37
|
-
internet = args[:internet] || fail("You need to supply :internet adapter")
|
38
|
-
|
39
|
-
parse internet.get(url, { "Authorization" => "Token #{credential[:token]}", accept: "application/json"})
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse(reply)
|
43
|
-
require 'json'
|
44
|
-
|
45
|
-
JSON.parse(reply.body)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
module Idonethis::UseCases
|
2
|
+
module Teams
|
3
|
+
class << self
|
4
|
+
def apply(credential, args={})
|
5
|
+
log = args[:log] || fail("You need to supply :log adapter")
|
6
|
+
view = args[:view] || fail("You need to supply :view adapter")
|
7
|
+
|
8
|
+
list = get(credential, log, args).tap{|result| log.call(result)}
|
9
|
+
|
10
|
+
view.call list
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get(credential, log, args)
|
16
|
+
result = []
|
17
|
+
page = 1
|
18
|
+
|
19
|
+
loop do
|
20
|
+
reply = get_page(page, credential, log, args)
|
21
|
+
|
22
|
+
result += reply["results"]
|
23
|
+
|
24
|
+
page += 1
|
25
|
+
|
26
|
+
break if reply["next"].nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_page(page, credential, log, args) # https://idonethis.com/api/v0.1/teams/
|
33
|
+
url = Idonethis::Index.teams
|
34
|
+
|
35
|
+
log.call "url: #{url}"
|
36
|
+
|
37
|
+
internet = args[:internet] || fail("You need to supply :internet adapter")
|
38
|
+
|
39
|
+
parse internet.get(url, { "Authorization" => "Token #{credential[:token]}", accept: "application/json"})
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse(reply)
|
43
|
+
require 'json'
|
44
|
+
|
45
|
+
JSON.parse(reply.body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|