scrumship-client 1.0.13 → 1.0.14

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
  SHA256:
3
- metadata.gz: 593c0086c8c866117eb2db3586b29e5b215954a116ca9088dcf7a259eda147bd
4
- data.tar.gz: 3c15452b285504bac9af84acf4f87bb5cf59ac26ff67622e1cf18dc2088518bb
3
+ metadata.gz: e90d90da1b4c725e50d3bf12307b0aa7b61d7c2ac02d25a5b1ccafca5ff2e197
4
+ data.tar.gz: 83933ef49300f2a949a1305706771cf09db1b22d43d7e4154f5c317effd37b58
5
5
  SHA512:
6
- metadata.gz: 30a4b9f9582687f67b5ceafbe4e0d9fd61ad5531c9bb47f5ae629f415feca9f7f05d49150d4d7ce39e0ec23e9a012ea6c804ad4b7326fbcf0633a9d64f21b933
7
- data.tar.gz: 9641df33c38a520b5ee3de31359089d6798261657d6fa2d52210a95f5f215869bd153231ca5213f317dfd97cb1e67b225ba7978dd100d2695a0f797711cf3dc0
6
+ metadata.gz: 710d9dd747086f611c19b6df3fdcfa55a5bb48de28d557250993174787d3fc9732663efb1b101493d0a8b8cde2184987aefe4460dc1e483b539378fd67f0143e
7
+ data.tar.gz: f20f7ae601cad09f3b2d9eb650ce83acd1e85ef3321d19bd2082a8f20b7a96eef8523aaf01b7012c1c818ab96d4aeb9ce9f096d0b3f7f5a408a6ee1e0e900e0c
@@ -1,5 +1,3 @@
1
1
  module Scrumship
2
- module Client
3
- VERSION = "1.0.13"
4
- end
2
+ VERSION = "1.0.14"
5
3
  end
@@ -3,63 +3,50 @@ require 'net/http'
3
3
  require 'json'
4
4
 
5
5
  module Scrumship
6
- class Configuration
7
- attr_accessor :config_file
8
- attr_accessor :activity_log_url
9
- attr_accessor :project_token
10
- attr_accessor :activity_token
11
-
12
- def initialize
13
- @activity_log_url = 'https://app.scrumship.com/api/ac'
14
- @config_file = 'scrumship.json'
15
- end
16
- end
17
6
 
18
7
  module Client
19
8
 
20
- def self.configure
21
- yield(configuration)
22
- ScrumshipClient::Client.setup
23
- if Rails.configuration.cache_classes
24
- ScrumshipClient::Client.log
9
+ def self.log(activity_token, config_file = 'scrumship.json')
10
+ if defined?(Rails) && Rails.configuration.cache_classes
11
+ Scrumship::Client.do_log(activity_token, config_file)
25
12
  else
26
13
  if defined?(ActiveSupport::Reloader)
27
14
  ActiveSupport::Reloader.to_prepare do
28
- ScrumshipClient::Client.log
15
+ Scrumship::Client.do_log(activity_token, config_file)
29
16
  end
30
17
  elsif defined?(ActionDispatch::Reloader)
31
18
  ActionDispatch::Reloader.to_prepare do
32
- ScrumshipClient::Client.log
19
+ Scrumship::Client.do_log(activity_token, config_file)
33
20
  end
34
21
  end
35
22
  end
36
23
  end
37
24
 
38
- def self.setup(configuration = Configuration.new)
25
+ def self.setup(project_token, activity_log_url = 'https://app.scrumship.com/api/ac', config_file = 'scrumship.json')
39
26
  begin
40
- username = `git config user.name`
41
- username = username.gsub('\n', '').strip!
42
- url = "#{configuration.activity_log_url}/e/#{configuration.project_token}"
27
+ username = git_command('git config user.name').gsub('\n', '').strip!
28
+ email = git_command('git config user.email').gsub('\n', '').strip!
29
+ url = "#{activity_log_url}/e/#{project_token}"
43
30
  http = client(url)
44
31
  uri = URI.parse(url)
45
32
  req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
46
- req.body = { username: username }.to_json
33
+ req.body = { username: username, email: email }.to_json
47
34
  res = http.request(req)
48
35
 
49
36
  json_res = JSON.parse(res.body)
50
37
  if json_res["status"] == 200
51
- config = { u: json_res["token"], url: configuration.activity_log_url, pt: configuration.project_token }
52
- File.open(configuration.config_file, 'w') { |file| file.write(config.to_json) }
38
+ config = { u: json_res["token"], url: activity_log_url, pt: project_token }
39
+ File.open(config_file, 'w') { |file| file.write(config.to_json) }
53
40
  end
54
41
  rescue
55
42
  # Ignored
56
43
  end
57
44
  end
58
45
 
59
- def self.log
46
+ def self.do_log(activity_token, config_file)
60
47
  begin
61
- token = JSON.parse(File.read(configuration.config_file)).symbolize_keys[:u]
62
- url = "#{configuration.activity_log_url}/#{configuration.project_token}/#{configuration.activity_token}/#{token}"
48
+ config = JSON.parse(File.read(config_file)).symbolize_keys
49
+ url = "#{config[:activity_log_url]}/#{config[:pt]}/#{activity_token}/#{config[:u]}"
63
50
  http = client(url)
64
51
  http.get(url)
65
52
  rescue
@@ -75,5 +62,20 @@ module Scrumship
75
62
  http
76
63
  end
77
64
 
65
+ def self.git_command(command)
66
+ begin
67
+ result = `#{command}`
68
+ if result == ""
69
+ raise Exception
70
+ end
71
+ result
72
+ rescue
73
+ puts "Please set up your git user and git user email: " +
74
+ "\n git config --global user.name \"Your Username\"" +
75
+ "\n git config --global user.email \"email@example.com\""
76
+ exit 1
77
+ end
78
+ end
79
+
78
80
  end
79
81
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'scrumship-client'
3
- s.version = '1.0.13'
3
+ s.version = '1.0.14'
4
4
  s.date = '2021-12-04'
5
5
  s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
6
6
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrumship-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Dymek