worklogger 2.5 → 2.5.6

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: 8203518dc88ad1196fa94b4816a6cf675bbac3c3
4
- data.tar.gz: c80c6c06e8971cd2c18c7ad8358d6db4e2e299e8
3
+ metadata.gz: 834b37d067d3086c53a3f2c67d69255daec299b7
4
+ data.tar.gz: 5f3c161416652c76e81a3a74e5640a405c804bfe
5
5
  SHA512:
6
- metadata.gz: 03dec8e67b0abe0e5379be1fa43d1b379c6ac8d4cf20bda08a0f1c665d8ad08554086c4ddeb4f3d5ebdf1265bbd4f363c2d90d11678c90a619f057fcfcaf926d
7
- data.tar.gz: c75f5cb6044ff3d32bfafaa4e426b5e677970713166597e2a46cef03ddfe8b7733fea722ef29654cfde429acff21b6a5bcc01a19e466214464694cae85f160e9
6
+ metadata.gz: 86c0adedff24ff55771e8393a9bf3c1b5f7220fb704fc6be4ec2f08d8a7ac8aea2f88f8bfa6705abd7e366c4f7a8afaba324ee31280d7f28206c06890be23b6e
7
+ data.tar.gz: f5509f4b1a37f051bdf9e985fa849f6fa0c2fb0a804db3841af94719abeafa4f6cd3c9cf723bd0f4a1bb29062fc1ed7027f9fe82b5bce79f1f1adb30d6d510ef
data/bin/worklogger CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'worklogger'
4
- require 'pry'
5
4
  require 'rubygems'
6
5
  require 'net/http'
7
6
  require 'net/https'
@@ -75,12 +74,14 @@ command = ARGV[0]
75
74
 
76
75
  case command
77
76
  when nil
78
- file = File.open('../options.txt', 'rb')
77
+ options_path = File.join(File.dirname(__FILE__), '../options.txt')
78
+ file = File.open(options_path, 'rb')
79
79
  content = file.read
80
80
  puts content
81
81
 
82
82
  when '-h', '--help'
83
- file = File.open('../README.rdoc', 'rb')
83
+ read_me_path = File.join(File.dirname(__FILE__), '../README.rdoc')
84
+ file = File.open(read_me_path, 'rb')
84
85
  content = file.read
85
86
  puts content
86
87
 
data/lib/post-commit ADDED
@@ -0,0 +1,90 @@
1
+ #!/bin/bash
2
+ echo 'A system developed by Vivek Tripathi lets you add a worklog with the description same as comment'
3
+ MESSAGE=$(git log -1 HEAD --pretty=format:%s)
4
+
5
+ prefix="issue="
6
+ MESSAGE=${MESSAGE#$prefix}
7
+ ISSUE_KEY=$(echo $MESSAGE| cut -d ' ' -f 1)
8
+ JIRA_USER_NAME=$USER_NAME
9
+ JIRA_PASSWORD=$PASSWORD
10
+ CORPORATE_URL=$CORPORATE_URL
11
+
12
+ time_spent="time="
13
+ TIME_SPENT=$(echo $MESSAGE | grep -o "$time_spent.*" | cut -d " " -f 1 | cut -d "=" -f 2)
14
+
15
+ COMMIT_MSG=$(echo $MESSAGE | cut -d " " -f3-)
16
+
17
+ jira_rest_get_issues(){
18
+ ruby <<EOF
19
+ require 'rubygems'
20
+ require 'net/http'
21
+ require 'net/https'
22
+ require 'json'
23
+ require 'uri'
24
+ require 'date'
25
+
26
+ issue_key = "$1"
27
+ time_spent = "$2"
28
+ commit_message = "$3"
29
+ jira_username = "$4"
30
+ jira_password = "$5"
31
+ corporate_url= "$6"
32
+
33
+ ## format time spent from say 2h10m to 2h 10m(added space)
34
+ time_spent_dup = time_spent.dup
35
+ index_of_h = time_spent_dup.index('h')
36
+ if !index_of_h.nil?
37
+ time_spent = time_spent_dup.insert(index_of_h + 1, ' ')
38
+ end
39
+
40
+ jira_url = "#{corporate_url}/rest/api/latest/issue/"
41
+ issue_keys = %w[issue_key]
42
+ json_ext = ".json"
43
+
44
+ for issue in issue_keys
45
+
46
+ uri = URI.parse("#{corporate_url}/rest/auth/1/session")
47
+ http = Net::HTTP.new(uri.host, uri.port)
48
+ http.use_ssl = true
49
+ request = Net::HTTP::Get.new(uri.to_s)
50
+ request.basic_auth jira_username.to_s, URI.decode(jira_password.to_s)
51
+ request['Content-Type'] = 'application/json'
52
+ response = http.request(request)
53
+ worklog = {
54
+ comment: commit_message.to_s,
55
+ started: DateTime.now.strftime("%Y-%m-%dT%H:%M:%S.%L%z"),
56
+ timeSpent: time_spent.to_s,
57
+ }.to_json
58
+
59
+
60
+ if response.code =~ /20[0-9]{1}/
61
+ data = JSON.parse(response.body)
62
+ fields = data.keys
63
+
64
+ uri = URI.parse("#{corporate_url}/rest/api/2/issue/#{issue_key}/worklog")
65
+ https = Net::HTTP.new(uri.host, uri.port)
66
+ https.use_ssl = true
67
+ req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
68
+ req.basic_auth jira_username.to_s, URI.decode(jira_password.to_s)
69
+ req.body = "#{worklog}"
70
+ res = https.request(req)
71
+ puts "Response #{res.code} #{res.message}: #{res.body}"
72
+
73
+ puts "\n"#extra line feed for readability
74
+ case res
75
+ when Net::HTTPRedirection
76
+ # repeat the request using response['Location']
77
+ when Net::HTTPSuccess
78
+ repo_info = JSON.parse res.body
79
+ else
80
+ # response code isn't a 200; raise an exception
81
+ res.error!
82
+ end
83
+ else
84
+ raise StandardError, "Unsuccessful response code " + response.code + " for issue " + issue
85
+ end
86
+ end
87
+ EOF
88
+ }
89
+
90
+ jira_rest_get_issues $ISSUE_KEY $TIME_SPENT "$COMMIT_MSG" $JIRA_USER_NAME $JIRA_PASSWORD $CORPORATE_URL
data/lib/worklogger.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class Worklogger
2
2
  def self.make_me_lazy
3
- system 'cp post-commit .git/hooks/'
3
+ post_commit_path = File.join(File.dirname(__FILE__), '/post-commit')
4
+ system "cp #{post_commit_path} .git/hooks/"
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worklogger
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.5'
4
+ version: 2.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.rdoc
21
21
  - bin/worklogger
22
+ - lib/post-commit
22
23
  - lib/worklogger.rb
23
24
  - options.txt
24
25
  homepage: http://rubygems.org/gems/worklogger