time_log_robot 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2652a17273d8fbd9ba807b14cfbc3eb018ab1c1
4
- data.tar.gz: e3856ad0064e76fcb6ffa010fab681148854585b
3
+ metadata.gz: ea745bfe20d10a98d2a22ada30fea34c6ea9d138
4
+ data.tar.gz: ef7dc87e71be0e41c932f2d692fa80507b8a02c0
5
5
  SHA512:
6
- metadata.gz: e4609015d99b6c66883598d98e10c26b1741392e5a93d821074892431ee23b1cafe2d874d85fbc7bab982efb0edcf9748e2db4488c057c89a1a6a01799aff566
7
- data.tar.gz: 19384cf6f8e7a187713255af9d11f4a400b8d51330c09917470839e3310f0673d842816b4f168c547d03758cb3b05d7d930b2fd35a50ae76ba9083c68482cf31
6
+ metadata.gz: 25361f569f95c89e8d06fef9841d31926bfd6292b54108c0e814444a4de98c0c4780fd893d7d5124b9dca7ca924c157a9306288e8cc07190551724379f6f3e66
7
+ data.tar.gz: 0d4a18ca78cc8cb920f151bd7a15f65001f90d989cf9306277967fa9019380d968c093260ec7fb8c802d6ae1ac98323b4c1a7151ec153e80598497f23f324fac
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
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
+ [![Gem Version](https://badge.fury.io/rb/time_log_robot.svg)](https://badge.fury.io/rb/time_log_robot)
2
3
  [![Code Climate](https://codeclimate.com/github/supremebeing7/time_log_robot/badges/gpa.svg)](https://codeclimate.com/github/supremebeing7/time_log_robot)
3
4
  [![Test Coverage](https://codeclimate.com/github/supremebeing7/time_log_robot/badges/coverage.svg)](https://codeclimate.com/github/supremebeing7/time_log_robot/coverage)
4
5
 
@@ -3,15 +3,19 @@ module TimeLogRobot
3
3
  class WorkLogger
4
4
  include HTTParty
5
5
 
6
- attr_accessor :username, :password, :time_entries, :log_tags
7
-
8
6
  base_uri 'https://hranswerlink.atlassian.net/rest/api/2'
9
7
 
8
+ @errors = []
9
+ @logged_count = 0
10
+
10
11
  class << self
12
+ attr_accessor :errors, :logged_count
13
+
11
14
  def log_all(time_entries:)
12
15
  time_entries.each do |entry|
13
16
  log(entry) unless is_logged?(entry)
14
17
  end
18
+ print_report
15
19
  end
16
20
 
17
21
  private
@@ -33,31 +37,51 @@ module TimeLogRobot
33
37
  end
34
38
 
35
39
  def log(entry)
36
- issue_key = JIRA::IssueKeyParser.parse(entry['description'])
40
+ issue_key = parse_issue_key(entry)
37
41
  payload = build_payload(entry)
38
- puts "Attempting to log #{human_readable_duration(parse_duration(entry))}"
39
- puts "starting on #{parse_start(entry)}"
40
- puts "to #{entry['description']}"
41
- puts "issue key #{issue_key}"
42
- puts "with comment #{parse_comment(entry)}" unless parse_comment(entry).nil?
43
42
  response = post("/issue/#{issue_key}/worklog", basic_auth: auth, headers: headers, body: payload)
44
43
  if response.success?
45
- puts "Success"
46
- puts '*' * 20
44
+ print "\e[32m.\e[0m"
47
45
  set_entry_as_logged(entry)
46
+ @logged_count += 1
48
47
  else
49
- puts response.code
50
- puts "Failed! Response from JIRA:"
48
+ print "\e[31mF\e[0m"
49
+ @errors << [entry, response]
51
50
  if response.code == 401
52
51
  raise UnauthorizedError, "Please check your username and password and try again"
53
- elsif response.code == 404
54
- puts "Not Found - Did you forget to put the JIRA issue key in your Toggl entry?"
55
52
  end
56
- puts '*' * 20
57
53
  end
58
54
  end
59
55
  class UnauthorizedError < Exception; end
60
56
 
57
+ def parse_issue_key(entry)
58
+ JIRA::IssueKeyParser.parse(entry['description'])
59
+ end
60
+
61
+ def print_report
62
+ print_errors if errors.any?
63
+ puts "\n\t#{logged_count} entries logged, #{errors.size} failed.\n\n"
64
+ end
65
+
66
+ def print_errors
67
+ puts "\n\t\e[1;31m Failed to log the following entries:\e[0m"
68
+ errors.each_with_index do |(entry, response), index|
69
+ puts "\e[31m"
70
+ puts "\t#{index + 1})\tDescription: #{entry['description']}"
71
+ if issue_key = parse_issue_key(entry)
72
+ puts "\t\tIssue Key: #{issue_key}"
73
+ else
74
+ puts "\t\tIssue Key: Missing"
75
+ end
76
+ unless parse_comment(entry).nil?
77
+ puts "\t\tComment: #{parse_comment(entry)}"
78
+ end
79
+ puts "\t\t#{human_readable_duration(parse_duration(entry))} starting on #{parse_start(entry)}"
80
+ puts "\t\tResponse Code: #{response.code}"
81
+ puts "\e[0m"
82
+ end
83
+ end
84
+
61
85
  def set_entry_as_logged(entry)
62
86
  Toggl::Tagger.update(entry_id: entry['id'])
63
87
  end
@@ -97,12 +121,6 @@ module TimeLogRobot
97
121
  "#{hours}h #{remaining_minutes}m"
98
122
  end
99
123
 
100
- # @TODO figure out how to capture both of this in one .match call with one set of regex
101
- def parse_issue_key(entry)
102
- matches = entry['description'].match(/(\[(?<issue_key>[^\]]*)\])/)
103
- matches['issue_key'] if matches.present?
104
- end
105
-
106
124
  def parse_comment(entry)
107
125
  matches = entry['description'].match(/(\{(?<comment>[^\}]*)\})/)
108
126
  matches['comment'] if matches.present?
@@ -1,3 +1,3 @@
1
1
  module TimeLogRobot
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
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.4
4
+ version: 0.1.5
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-06-10 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler