checkoff 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fa7ac9629b6bf129771e5c5d7f9cdf0a19fcdfa
4
- data.tar.gz: 7508f757fd87b77d57759bd94a9dd088dbd11668
3
+ metadata.gz: fb140b2c3cd6899f6244d46a8b8c979ff84156c4
4
+ data.tar.gz: 27fe46e1995216eb5e7a663e64baffc4528732a3
5
5
  SHA512:
6
- metadata.gz: 743208cf0f350833f60134480c9ae88ffc59cedb646a43e1edb961594023577354a7691590563c9b5b5b69f39ecc7a2ac7d33f152b4552be1513c5a6ace573b3
7
- data.tar.gz: 577fe3cfb99e59890367501d946cf66d7bf3d8c12694af9d0d860a6a0a0ada80dd93d3c44666ee1b23abb0c7f51746d20b88a389b481d69c8de8641295ab96cc
6
+ metadata.gz: 7296099b7f92d602263ffbff3f29365ece01b4915b5dcdbf8526dce9e2381c478e96b695443f57ef543a578f6c74550eb1470e855893abb2cc964171836fc704
7
+ data.tar.gz: ecabaf1af01734d7b5cfe4407fa35c80e2b0e1fddd15eecb31a87ab35a4c894e310166546cdadf06ec33505b0c356971b1c49a714c20aaca48f8750796d949a1
data/.rubocop.yml CHANGED
@@ -17,6 +17,9 @@ ParameterLists:
17
17
  TrivialAccessors:
18
18
  ExactNameMatch: true
19
19
 
20
+ Layout/MultilineMethodCallIndentation:
21
+ EnforcedStyle: indented
22
+
20
23
  #
21
24
  # Add 'XXX' to the standard list
22
25
  #
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in checkoff.gemspec
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
3
4
 
4
5
  Dir['lib/tasks/**/*.rake'].each { |t| load t }
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "checkoff"
4
+ require 'bundler/setup'
5
+ require 'checkoff'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "checkoff"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
data/checkoff.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # coding: ascii
3
+
3
4
  lib = File.expand_path('../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require 'checkoff/version'
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 98.66
3
+ "covered_percent": 98.78
4
4
  }
5
5
  }
data/exe/checkoff CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'checkoff/cli'
4
5
 
data/lib/checkoff/cli.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # frozen_string_literal: true
4
+
4
5
  require 'ostruct'
5
6
  require 'dalli'
6
7
  require 'cache_method'
8
+ require_relative 'workspaces'
7
9
  require_relative 'projects'
8
10
  require_relative 'tasks'
9
11
  require_relative 'sections'
@@ -13,12 +15,16 @@ module Checkoff
13
15
  class CLI
14
16
  attr_reader :sections, :stderr
15
17
 
