mtm 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,24 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ How to use this script?
22
+
23
+ 1. Opens your teminal and input:$: gem install mtm
24
+
25
+ 2. Opens your teminal and input: tm -p 'Project name' -c 'Change name' -h 8 -d 'Tested some pages' -u bruce.yue:password
26
+ The default hours is 8 and default description is "Tested some pages and fixed some bugs."
27
+ If step 2 have been done, '-u' is not required in the step 3.
28
+ For example:
29
+ Project "CM Peak Development Requests", Its change is "Automate Upload of Build Records"
30
+ $: tm -p 'Peak Development' -c 'Build Records' -h 6 -d 'Added exception process logic.'
31
+
32
+ If there is no change. just paste
33
+
34
+ $: tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
35
+
36
+ Fill your time card at some time.
37
+ $: at 9pm today tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
38
+
22
39
 
23
40
  ## Contributing
24
41
 
data/lib/mtm/config.rb ADDED
@@ -0,0 +1,38 @@
1
+ ####################################################################################
2
+ ############################### start parse value ##################################
3
+ ####################################################################################
4
+ # please fill these fields: ###
5
+ SF_USERNAME = '' # Salesforce user name ###
6
+ SF_PASSWORD = '' # Salesforce password ###
7
+ SF_SECURITY_TOKEN = '' # Salesforce password security token(option) ###
8
+
9
+
10
+
11
+ ############ option ################
12
+ SF_PROJECT = '' # project name
13
+ SF_PROJECT_NUMBER = nil # project number #if Prj-07867, SF_PROJECT_NUMBER = 07867
14
+ SF_CHANGE = '' # change name
15
+ SF_CHANGE_NUMBER = nil # change number
16
+ SF_HOUR = 8 # time card hours
17
+ SF_TIMECARD_DESCRIPTION = 'Tested some pages and fixed some bugs.'
18
+ ####################################################################################
19
+ ############################## end parse value #####################################
20
+ ####################################################################################
21
+
22
+ =begin
23
+ How to use this script?
24
+ 1. Opens your teminal and input:$: gem install mtm
25
+ 2. Opens this file and paste your user name, password and sf_security_token.
26
+ 3. Opens your teminal and input: tm -p 'Project name' -c 'Change name' -h 8 -d 'Tested some pages' -u bruce.yue:password
27
+ The default hours is 8 and default description is "Tested some pages and fixed some bugs."
28
+ If step 2 have been done, '-u' is not required in the step 3.
29
+ For example:
30
+ Project "Silver Peak Development Requests", Its change is "Automate Upload of Build Records"
31
+ $: tm -p 'Peak Development' -c 'Build Records' -h 6 -d 'Added exception process logic.'
32
+
33
+ If there is no change. just paste
34
+ $: tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
35
+
36
+ Fill your time card at some time.
37
+ $: at 9pm today tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
38
+ =end
data/lib/mtm/mtm.rb CHANGED
@@ -1,83 +1,38 @@
1
- ####################################################################################
2
- ############################### start parse value ##################################
3
- ####################################################################################
4
- # please fill these fields: ###
5
- sf_username = '' # Salesforce user name ###
6
- sf_password = '' # Salesforce password ###
7
- sf_security_token = '' # Salesforce password security token(option) ###
8
- ####################################################################################
9
- ############################## end parse value #####################################
10
- ####################################################################################
11
-
12
- =begin
13
- How to use this script?
14
- 0. Opens your teminal and input:$: gem install restforce
15
- $: gem install ruby-progressbar
16
-
17
- 1. Puts this file to '/usr/bin' folder
18
- $: cd /user/bin
19
- $: chmod 755 tm
20
- 2. Opens this file and paste your user name and password.
21
- 3. Opens your teminal and input: tm -p 'Project name' -c 'Change name' -h 8 -d 'Tested some pages' -u bruce.yue:password
22
- The default hours is 8 and default description is "Tested some pages and fixed some bugs."
23
- If step 2 have been done, '-u' is not required in the step 3.
24
- For example:
25
- Project "Silver Peak Development Requests", Its change is "Automate Upload of Build Records"
26
- $: tm -p 'Peak Development' -c 'Build Records' -h 6 -d 'Added exception process logic.'
27
-
28
- If there is no change. just paste
29
- $: tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
30
-
31
- Fill your time card at some time.
32
- $: at 9pm today tm -p 'Peak Development' -h 6 -d 'Added exception process logic.'
33
- =end
34
-
35
- # salesforce remote app client id
36
- sf_client_id = '3MVG9Y6d_Btp4xp6SWO6yPlUURnycVbOfuH7I_NH2bjaw0yeoguRatNzKRpEVaIvmX7TcQbVVjuQUCZ006pwN'
37
- sf_client_secret = '5339957415407001741' # salesforce remote app client secret
38
- user_name_suffix = '@pm.meginfo.com'
39
- sf_project = '' # project name
40
- sf_project_number = nil # project number
41
- sf_change = '' # change name
42
- sf_change_number = nil # change number
43
- sf_hour = 8 # time card hours
44
-
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__))
45
2
  require 'rubygems'
46
3
  require 'restforce' # gem install restforce
47
4
  require 'optparse/date'
48
5
  require 'ruby-progressbar'
6
+ require 'utils'
7
+ require 'config'
49
8
 
50
9
  @pb = ProgressBar.create(:title => 'Logging', :starting_at => 0, :total => 100, :progress_mark => '*', :format => '%w %%')
51
10
 
52
- # for date format argv
53
- def parse_days_or_date(d)
54
- if d.to_s =~ /^\d+$/
55
- d.to_i
56
- else
57
- Date.parse(d)
58
- end
59
- end
60
-
61
11
  # Parse arguments
62
12
  options = {}
63
- options[:user_name] = sf_username
64
- options[:password] = sf_password
65
- options[:security_token] = sf_security_token
13
+ options[:user_name] = SF_USERNAME
14
+ options[:password] = SF_PASSWORD
15
+ options[:security_token] = SF_SECURITY_TOKEN
66
16
  options[:test] = false
67
17
  options[:host] = 'login.salesforce.com'
68
18
  options[:tm_list] = false
69
- options[:tm_project] = sf_project
70
- options[:tm_p_number] = sf_project_number
71
- options[:tm_change] = sf_change
72
- options[:tm_c_number] = sf_change_number
73
- options[:tm_hour] = sf_hour
19
+ options[:tm_project] = SF_PROJECT
20
+ options[:tm_p_number] = SF_PROJECT_NUMBER
21
+ options[:tm_change] = SF_CHANGE
22
+ options[:tm_c_number] = SF_CHANGE_NUMBER
23
+ options[:tm_hour] = SF_HOUR
74
24
  options[:tm_date] = DateTime.now.to_date
75
- options[:tm_description] = 'Tested some pages and fixed some bugs.'
25
+ options[:tm_description] = SF_TIMECARD_DESCRIPTION
26
+
27
+ # salesforce remote app client id
28
+ sf_client_id = '3MVG9Y6d_Btp4xp6SWO6yPlUURnycVbOfuH7I_NH2bjaw0yeoguRatNzKRpEVaIvmX7TcQbVVjuQUCZ006pwN'
29
+ sf_client_secret = '5339957415407001741' # salesforce remote app client secret
30
+ user_name_suffix = '@pm.meginfo.com'
76
31
 
77
32
  op = OptionParser.new do |opts|
78
33
  opts.banner = <<-BANNER
79
34
  Timecard Solution
80
- Usage: tm -p project -c change -h 6 -d 'Added exception process logic.'
35
+ Usage: mtm -p project -c change -h 6 -d 'Added exception process logic.'
81
36
  BANNER
82
37
  opts.separator ''
83
38
 
@@ -121,7 +76,7 @@ op = OptionParser.new do |opts|
121
76
  end
122
77
 
123
78
  opts.on("-d", "--date YYYY-MM-DD", "Timecard Date, default: TODAY", "Enter date in (YYYY-MM-DD) format.") do |d|
124
- options[:tm_date] = parse_days_or_date(d)
79
+ options[:tm_date] = Mtm.parse_days_or_date(d)
125
80
  end
126
81
 
127
82
  opts.on("-e Description", "Timecard detail information, describle today's work.") do |desc|
@@ -139,17 +94,19 @@ if ARGV.size < 1
139
94
  puts op
140
95
  exit
141
96
  end
97
+
142
98
  40.times { sleep(0.05); @pb.increment }
99
+
143
100
  # login to salesforce.com
144
101
  begin
145
- @client = Restforce.new :client_id => sf_client_id,
102
+ client = Restforce.new :client_id => sf_client_id,
146
103
  :client_secret => sf_client_secret,
147
104
  :username => options[:user_name],
148
105
  :password => options[:password],
149
106
  :security_token => options[:security_token],
150
107
  :host => options[:host]
151
- response = @client.authenticate!
152
- info = @client.get(response.id).body
108
+ response = client.authenticate!
109
+ info = client.get(response.id).body
153
110
  @sf_user_id = info.user_id
154
111
  rescue Exception => e
155
112
  puts e.message
@@ -159,7 +116,7 @@ end
159
116
  # list all projects and its changes
160
117
  if options[:tm_list]
161
118
  40.times { sleep(0.05); @pb.increment }
162
- projects = @client.query("select Id, Name, ProjectNumber__c, (select Id, Name, ChangeNumber__c from Changes__r
119
+ projects = client.query("select Id, Name, ProjectNumber__c, (select Id, Name, ChangeNumber__c from Changes__r
163
120
  where Status__c != 'Closed') from MProject__c where Status__c != 'Closed'")
164
121
  projects.each do |p|
165
122
  puts
@@ -175,8 +132,8 @@ if options[:tm_list]
175
132
  end
176
133
 
177
134
  # Creates time card
178
- def create_timecard(*args)
179
- @tm = @client.create!('TimeCard__c', Project__c: args[0],
135
+ def create_timecard(*args, client)
136
+ @tm = client.create!('TimeCard__c', Project__c: args[0],
180
137
  Change__c: args[1],
181
138
  Date__c: args[2],
182
139
  Hours__c: args[3],
@@ -189,14 +146,14 @@ end
189
146
  msg = 'Project not found'
190
147
  begin
191
148
  if options[:tm_project] != ''
192
- projects = @client.query("select Id, Name, (select Id, Name from Changes__r where Status__c != 'Closed' and
149
+ projects = client.query("select Id, Name, (select Id, Name from Changes__r where Status__c != 'Closed' and
193
150
  Name like '%#{options[:tm_change]}%') from MProject__c where Status__c != 'Closed'
194
151
  and Name like '%#{options[:tm_project]}%'")
195
- end
196
- if options[:tm_p_number] != nil
197
- projects = @client.query("select Id, Name, (select Id, Name from Changes__r where Status__c != 'Closed'
152
+ elsif options[:tm_p_number] != nil
153
+ p_number = 'Prj-' << options[:tm_p_number]
154
+ projects = client.query("select Id, Name, (select Id, Name from Changes__r where Status__c != 'Closed'
198
155
  and ChangeNumber__c = '#{options[:tm_c_number]}')
199
- from MProject__c where Status__c != 'Closed' and ProjectNumber__c = '#{options[:tm_p_number]}'")
156
+ from MProject__c where Status__c != 'Closed' and ProjectNumber__c = '#{p_number}'")
200
157
  end
201
158
  30.times { sleep(0.05); @pb.increment }
202
159
  rescue Exception => e
@@ -217,15 +174,15 @@ end
217
174
 
218
175
  begin
219
176
  if projects.size == 1
220
- team_member = @client.query("select Id from TeamMember__c where Project__c = '#{projects.first.Id}' and User__c = '#{@sf_user_id}'");
177
+ team_member = client.query("select Id from TeamMember__c where Project__c = '#{projects.first.Id}' and User__c = '#{@sf_user_id}'");
221
178
  if(options[:tm_change] == '' && options[:tm_c_number] == nil)
222
179
  create_timecard(projects.first.Id, nil, options[:tm_date], options[:tm_hour],
223
- team_member.first.Id, options[:tm_description], projects.first.Name)
180
+ team_member.first.Id, options[:tm_description], projects.first.Name, client)
224
181
  else
225
182
  if (projects.first.Changes__r != nil && projects.first.Changes__r.size == 1)
226
183
  create_timecard(projects.first.Id, projects.first.Changes__r.first.Id,
227
184
  options[:tm_date], options[:tm_hour], team_member.first.Id,
228
- options[:tm_description], projects.first.Name)
185
+ options[:tm_description], projects.first.Name, client)
229
186
  elsif projects.first.Changes__r == nil
230
187
  puts
231
188
  puts 'No change found.'
data/lib/mtm/utils.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Mtm
2
+ extend self
3
+
4
+ # for date format argv
5
+ def parse_days_or_date(d)
6
+ if d.to_s =~ /^\d+$/
7
+ d.to_i
8
+ else
9
+ Date.parse(d)
10
+ end
11
+ end
12
+
13
+ end
data/lib/mtm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mtm
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/mtm.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "mtm/version"
2
2
 
3
3
  module Mtm
4
- class Tm
4
+ class Mtm
5
5
  def log_timecard
6
6
  puts 'Please log your timecard on time.'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir:
11
11
  - bin
12
12
  cert_chain: []
13
- date: 2013-03-26 00:00:00.000000000 Z
13
+ date: 2013-03-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: restforce
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: '0'
22
+ version: 1.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
- version: '0'
30
+ version: 1.1.0
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: ruby-progressbar
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
- version: '0'
38
+ version: 1.0.2
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: 1.0.2
47
47
  description: Timecard solution
48
48
  email:
49
49
  - bruce.yue@outlook.com
@@ -52,7 +52,9 @@ executables:
52
52
  extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
+ - lib/mtm/config.rb
55
56
  - lib/mtm/mtm.rb
57
+ - lib/mtm/utils.rb
56
58
  - lib/mtm/version.rb
57
59
  - lib/mtm.rb
58
60
  - README.md