githabit 0.2.0 → 0.3.0

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: ac9303dc97c43cd6836a029bcc958b0f3b659473
4
- data.tar.gz: b4dca1dfbc88a367d4818d9b37e6df024fbc3ece
3
+ metadata.gz: 3693ae5c5c9621047ecc21a8df57c2c37814ca79
4
+ data.tar.gz: e96c70e3c28390bafe7f33e718c1a3b6f8961995
5
5
  SHA512:
6
- metadata.gz: dd51de3f4f89fa833d722240a1d2822690ad095b8941fbc899a66f1fd90bc252ef14807ac029f2deadc3c3072a2d0825a7fdad43cf769ebf4efad9ede92e7e20
7
- data.tar.gz: a2d87f3be416d747a5d35e56335b8140f237cb58e7775357a3ce2fb117424b8a4475ba78a19278de96525ea5443bcbcf389beeb04dab427396a9d385a4701112
6
+ metadata.gz: ffe42c81766b352cad25ac2e9d76281d5870197fb3223a7aea2e384a936519aa920168f3ceb4773edf94a49fa46bf849ce6cb8a239a4363d7c20dc20b6f2b207
7
+ data.tar.gz: 8621efbbac931617a25ad015fc08705ab95aef5c1fdcdbc24eac4bc4efd1f4b2b68023698301c2ee4283fa35ff293edbf9d73e6d5d2fb0f2c7b51dbf0266ebc0
data/githabit.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Morgan Kesler"]
10
10
  spec.email = ["keslerm@dasbiersec.com"]
11
11
 
12
- spec.summary = "Automatically awards for tasks in HabitRPG based on github events."
12
+ spec.summary = "Automatically awards for tasks in HabitRPG based on github events."
13
13
  spec.description = "Gamify your github work on GithabitRPG. This gem will automatically award those tasks for these events."
14
14
  spec.homepage = "https://github.com/keslerm/githabit"
15
15
  spec.license = "MIT"
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rest-client", "~> 1.8"
25
25
  spec.add_development_dependency "github_api", "~> 0.12.3"
26
+ spec.add_development_dependency "habitrpg_api", "~> 0.0.1"
26
27
  end
data/lib/githabit/app.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'pp'
3
3
  require 'githabit/github_api'
4
- require 'githabit/habitrpg_api'
4
+ require 'habitrpg'
5
5
  require 'githabit/cache'
6
6
 
7
7
  module Githabit
@@ -15,7 +15,7 @@ module Githabit
15
15
 
16
16
  # Init apis
17
17
  @log.debug("Loading APIs")
18
- @habit_api = HabitRPGAPI.new(@settings['habitrpg']['user'], @settings['habitrpg']['token'])
18
+ @habit_api = HabitRPG_API.new(@settings['habitrpg']['user'], @settings['habitrpg']['token'])
19
19
  @github_api = GithubAPI.new(@settings['github']['user'], @settings['github']['password'])
20
20
 
21
21
  # Initialize cache
@@ -72,42 +72,47 @@ module Githabit
72
72
  new_events_found = 0
73
73
 
74
74
  @log.info("Checking github for new events")
75
- events = @github_api.get_user_events(@settings['github']['monitor_user'])
76
75
 
77
- # For now only push events
78
- events.select { |e| e['type'] == 'PushEvent'}.each do |event|
79
- # We only want pushes to master branches
80
- next if event['payload']['ref'] != "refs/heads/master"
76
+ begin
77
+ events = @github_api.get_user_events(@settings['github']['monitor_user'])
78
+ # For now only push events
79
+ events.select { |e| e['type'] == 'PushEvent'}.each do |event|
80
+ # We only want pushes to master branches
81
+ next if event['payload']['ref'] != "refs/heads/master"
81
82
 
82
- # Find how many commits
83
- event['payload']['commits'].each do |commit|
83
+ # Find how many commits
84
+ event['payload']['commits'].each do |commit|
84
85
 
85
- # If already in the cache - skip it, we've already rewarded it
86
- next if @cache.cached? ("Commit:#{commit['sha']}")
86
+ # If already in the cache - skip it, we've already rewarded it
87
+ next if @cache.cached? ("Commit:#{commit['sha']}")
87
88
 
88
- @log.info("Rewarding commit: " + commit['sha'] + " to repo: " + event['repo']['name'] + " Message: " + commit['message'])
89
- @habit_api.score_task(@github_commit_task_id, 'up', nil)
89
+ @log.info("Rewarding commit: " + commit['sha'] + " to repo: " + event['repo']['name'] + " Message: " + commit['message'])
90
+ @habit_api.score_task(@github_commit_task_id, 'up', nil)
90
91
 