16
- def initialize(projects: Checkoff::Projects.new,
18
+ def initialize(workspaces: Checkoff::Workspaces.new,
19
+ projects: Checkoff::Projects.new,
17
20
  sections: Checkoff::Sections.new(projects: projects),
21
+ tasks: Checkoff::Tasks.new,
18
22
  stderr: STDERR,
19
23
  kernel: Kernel)
24
+ @workspaces = workspaces
20
25
  @projects = projects
21
26
  @sections = sections
27
+ @tasks = tasks
22
28
  @kernel = kernel
23
29
  @stderr = stderr
24
30
  end
@@ -54,26 +60,37 @@ module Checkoff
54
60
  tasks_to_hash(tasks).to_json
55
61
  end
56
62
 
57
- def quickadd(task_name)
58
- @projects.add_task(task_name)
63
+ def quickadd(workspace_name, task_name)
64
+ workspace = @workspaces.workspace_by_name(workspace_name)
65
+ @tasks.add_task(task_name,
66
+ workspace_id: workspace.id)
59
67
  end
60
68
 
61
69
  def validate_args!(args)
62
- return unless args.length < 2 || !%w(view quickadd).include?(args[0])
70
+ return unless args.length < 2 || !%w[view quickadd].include?(args[0])
63
71
 
64
72
  output_help
65
73
  exit(1)
66
74
  end
67
75
 
76
+ def parse_view_args(subargs, args)
77
+ subargs.workspace = args[1]
78
+ subargs.project = args[2]
79
+ subargs.section = args[3]
80
+ end
81
+
82
+ def parse_quickadd_args(subargs, args)
83
+ subargs.workspace = args[1]
84
+ subargs.task_name = args[2]
85
+ end
86
+
68
87
  def parse_args(args)
69
- validate_args!(args)
70
88
  mode = args[0]
71
89
  subargs = OpenStruct.new
72
90
  if mode == 'view'
73
- subargs.workspace = args[1]
74
- subargs.project = args[2]
91
+ parse_view_args(subargs, args)
75
92
  elsif mode == 'quickadd'
76
- subargs.task_name = args[1]
93
+ parse_quickadd_args(subargs, args)
77
94
  else
78
95
  raise
79
96
  end
@@ -83,24 +100,28 @@ module Checkoff
83
100
  def output_help
84
101
  stderr.puts 'View tasks:'
85
102
  stderr.puts " #{$PROGRAM_NAME} view workspace project [section]"
86
- stderr.puts " #{$PROGRAM_NAME} quickadd task_name"
103
+ stderr.puts " #{$PROGRAM_NAME} quickadd workspace task_name"
87
104
  stderr.puts
88
105
  stderr.puts "'project' can be set to a project name, or :my_tasks, " \
89
106
  ':my_tasks_upcoming, :my_tasks_new, or :my_tasks_today'
90
107
  end
91
108
 
109
+ def view(workspace_name, project_name, section_name)
110
+ project_name = project_name[1..-1].to_sym if project_name.start_with? ':'
111
+ if section_name.nil?
112
+ run_on_project(workspace_name, project_name)
113
+ else
114
+ run_on_section(workspace_name, project_name, section_name)
115
+ end
116
+ end
117
+
92
118
  def run(args)
119
+ validate_args!(args)
93
120
  command, subargs = parse_args(args)
94
121
  if command == 'view'
95
- project = subargs.project
96
- project = project[1..-1].to_sym if project.start_with? ':'
97
- if section.nil?
98
- run_on_project(subargs.workspace, project)
99
- else
100
- run_on_section(subargs.workspace, project, subargs.section)
101
- end
122
+ view(subargs.workspace, subargs.project, subargs.section)
102
123
  elsif command == 'quickadd'
103
- quickadd(subargs.task_name)
124
+ quickadd(subargs.workspace, subargs.task_name)
104
125
  else
105
126
  raise
106
127
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'yaml'
3
4
  require 'active_support/core_ext/hash'
4
5
 
@@ -9,7 +10,7 @@ module Checkoff
9
10
  def self.load(sym)
10
11
  file = "#{sym}.yml"
11
12
  YAML.load_file(File.expand_path("~/.#{file}"))
12
- .with_indifferent_access
13
+ .with_indifferent_access
13
14
  end
14
15
  end
15
16
  end
@@ -24,15 +24,15 @@ module Checkoff
24
24
  # XXX: Move low-level functions private
25
25
 
26
26
  def initialize(config: Checkoff::ConfigLoader.load(:asana),
27
- asana_client: Asana::Client)
27
+ asana_client: Asana::Client,
28
+ workspaces: Checkoff::Workspaces.new)
28
29
  @config = config
29
30
  @asana_client = asana_client
31
+ @workspaces = workspaces
30
32
  end
31
33
 
32
34
  def client
33
- @client ||= @asana_client.new do |c|
34
- c.authentication :access_token, @config[:personal_access_token]
35
- end
35
+ @workspaces.client
36
36
  end
37
37
 
38
38
  def projects
@@ -40,37 +40,8 @@ module Checkoff
40
40
  end
41
41
  cache_method :projects, LONG_CACHE_TIME
42
42
 
