dovico 1.2.0 → 1.3.0

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: 641eaa573848e60b70368be58db24872e2237a24
4
- data.tar.gz: ca2e3477d9d1a70545e95d223aed5101796aec50
3
+ metadata.gz: 14163c6be8c7579510cc31562a4ad12654913915
4
+ data.tar.gz: 199cf014ef1ead6072d13991b52aa909c7ef7a88
5
5
  SHA512:
6
- metadata.gz: 4b837afe730bbc5fe4a057c2b71ba8910a73cb50d0de4cc5dd9a738d0eecc79d19c7c108709f9d6f2bf4559e22cf93ba223e8d6af0fb6fc7a84a6cc2acd0a3b3
7
- data.tar.gz: 8a7550467aaafa92c599e1f9aa556a534ca15cdb35c0a095523cb4f5e50b97bf8e2755648cefae7590f8f44688a10bc9782ba5fdf40d31f880489dd7d0337a52
6
+ metadata.gz: b9da177d527421c5d0567437658d6be258b43bf05df977ed8531552feff1f7d350e9911c6ae7a4e42fc7b16a7aaa29c3d200ae7bb2db1ef9b3ceb9990a3edcda
7
+ data.tar.gz: ce26cd4d455096696a38ffcc96ef461601d95de7126a1d234986100b0ba6c486f73bd7855ac5295ff299523aef18640bcfb66f1f0c81f49298150cc239dce879
data/CHANGELOG.md CHANGED
@@ -1,6 +1,41 @@
1
1
  # Next version
2
2
  - Your contribution!
3
3
 
4
+ # Version 1.3.0
5
+ - Update [README.md](README.md)
6
+ - Fix bug when no time entries were to be submitted
7
+ - **Breaking change**: Specific days must be configured in the special `specific_days` section in the configuration file
8
+ - Specific weeks or months can be defined with `specific_weeks` and `specific_months` configuration
9
+ ~~~json
10
+ assignments:
11
+ default_day:
12
+ - project_id: 1234
13
+ task_id: 100
14
+ hours: 3
15
+ - project_id: 9999
16
+ task_id: 120
17
+ hours: 2
18
+ - project_id: 4321
19
+ task_id: 424
20
+ hours: 2
21
+ specific_days:
22
+ # Quotes around day are mandatory
23
+ # On leave: use an empty array
24
+ '2016-01-17': []
25
+ # Specific day: redefine each tasks
26
+ '2017-12-19':
27
+ - project_id: 1234
28
+ task_id: 456
29
+ hours: 6
30
+ - project_id: 4321
31
+ task_id: 424
32
+ hours: 1
33
+ specific_weeks:
34
+ '2016-52': [] # Christmas week
35
+ specific_months:
36
+ '2016-07': [] # No work on July
37
+ ~~~
38
+
4
39
  # Version 1.2.0
5
40
  - Update [README.md](README.md)
6
41
  - Add `--clear` option to delete time entries
data/Makefile CHANGED
@@ -1,8 +1,3 @@
1
- WEEK ?= $(shell date +%V)
2
- YEAR ?= $(shell date +%Y)
3
- DAY ?= $(shell date +%F)
4
- TAG ?= $(shell git log -1 --abbrev=10 --format=%h)
5
-
6
1
  # Update the specified dependencies
7
2
  install:
8
3
  @command -v ruby >/dev/null 2>&1 || { echo >&2 "I require ruby but it's not installed. Aborting."; exit 1; }
@@ -13,54 +8,17 @@ install:
13
8
  test: bundler
14
9
  bundle exec rake spec
15
10
 
11
+ # Build a new package file
16
12
  build:
17
13
  bundle exec gem build dovico-client.gemspec
18
14
 