91
- new_events_found += 1
92
- end
92
+ new_events_found += 1
93
+ end
93
94
 
94
- @cache.cache(event)
95
+ @cache.cache(event)
95
96
 
96
- end
97
+ end
97
98
 
98
- events.select { |e| e['type'] == 'IssuesEvent'}.each do |event|
99
- next if @cache.cached? ("Issue:#{event['id']}") or event['payload']['action'] != 'closed'
99
+ events.select { |e| e['type'] == 'IssuesEvent'}.each do |event|
100
+ next if @cache.cached? ("Issue:#{event['id']}") or event['payload']['action'] != 'closed'
100
101
 
101
- @log.info("Rewarding closed issue for id: #{event['id']} Issue: #{event['payload']['issue']['title']}")
102
+ @log.info("Rewarding closed issue for id: #{event['id']} Issue: #{event['payload']['issue']['title']}")
102
103
 
103
- @habit_api.score_task(@github_issue_task_id, 'up', nil)
104
- new_events_found += 1
104
+ @habit_api.score_task(@github_issue_task_id, 'up', nil)
105
+ new_events_found += 1
105
106
 
106
- @cache.cache(event)
107
+ @cache.cache(event)
107
108
 
108
- end
109
+ end
109
110
 
110
- @log.info("Found " + new_events_found.to_s + " new events this run")
111
+ @log.info("Found " + new_events_found.to_s + " new events this run")
112
+ end
113
+ rescue => e
114
+ @log.error("There was a problem communicating with the server")
115
+ @log.error(e)
111
116
  end
112
117
  end
113
118
  end
@@ -1,3 +1,3 @@
1
1
  module Githabit
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: githabit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgan Kesler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-06-09 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: 0.12.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: habitrpg_api
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.1
69
83
  description: Gamify your github work on GithabitRPG. This gem will automatically award
70
84
  those tasks for these events.
71
85
  email:
@@ -93,7 +107,6 @@ files:
93
107
  - lib/githabit/app.rb
94
108
  - lib/githabit/cache.rb
95
109
  - lib/githabit/github_api.rb
96
- - lib/githabit/habitrpg_api.rb
97
110
  - lib/githabit/version.rb
98
111
  homepage: https://github.com/keslerm/githabit
99
112
  licenses:
@@ -115,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
128
  version: '0'
116
129
  requirements: []
117
130
  rubyforge_project:
118
- rubygems_version: 2.4.6
131
+ rubygems_version: 2.4.7
119
132
  signing_key:
120
133
  specification_version: 4
121
134
  summary: Automatically awards for tasks in HabitRPG based on github events.
@@ -1,48 +0,0 @@
1
- require 'json'
2
- require 'rest_client'
3
- require 'pp'
4
-
5
- class HabitRPGAPI
6
-
7
- def initialize(api_user, api_token)
8
- @api_user = api_user
9
- @api_token = api_token
10
- end
11
-
12
- def score_task(task_id, direction, task)
13
- post("user/tasks/#{task_id}/#{direction}", task)
14
- end
15
-
16
- def list_tasks()
17
- get("user/tasks")
18
- end
19
-
20
- def get_task(task_id)
21
- get("user/tasks/#{task_id}")
22
- end
23
-
24
- def create_task(task)
25
- post("user/tasks", task)
26
- end
27
-
28
- private
29
- def delete(url, params = nil)
30
- JSON.parse(RestClient.delete("https://habitrpg.com/api/v2/#{url}", { 'x-api-key' => @api_token, 'x-api-user' => @api_user }))
31
- end
32
-
33
- private
34
- def post(url, params = nil)
35
- JSON.parse(RestClient.put("https://habitrpg.com/api/v2/#{url}", params, { 'x-api-key' => @api_token, 'x-api-user' => @api_user }))
36
- end
37
-
38
- private
39
- def post(url, params = nil)
40
- JSON.parse(RestClient.post("https://habitrpg.com/api/v2/#{url}", params, { 'x-api-key' => @api_token, 'x-api-user' => @api_user }))
41
- end
42
-
43
- private
44
- def get(url, params = nil)
45
- JSON.parse(RestClient.get("https://habitrpg.com/api/v2/#{url}", { 'x-api-key' => @api_token, 'x-api-user' => @api_user }))
46
- end
47
- end
48
-