43
- def add_task(name,
44
- workspace_id: default_workspace_id,
45
- assignee_id: default_assignee_id)
46
- Asana::Resources::Task.create(client,
47
- assignee: assignee_id,
48
- workspace: workspace_id, name: name)
49
- end
50
-
51
- def default_workspace_id
52
- @config[:default_workspace_id]
53
- end
54
-
55
- def default_assignee_id
56
- @config[:default_assignee_id]
57
- end
58
-
59
- def user_by_name(name, workspace_id: raise)
60
- client.users.find_all(workspace: workspace_id).find do |user|
61
- print(user)
62
- user.name == name
63
- end || raise("Could not find user #{email}")
64
- end
65
-
66
- def workspace_by_name(workspace_name)
67
- client.workspaces.find_all.find do |workspace|
68
- workspace.name == workspace_name
69
- end || raise("Could not find workspace #{workspace_name}")
70
- end
71
-
72
43
  def projects_by_workspace_name(workspace_name)
73
- workspace = workspace_by_name(workspace_name)
44
+ workspace = @workspaces.workspace_by_name(workspace_name)
74
45
  raise "Could not find workspace named #{workspace_name}" unless workspace
75
46
  projects.find_by_workspace(workspace: workspace.id)
76
47
  end
@@ -102,14 +73,19 @@ module Checkoff
102
73
 
103
74
  def task_options
104
75
  {
76
+ per_page: 100,
105
77
  options: {
106
- fields: %w(name assignee_status completed_at due_at due_on),
78
+ fields: %w[name completed_at due_at due_on],
107
79
  },
108
80
  }
109
81
  end
110
82
 
111
- def tasks_from_project(project)
112
- project.tasks(task_options).to_a
83
+ def tasks_from_project(project, only_uncompleted: true, extra_fields: [])
84
+ options = task_options
85
+ options[:completed_since] = '9999-12-01' if only_uncompleted
86
+ options[:project] = project.id
87
+ options[:options][:fields] += extra_fields
88
+ client.tasks.find_all(options).to_a
113
89
  end
114
90
  cache_method :tasks_from_project, LONG_CACHE_TIME
115
91
  end
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
2
5
  module Checkoff
3
6
  # Query different sections of Asana projects
4
7
  class Sections
@@ -6,6 +9,8 @@ module Checkoff
6
9
  LONG_CACHE_TIME = MINUTE * 15
7
10
  SHORT_CACHE_TIME = MINUTE * 5
8
11
 
12
+ extend Forwardable
13
+
9
14
  attr_reader :projects, :time
10
15
 