19
- help:
20
- bundle exec bin/dovico --help
21
-
22
- tasks:
23
- bundle exec bin/dovico --tasks
24
-
25
- myself:
26
- bundle exec bin/dovico --myself
27
-
28
- # Fill actions
29
- current_week:
30
- bundle exec bin/dovico --fill --current-week
31
-
32
- week:
33
- bundle exec bin/dovico --fill --year=$(YEAR) --week=$(WEEK)
34
-
35
- today:
36
- bundle exec bin/dovico --fill --today
37
-
38
- day:
39
- bundle exec bin/dovico --fill --day=$(DAY)
40
-
41
- # Submit actions
42
- submit-current-week:
43
- bundle exec bin/dovico --submit --current-week
44
-
45
- submit-week:
46
- bundle exec bin/dovico --submit --year=$(YEAR) --week=$(WEEK)
47
-
48
- submit-day:
49
- bundle exec bin/dovico --submit --day=$(DAY)
50
-
51
- submit-today:
52
- bundle exec bin/dovico --submit --today
15
+ # Publish a package on https://rubygems.org/gems/dovico
16
+ publish:
17
+ bundle exec gem push $(PACKAGE_FILE)
53
18
 
54
19
  # Private - ensure gems are up-to-date
55
20
  bundler:
56
21
  bundle check>/dev/null || bundle install
57
22
 
58
- docker-build-image:
59
- docker images | grep capitainetrain/dovico | grep $(TAG) || docker build --force-rm -t capitainetrain/dovico:$(TAG) -f Dockerfile .
60
-
61
- # Run tests in Docker image
62
- docker-test: docker-build-image
63
- docker run --rm capitainetrain/dovico:$(TAG) test
64
-
65
23
 
66
- .PHONY: install test help tasks myself current_week week today day submit-current-week submit-week submit-day submit-today bundler docker-build-image docker-test
24
+ .PHONY: install test build publish bundler
data/README.md CHANGED
@@ -62,17 +62,23 @@ assignments:
62
62
  - project_id: 4321
63
63
  task_id: 424
64
64
  hours: 2
65
- # Quotes around day are mandatory
66
- # On leave: use an empty array
67
- '2016-01-17': []
68
- # Specific day: redefine each tasks
69
- '2017-12-19':
70
- - project_id: 1234
71
- task_id: 456
72
- hours: 6
73
- - project_id: 4321
74
- task_id: 424
75
- hours: 1
65
+ specific_days:
66
+ # Quotes around day are mandatory
67
+ # On leave: use an empty array
68
+ '2016-01-17': []
69
+ # Specific day: redefine each tasks
70
+ '2017-12-19':
71
+ - project_id: 1234
72
+ task_id: 456
73
+ hours: 6
74
+ - project_id: 4321
75
+ task_id: 424
76
+ hours: 1
77
+ specific_weeks:
78
+ '2016-52': [] # Christmas week
79
+ specific_months:
80
+ '2016-07': [] # No work on July
81
+
76
82
  ~~~
77
83
 
78
84
  # Usage
@@ -106,7 +112,7 @@ Project | Task | Description
106
112
  The date options are detailed below. All the other commands use the same format for these date options.
107
113
 
108
114
  ### For the current week
109
- `dovico --fill --current_week`
115
+ `dovico --fill --current-week`
110
116
 
111
117
  ### For today
112
118
  `dovico --fill --today`
data/dovico.yml.example CHANGED
@@ -13,14 +13,19 @@ assignments:
13
13
  - project_id: 4321
14
14
  task_id: 424
15
15
  hours: 2
16
- # Quotes around day are mandatory
17
- # On leave: use an empty array
18
- '2016-01-17': []
19
- # Specific day: redefine each tasks
20
- '2017-12-19':
21
- - project_id: 1234
22
- task_id: 456
23
- hours: 6
24
- - project_id: 4321
25
- task_id: 424
26
- hours: 1
16
+ specific_days:
17
+ # Quotes around day are mandatory
18
+ # On leave: use an empty array
19
+ '2016-01-17': []
20
+ # Specific day: redefine each tasks
21
+ '2017-12-19':
22
+ - project_id: 1234
23
+ task_id: 456
24
+ hours: 6
25
+ - project_id: 4321
26
+ task_id: 424
27
+ hours: 1
28
+ specific_weeks:
29
+ '2016-52': [] # Christmas week
30
+ specific_months:
31
+ '2016-07': [] # No work on July
data/lib/dovico/app.rb CHANGED
@@ -84,8 +84,12 @@ EOL
84
84
  )
