time_log_robot 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![CircleCI](https://circleci.com/gh/supremebeing7/time_log_robot/tree/master.svg?style=svg)](https://circleci.com/gh/supremebeing7/time_log_robot/tree/master)
2
+ [![Code Climate](https://codeclimate.com/github/supremebeing7/time_log_robot/badges/gpa.svg)](https://codeclimate.com/github/supremebeing7/time_log_robot)
3
+ [![Test Coverage](https://codeclimate.com/github/supremebeing7/time_log_robot/badges/coverage.svg)](https://codeclimate.com/github/supremebeing7/time_log_robot/coverage)
4
+
1
5
  # Time Log Robot
2
6
  ***Let the robot do your work time logging.***
3
7
 
@@ -40,11 +44,11 @@ This is an integration between project management tools (like JIRA) and time log
40
44
 
41
45
  The simplest usage is just to invoke the robot:
42
46
 
43
- time_log_robot
47
+ $ time_log_robot
44
48
 
45
49
  By default, the robot will get all time entries since the previous Saturday. To specify a different time, run it with the optional `--since` flag (Note: the date given must be in YYYY-MM-DD format):
46
50
 
47
- time_log_robot --since 2016-05-01
51
+ $ time_log_robot --since 2016-05-01
48
52
 
49
53
  On start, the robot will ask you for these details:
50
54
 
@@ -59,7 +63,7 @@ The robot has a memory like a steel trap, so after you run it the first time, it
59
63
 
60
64
  time_log_robot --overwrite
61
65
 
62
- Or, if you want to pop open the internals, the robot saves all configuration in `path/to/gem/config/settings.yml`, so open up that file and edit to your heart's content.
66
+ Or, if you want to pop open the internals, the robot saves all configuration in a file in your home directory: `~/.time_log_robot_settings.yml`, so open up that file and edit to your heart's content.
63
67
 
64
68
  ### Configuration
65
69
 
@@ -79,32 +83,43 @@ Here are some notes about how to find the appropriate values for those environme
79
83
 
80
84
  ### Mapping keys
81
85
 
82
- You can now map JIRA keys to specific phrases so that in your Toggl time entries, you won't need to enter the JIRA key. These mappings are stored in a YAML file in the gem root directory:
86
+ You can now map JIRA keys to specific phrases so that in your Toggl time entries, you won't need to enter the JIRA key. These mappings are stored by default in a YAML file in your home directory:
83
87
 
84
- path/to/gem/mapping.yml
88
+ ~/.time_log_robot_mapping.yml
85
89
 
86
90
  # Example usage
87
91
  # --
88
92
  # phrase: JIRA-KEY
89
93
  weekly planning: PM-1
90
94
 
91
- With this mapping, when logging time on on Toggl, instead of having to enter "weekly planning [PM-1]", you can just enter "weekly planning" and the robot will get the JIRA key from the `mapping.yml` file.
95
+ With this mapping, when logging time on on Toggl, instead of having to enter "weekly planning [PM-1]", you can just enter "weekly planning" and the robot will get the JIRA key from the `.time_log_robot_mapping.yml` file.
96
+
97
+ #### Moving the mapping file
98
+
99
+ If you don't care about keeping your mapping file hidden or out of the way, or if you want it somewhere it can be accessed more easily, feel free to create your own, then just tell the robot where it's located using the `--mapping` flag:
100
+
101
+ $ time_log_robot --mapping
102
+ # or `time_log_robot -m`
103
+ Enter your MAPPING_FILE_PATH: /full/path/to/your_mapping_file.yml
92
104
 
93
105
  ### Help
94
106
 
95
107
  For more details use the help flag:
96
108
 
97
- time_log_robot --help
109
+ $ time_log_robot --help
110
+
111
+ Or ask for help with the `run` command:
98
112
 
113
+ $ time_log_robot run --help
99
114
 
100
115
  ## Development
101
116
  To see available rake tasks for development
102
117
 
103
- rake -T
118
+ $ rake -T
104
119
 
105
120
  To run the app in IRB for debugging run
106
121
 
107
- rake console
122
+ $ rake console
108
123
 
109
124
  (Note: If you've built the gem and have committed the `.gem` file, none of your `rake` commands will work. You'll need to remove the built gem and commit the deletion.)
110
125
 
@@ -112,9 +127,11 @@ To run the app in IRB for debugging run
112
127
 
113
128
  1. Fork it
114
129
  2. Create your feature branch (`git checkout -b my-new-feature`)
115
- 3. Commit your changes (`git commit -am 'Add some feature'`)
116
- 4. Push to the branch (`git push origin my-new-feature`)
117
- 5. Create new Pull Request to Dev
130
+ 3. Write tests for your new code (uses `minitest`)
131
+ 4. Make sure all tests pass (`rake test`)
132
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
133
+ 6. Push to the branch (`git push origin my-new-feature`)
134
+ 7. Create new Pull Request to Dev
118
135
 
119
136
  ## License
120
137
 
data/bin/time_log_robot CHANGED
@@ -28,10 +28,12 @@ command :run do |c|
28
28
  c.example 'shorthand', 'time_log_robot'
29
29
  c.example 'with optional parameter "since"', 'time_log_robot run --since "2015-10-21"'
30
30
 
31
- c.option '--since STRING', String, 'The date from which to log time entries. Must be in YYYY-MM-DD format. Default is the previous Saturday.'
31
+ c.option '-m', '--mapping', 'Description to JIRA key mapping file is located by default at `~/.time_log_robot_mapping.yml`. Use this flag if you have a mapping file eslewhere and would like to define the path to point to your file instead.'
32
32
 
33
33
  c.option '--overwrite', 'Your settings are automatically written to a file - `~/.time_log_robot_settings.yml` - to be used again the next time you invoke the robot. Use this flag if you need to overwrite those settings.'
34
34
 
35
+ c.option '-s', '--since STRING', String, 'The date from which to log time entries. Must be in YYYY-MM-DD format. Default is the previous Saturday.'
36
+
35
37
  c.action do |args, options|
36
38
  if options.inputs_help
37
39
  print_inputs_help
@@ -41,6 +43,9 @@ command :run do |c|
41
43
  fetch_envars_from_config unless options.overwrite
42
44
 
43
45
  missing_envars = get_missing_envars
46
+ if options.mapping
47
+ missing_envars['MAPPING_FILE_PATH'] = get_envar('MAPPING_FILE_PATH')
48
+ end
44
49
 
45
50
  since = DateTime.parse(options.since).to_s unless options.since.nil?
46
51
 
@@ -62,22 +67,24 @@ def get_missing_envars
62
67
  missing_envars = {}
63
68
 
64
69
  TimeLogRobot.envars.each do |key|
65
- string_key = key.to_s
66
- unless ENV[string_key]
67
- ENV[string_key] = ask "Enter your #{string_key}: " do |char|
68
- char.echo = '*' if string_key =~ /password|token/i
69
- end
70
- if ENV[string_key].length == 0
71
- puts 'Invalid input. This is a required field.'
72
- exit
73
- end
74
- missing_envars[string_key] = ENV[string_key]
75
- end
70
+ next if key == 'MAPPING_FILE_PATH' || ENV[key]
71
+ missing_envars[key] = get_envar(key)
76
72
  end
77
73
 
78
74
  return missing_envars
79
75
  end
80
76
 
77
+ def get_envar(key)
78
+ ENV[key] = ask "Enter your #{key}: " do |char|
79
+ char.echo = '*' if key =~ /password|token/i
80
+ end
81
+ if ENV[key].length == 0
82
+ puts 'Invalid input. This is a required field.'
83
+ exit
84
+ end
85
+ ENV[key]
86
+ end
87
+
81
88
  def fetch_envars_from_config
82
89
  return unless envars = YAML.load_file(settings_file_path)
83
90
  envars.each_pair do |key, value|
@@ -101,11 +108,11 @@ def write_missing_envars(missing_envars={})
101
108
  end
102
109
 
103
110
  def create_settings_file_if_nonexistent
104
- File.new(settings_file_path, "w+") unless File.exists?(settings_file_path)
111
+ File.new(settings_file_path, "w+") unless File.file?(settings_file_path)
105
112
  end
106
113
 
107
114
  def settings_file_path
108
- File.join(TimeLogRobot.root, '.settings.yml')
115
+ File.join(ENV['HOME'], '.time_log_robot_settings.yml')
109
116
  end
110
117
 
111
118
  # set default action for gem
@@ -19,10 +19,18 @@ module TimeLogRobot
19
19
 
20
20
  def mappings
21
21
  YAML.load_file(keymap_file_path) || {}
22
+ rescue Errno::ENOENT
23
+ {}
22
24
  end
23
25
 
24
26
  def keymap_file_path
25
- File.join(TimeLogRobot.root, 'mapping.yml')
27
+ ENV['MAPPING_FILE_PATH'] || default_keymap_file_path
28
+ end
29
+
30
+ def default_keymap_file_path
31
+ path = File.join(ENV['HOME'], '.time_log_robot_mapping.yml')
32
+ return path if File.file?(path)
33
+ File.new(path, "w+").path
26
34
  end
27
35
  end
28
36
  end
@@ -1,3 +1,3 @@
1
1
  module TimeLogRobot
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -25,31 +25,30 @@ module TimeLogRobot
25
25
 
26
26
  def self.envars_help
27
27
  {
28
- TOGGL_TOKEN:
28
+ 'MAPPING_FILE_PATH' =>
29
+ "This is the path to your mapping file. By default, this file is named `.time_log_robot_mapping.yml` and lives in your home directory.\n\n",
30
+
31
+ 'TOGGL_TOKEN' =>
29
32
  "In your Toggl account, go to your profile page and look for the API token at the bottom.\n\n",
30
33
 
31
- TOGGL_WORKSPACE_ID:
34
+ 'TOGGL_WORKSPACE_ID' =>
32
35
  "This is a little trickier. Your workspaces usually only show a human-readable name to you in Toggl's UI, and here you need the workspace machine ID. But you can do a curl request to find it like this (replacing TOGGL_TOKEN with your token from above):
33
36
 
34
37
  \tcurl -v -u TOGGL_TOKEN:api_token \ -X GET https://www.toggl.com/api/v8/workspaces
35
38
 
36
39
  Look at the result and find the id given for the workspace you want to use.\n\n",
37
40
 
38
- TOGGL_USER_AGENT:
41
+ 'TOGGL_USER_AGENT' =>
39
42
  "This is your Toggl username, usually your email.\n\n",
40
43
 
41
- TOGGL_DEFAULT_LOG_TAG:
44
+ 'TOGGL_DEFAULT_LOG_TAG' =>
42
45
  "This is the tag name you would like to use for tagging your Toggl time entries as they are logged to JIRA.\n\n",
43
46
 
44
- JIRA_USERNAME:
47
+ 'JIRA_USERNAME' =>
45
48
  "This is your JIRA username, which is not an email, but usually your email minus the '@domain.com'\n\n",
46
49
 
47
- JIRA_PASSWORD:
48
- "I know there's a lot of jargon, but some of these are pretty self-explanatory
49
- ┌─┐
50
- ┴─┴
51
- ಠ_ರೃ
52
- \n"
50
+ 'JIRA_PASSWORD' =>
51
+ "I know there's a lot of jargon, but some of these are pretty self-explanatory\n"
53
52
  }
54
53
  end
55
54
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require 'minitest/autorun'
2
5
  require 'minitest/pride'
3
- require 'minitest/emoji'
4
6
  require 'minitest/reporters'
5
7
  require 'yaml'
6
8
  require 'active_support'
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rake', '~> 10.5'
24
24
  spec.add_development_dependency 'minitest', '~> 5.8'
25
25
  spec.add_development_dependency 'minitest-reporters', '~> 1.1'
26
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5'
26
27
 
27
28
  spec.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.6'
28
29
  spec.add_runtime_dependency 'commander', '~> 4.1', '>= 4.1.6'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_log_robot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark J. Lehman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-27 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activesupport
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -155,8 +169,9 @@ executables:
155
169
  extensions: []
156
170
  extra_rdoc_files: []
157
171
  files:
172
+ - ".codeclimate.yml"
158
173
  - ".gitignore"
159
- - ".settings.yml"
174
+ - ".rubocop.yml"
160
175
  - Gemfile
161
176
  - Gemfile.lock
162
177
  - LICENSE.txt
@@ -170,7 +185,6 @@ files:
170
185
  - lib/time_log_robot/toggl/report.rb
171
186
  - lib/time_log_robot/toggl/tagger.rb
172
187
  - lib/time_log_robot/version.rb
173
- - mapping.yml
174
188
  - test/test_helper.rb
175
189
  - test/time_log_robot/jira/issue_key_parser_test.rb
176
190
  - time_log_robot.gemspec
data/.settings.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- toggl_token: 5f85129ba262ce647e2914b7eeaa4cbc
3
- toggl_workspace_id: '702788'
4
- toggl_user_agent: markopolo@gmail.com
5
- toggl_default_log_tag: logged
6
- jira_username: markl
7
- jira_password: XDR%t6yhn
data/mapping.yml DELETED
@@ -1,8 +0,0 @@
1
- monday meeting: PM-1
2
- weekly planning meeting: PM-1
3
- architecture planning: PM-1
4
- architecture meeting: PM-1
5
- time log robot: OSS-5
6
- code review: PM-38
7
- daily planning: PM-35
8
- hw checkin meeting: HW-10