11
16
  def initialize(projects: Checkoff::Projects.new,
@@ -14,6 +19,8 @@ module Checkoff
14
19
  @time = time
15
20
  end
16
21
 
22
+ def_delegators :@projects, :client
23
+
17
24
  def file_task_by_section(current_section, by_section, task)
18
25
  if task.name =~ /:$/
19
26
  current_section = task.name
@@ -47,7 +54,7 @@ module Checkoff
47
54
  raw_tasks = projects.tasks_from_project(project)
48
55
  by_assignee_status =
49
56
  projects.active_tasks(raw_tasks)
50
- .group_by(&:assignee_status)
57
+ .group_by(&:assignee_status)
51
58
  active_tasks = by_assignee_status[assignee_status]
52
59
  by_section(active_tasks)
53
60
  end
@@ -14,12 +14,32 @@ module Checkoff
14
14
  LONG_CACHE_TIME = MINUTE * 15
15
15
  SHORT_CACHE_TIME = MINUTE * 5
16
16
 
17
- def initialize(sections: Checkoff::Sections.new)
17
+ def initialize(config: Checkoff::ConfigLoader.load(:asana),
18
+ sections: Checkoff::Sections.new,
19
+ asana_task: Asana::Resources::Task)
20
+ @config = config
18
21
  @sections = sections
22
+ @asana_task = asana_task
23
+ end
24
+
25
+ def client
26
+ @sections.client
19
27
  end
20
28
 
21
29
  def tasks_minus_sections(tasks)
22
30
  @sections.by_section(tasks).values.flatten
23
31
  end
32
+
33
+ def add_task(name,
34
+ workspace_id: default_workspace_id,
35
+ assignee_id: default_assignee_id)
36
+ @asana_task.create(client,
37
+ assignee: assignee_id,
38
+ workspace: workspace_id, name: name)
39
+ end
40
+
41
+ def default_assignee_id
42
+ @config[:default_assignee_id]
43
+ end
24
44
  end
25
45
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Checkoff
3
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
4
5
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Checkoff
4
+ # Query different workspaces of Asana projects
5
+ class Workspaces
6
+ def initialize(config: Checkoff::ConfigLoader.load(:asana),
7
+ asana_client: Asana::Client)
8
+ @config = config
9
+ @asana_client = asana_client
10
+ end
11
+
12
+ def client
13
+ @client ||= @asana_client.new do |c|
14
+ c.authentication :access_token, @config[:personal_access_token]
15
+ end
16
+ end
17
+
18
+ def default_workspace_id
19
+ @config[:default_workspace_id]
20
+ end
21
+
22
+ def workspace_by_name(workspace_name)
23
+ client.workspaces.find_all.find do |workspace|
24
+ workspace.name == workspace_name
25
+ end || raise("Could not find workspace #{workspace_name}")
26
+ end
27
+ end
28
+ end
data/lib/checkoff.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'checkoff/version'
4
+ require 'checkoff/workspaces'
3
5
  require 'checkoff/projects'
4
6
  require 'checkoff/sections'
5
7
  require 'checkoff/tasks'
data/lib/tasks/ci.rake CHANGED
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  task ci: :localtest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  task :clear_metrics do |_t|
3
4
  ret =
4
5
  system('git checkout coverage/.last_run.json metrics/*_high_water_mark')
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  task default: :localtest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rspec/core/rake_task'
3
4
 
4
5
  desc 'Run features'
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
- task localtest: [:clear_metrics, :test, :quality]
2
+
3
+ task localtest: %i[clear_metrics test quality]
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'quality/rake/task'
3
4
 
4
5
  Quality::Rake::Task.new do |task|
5
6
  task.skip_tools = ['reek']
6
7
  task.output_dir = 'metrics'
8
+ task.exclude_files = ['docs/example_project.png']
7
9
  end
data/lib/tasks/spec.rake CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rspec/core/rake_task'
3
4
 
4
5
  desc 'Run specs'
data/lib/tasks/test.rake CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rake/testtask'
3
4
 
4
5
  Rake::TestTask.new do |t|
@@ -1 +1 @@
1
- 487
1
+ 459
@@ -0,0 +1 @@
1
+ 0
@@ -0,0 +1 @@
1
+ 8
@@ -0,0 +1 @@
1
+ 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli
@@ -181,7 +181,6 @@ files:
181
181
  - LICENSE.txt
182
182
  - README.md
183
183
  - Rakefile
184
- - bin/checkoff
185
184
  - bin/console
186
185
  - bin/setup
187
186
  - checkoff.gemspec
@@ -196,6 +195,7 @@ files:
196
195
  - lib/checkoff/sections.rb
197
196
  - lib/checkoff/tasks.rb
198
197
  - lib/checkoff/version.rb
198
+ - lib/checkoff/workspaces.rb
199
199
  - lib/tasks/ci.rake
200
200
  - lib/tasks/clear_metrics.rake
201
201
  - lib/tasks/default.rake
@@ -209,13 +209,16 @@ files:
209
209
  - metrics/bundle-audit_high_water_mark
210
210
  - metrics/cane_high_water_mark
211
211
  - metrics/eslint_high_water_mark
212
+ - metrics/flake8_high_water_mark
212
213
  - metrics/flay_high_water_mark
213
214
  - metrics/flog_high_water_mark
214
215
  - metrics/jscs_high_water_mark
216
+ - metrics/mdl_high_water_mark
215
217
  - metrics/pep8_high_water_mark
216
218
  - metrics/punchlist_high_water_mark
217
219
  - metrics/rails_best_practices_high_water_mark
218
220
  - metrics/rubocop_high_water_mark
221
+ - metrics/scalastyle_high_water_mark
219
222
  homepage: http://github.com/apiology/checkoff
220
223
  licenses:
221
224
  - MIT
data/bin/checkoff DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env ruby