85
85
  time_entries = time_entry_generator.generate(start_date, end_date)
86
86
 
87
- saved_time_entries = TimeEntry.batch_create!(time_entries)
88
- puts "#{saved_time_entries["TimeEntries"].count} Entries created between #{start_date} and #{end_date}"
87
+ if time_entries.count > 0
88
+ saved_time_entries = TimeEntry.batch_create!(time_entries)
89
+ puts "#{saved_time_entries["TimeEntries"].count} Entries created between #{start_date} and #{end_date}"
90
+ else
91
+ puts "No entries to be created between #{start_date} and #{end_date}"
92
+ end
89
93
  end
90
94
 
91
95
  if config[:submit]
@@ -54,7 +54,11 @@ module Dovico
54
54
 
55
55
  def self.batch_create!(assignments)
56
56
  api_assignements = assignments.map(&:to_api)
57
- ApiClient.post(URL_PATH, body: api_assignements.to_json)
57
+ if api_assignements.count > 0
58
+ ApiClient.post(URL_PATH, body: api_assignements.to_json)
59
+ else
60
+ []
61
+ end
58
62
  end
59
63
 
60
64
  def self.submit!(employee_id, start_date, end_date)
@@ -50,7 +50,19 @@ module Dovico
50
50
  end
51
51
 
52
52
  def day_assignments(date)
53
- assignments[date.to_s] || assignments["default_day"]
53
+ special_day(date) || special_week(date) || special_month(date) || assignments["default_day"]
54
+ end
55
+
56
+ def special_day(date)
57
+ assignments["special_days"] && assignments["special_days"][date.iso8601]
58
+ end
59
+
60
+ def special_week(date)
61
+ assignments["special_weeks"] && assignments["special_weeks"][date.strftime("%Y-%V")]
62
+ end
63
+
64
+ def special_month(date)
65
+ assignments["special_months"] && assignments["special_months"][date.strftime("%Y-%m")]
54
66
  end
55
67
  end
56
68
  end
@@ -1,3 +1,3 @@
1
1
  module Dovico
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -11,15 +11,22 @@ module Dovico
11
11
  let(:employee_id) { "999" }
12
12
  let(:assignment_1) do
13
13
  {
14
- "project_id": "1234",
15
- "task_id": "456",
14
+ "project_id": "1111",
15
+ "task_id": "111",
16
16
  "hours": 4,
17
17
  }.stringify_keys
18
18
  end
19
19
  let(:assignment_2) do
20
20
  {
21
- "project_id": "6789",
22
- "task_id": "999",
21
+ "project_id": "2222",
22
+ "task_id": "222",
23
+ "hours": 3,
24
+ }.stringify_keys
25
+ end
26
+ let(:assignment_3) do
27
+ {
28
+ "project_id": "3333",
29
+ "task_id": "333",
23
30
  "hours": 3,
24
31
  }.stringify_keys
25
32
  end
@@ -44,16 +51,16 @@ module Dovico
44
51
 
45
52
  expect(first_time_entry.id).to be_nil
46
53
  expect(first_time_entry.employee_id).to eq(employee_id)
47
- expect(first_time_entry.project_id).to eq('1234')
48
- expect(first_time_entry.task_id).to eq('456')
54
+ expect(first_time_entry.project_id).to eq('1111')
55
+ expect(first_time_entry.task_id).to eq('111')
49
56
  expect(first_time_entry.date).to eq('2017-01-02')
50
57
  expect(first_time_entry.start_time).to eq('0900')
51
58
  expect(first_time_entry.stop_time).to eq('1300')
52
59
  expect(first_time_entry.total_hours).to eq(4)
53
60
 
54
61
  expect(first_time_entry.employee_id).to eq(employee_id)
55
- expect(last_time_entry.project_id).to eq('6789')
56
- expect(last_time_entry.task_id).to eq('999')
62
+ expect(last_time_entry.project_id).to eq('2222')
63
+ expect(last_time_entry.task_id).to eq('222')
57
64
  expect(last_time_entry.date).to eq('2017-01-06')
58
65
  expect(last_time_entry.start_time).to eq('1300')
