idonethis-cli 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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(credential, args={})
5
- log = args[:log] || fail("You need to supply :log adapter")
6
-
7
- log.call args
8
-
9
- opts = args[:opts]
10
-
11
- dir = opts.any? ? File.expand_path(opts.first) : File.expand_path(".")
12
-
13
- if opts.any?
14
- all_dirs = directories_in(dir)
15
-
16
- log.call("All directories in <#{dir}>: #{all_dirs}")
17
-
18
- dirs_that_have_changed_today = all_dirs.select{|it| modified_today?(it, log) }
19
-
20
- puts "Scanning dir <#{dir}>, which has <#{dirs_that_have_changed_today.size}> repositories that have changed today\n\n"
21
-
22
- summarise *dirs_that_have_changed_today
23
-
24
- puts ""
25
- else
26
- puts "Scanning the current directory <#{dir}>\n\n"
27
- summarise dir
28
- end
29
- end
30
-
31
- def summarise(*dirs)
32
- dirs.each do |dir|
33
- summary = commit_summary(dir)
34
- puts %Q{#{Pathname.new(dir).basename} (#{summary.size}):\n-- #{summary.join("\n-- ")}}
35
- end
36
- end
37
-
38
- def directories_in(dir)
39
- Dir.entries(dir).
40
- reject{|it| ["..", "."].include?(it) }.
41
- select{|it| File.directory?(File.join(dir, it))}.
42
- map{ |it| File.expand_path(File.join(dir, it))}
43
- end
44
-
45
- def modified_today?(dir, log)
46
- time = File.ctime(dir)
47
- now = Time.now
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