59
66
  expect(last_time_entry.stop_time).to eq('1600')
@@ -65,8 +72,10 @@ module Dovico
65
72
  let(:assignments_config) do
66
73
  {
67
74
  'default_day': [ assignment_1, assignment_2 ],
68
- '2016-02-29': [],
69
- '2016-03-01': [ assignment_2 ],
75
+ 'special_days': {
76
+ '2016-02-29': [],
77
+ '2016-03-01': [ assignment_2 ],
78
+ }.stringify_keys,
70
79
  }.stringify_keys
71
80
  end
72
81
  let(:start_date) { Date.parse('2016-02-29') }
@@ -81,6 +90,56 @@ module Dovico
81
90
  expect(time_entry.total_hours).to eq(3)
82
91
  end
83
92
  end
93
+
94
+ context 'with specific day, weeks and month assignments' do
95
+ let(:assignments_config) do
96
+ {
97
+ 'default_day': [ ],
98
+ 'special_days': {
99
+ '2017-08-28': [ assignment_1 ],
100
+ }.stringify_keys,
101
+ 'special_weeks': {
102
+ '2017-35': [ assignment_2 ],
103
+ }.stringify_keys,
104
+ 'special_months': {
105
+ '2017-09': [ assignment_3 ],
106
+ }.stringify_keys,
107
+ }.stringify_keys
108
+ end
109
+ context 'in the first week' do
110
+ let(:start_date) { Date.parse('2017-08-28') }
111
+ let(:end_date) { Date.parse('2017-08-29') }
112
+
113
+ it 'uses specific days and weeks assignments' do
114
+ time_entries = subject.generate(start_date, end_date)
115
+ expect(time_entries.count).to eq(2)
116
+
117
+ # Specific day
118
+ expect(time_entries[0].date).to eq('2017-08-28')
119
+ expect(time_entries[0].project_id).to eq('1111')
120
+ expect(time_entries[0].task_id).to eq('111')
121
+
122
+ # Specific week
123
+ expect(time_entries[1].date).to eq('2017-08-29')
124
+ expect(time_entries[1].project_id).to eq('2222')
125
+ expect(time_entries[1].task_id).to eq('222')
126
+ end
127
+ end
128
+
129
+ context 'in a second week' do
130
+ let(:start_date) { Date.parse('2017-09-04') }
131
+ let(:end_date) { Date.parse('2017-09-04') }
132
+
133
+ it 'uses specific months assignments' do
134
+ time_entries = subject.generate(start_date, end_date)
135
+
136
+ # Specific month
137
+ expect(time_entries[0].date).to eq('2017-09-04')
138
+ expect(time_entries[0].project_id).to eq('3333')
139
+ expect(time_entries[0].task_id).to eq('333')
140
+ end
141
+ end
142
+ end
84
143
  end
85
144
  end
86
145
  end
@@ -120,13 +120,24 @@ module Dovico
120
120
  allow(ApiClient).to receive(:post)
121
121
  end
122
122
 
123
- it 'calls the API and post TimeEntries objects' do
124
- Dovico::TimeEntry.batch_create!(assignments)
123
+ context 'with time entries to be created' do
124
+ it 'calls the API and post TimeEntries objects' do
125
+ Dovico::TimeEntry.batch_create!(assignments)
125
126
 
126
- expect(ApiClient).to have_received(:post).with(
127
- "#{Dovico::TimeEntry::URL_PATH}",
128
- body: [subject.to_api].to_json
129
- )
127
+ expect(ApiClient).to have_received(:post).with(
128
+ "#{Dovico::TimeEntry::URL_PATH}",
129
+ body: [subject.to_api].to_json
130
+ )
131
+ end
132
+ end
133
+
134
+ context 'with no time entries to be created' do
135
+ it 'does not call the API and returns an empty array' do
136
+ result = Dovico::TimeEntry.batch_create!([])
137
+
138
+ expect(ApiClient).not_to have_received(:post)
139
+ expect(result).to eq([])
140
+ end
130
141
  end
131
142
  end
132
143
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dovico
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Théophile Helleboid
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-09 00:00:00.000000000 Z
12
+ date: 2017-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: easy_app_helper