huginn_github_received_events_agent 0.1.10

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 76b54d8b9c96db57aafa090f428b4b6185ab1f21531d0c25d07b81b64686288a
4
+ data.tar.gz: 70bd1e0211045a9008b58f8a369bf9cc83f9ffb8ad5b4da904db4baa0736af5a
5
+ SHA512:
6
+ metadata.gz: d65c02d18af68f4f9c42a62bff5da5cdca9352554b1abe6e8cce895be55209757daa0024fba1cbbd7fb5ed2b7bcbec0454b93a44e882cabeff3f231e1c7d5ba4
7
+ data.tar.gz: f6c11679823ad279c080edaea2b64f36dd07b9f44fe29dc3d45e5c8125162d22e5a7880304238aea00c3e0cd11f819b752061043e77b30a87f8ca54bea14162c
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2020 Nicolas Germain
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,167 @@
1
+ module Agents
2
+ class GithubReceivedEventsAgent < Agent
3
+ include FormConfigurable
4
+ can_dry_run!
5
+ no_bulk_receive!
6
+ default_schedule 'every_1h'
7
+
8
+ description do
9
+ <<-MD
10
+ The Github notification agent fetches notifications and creates an event by notification.
11
+
12
+ `username` for the wanted username.
13
+
14
+ `token` If you are authenticated as the given user, you will see private events.
15
+
16
+ `debug` is used for verbose mode.
17
+
18
+ The `changes only` option causes the Agent to report an event only when the status changes. If set to false, an event will be created for every check. If set to true, an event will only be created when the status changes (like if your site goes from 200 to 500).
19
+
20
+ `expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
21
+ that you anticipate passing without this Agent receiving an incoming Event.
22
+ MD
23
+ end
24
+
25
+ event_description <<-MD
26
+ Events look like this:
27
+
28
+ {
29
+ "id": "XXXXXXXXXXX",
30
+ "type": "WatchEvent",
31
+ "actor": {
32
+ "id": XXXXXX,
33
+ "login": "XXXXXX",
34
+ "display_login": "XXXXXX",
35
+ "gravatar_id": "",
36
+ "url": "https://api.github.com/users/XXXXXX",
37
+ "avatar_url": "https://avatars.githubusercontent.com/u/XXXXXX?"
38
+ },
39
+ "repo": {
40
+ "id": 76460706,
41
+ "name": "hihouhou/docker-sslscan",
42
+ "url": "https://api.github.com/repos/hihouhou/docker-sslscan"
43
+ },
44
+ "payload": {
45
+ "action": "started"
46
+ },
47
+ "public": true,
48
+ "created_at": "2020-10-06T08:55:11Z"
49
+ }
50
+ MD
51
+
52
+ def default_options
53
+ {
54
+ 'username' => '',
55
+ 'debug' => 'false',
56
+ 'changes_only' => 'true',
57
+ 'expected_receive_period_in_days' => '2',
58
+ 'token' => ''
59
+ }
60
+ end
61
+
62
+ form_configurable :username, type: :string
63
+ form_configurable :changes_only, type: :boolean
64
+ form_configurable :debug, type: :boolean
65
+ form_configurable :token, type: :string
66
+ form_configurable :expected_receive_period_in_days, type: :string
67
+
68
+ def validate_options
69
+ unless options['username'].present?
70
+ errors.add(:base, "username is a required field")
71
+ end
72
+
73
+ if options.has_key?('debug') && boolify(options['debug']).nil?
74
+ errors.add(:base, "if provided, debug must be true or false")
75
+ end
76
+
77
+ unless options['token'].present?
78
+ errors.add(:base, "token is a required field")
79
+ end
80
+
81
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
82
+ errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
83
+ end
84
+ end
85
+
86
+ def working?
87
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
88
+ end
89
+
90
+ def check
91
+ fetch
92
+ end
93
+
94
+ private
95
+
96
+ def log_curl_output(code,body)
97
+
98
+ log "request status : #{code}"
99
+
100
+ if interpolated['debug'] == 'true'
101
+ log "body"
102
+ log body
103
+ end
104
+
105
+ end
106
+
107
+ def fetch
108
+ uri = URI.parse("https://api.github.com/users/hihouhou/received_events")
109
+ request = Net::HTTP::Get.new(uri)
110
+ request["Authorization"] = "#{interpolated['token']}"
111
+
112
+ req_options = {
113
+ use_ssl: uri.scheme == "https",
114
+ }
115
+
116
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
117
+ http.request(request)
118
+ end
119
+
120
+ log_curl_output(response.code,response.body)
121
+
122
+ payload = JSON.parse(response.body)
123
+
124
+ if interpolated['changes_only'] == 'true' && !payload.empty?
125
+ if payload != memory['last_status']
126
+ if payload
127
+ payload.each do |event|
128
+ found = false
129
+ if interpolated['debug'] == 'true'
130
+ log "found is #{found}!"
131
+ log event
132
+ end
133
+ if !memory['last_status'].nil? && !memory['last_status'].empty?
134
+ last_status = memory['last_status']
135
+ last_status.each do |eventbis|
136
+ if event == eventbis
137
+ found = true
138
+ end
139
+ if interpolated['debug'] == 'true'
140
+ log "found is #{found}!"
141
+ end
142
+ end
143
+ end
144
+ if found == false
145
+ if interpolated['debug'] == 'true'
146
+ log "found is #{found}! so event created"
147
+ log event
148
+ end
149
+ create_event payload: event
150
+ end
151
+ end
152
+ end
153
+ else
154
+ log "no diff"
155
+ end
156
+ memory['last_status'] = payload
157
+ else
158
+ if !payload.empty?
159
+ create_event payload: payload
160
+ if payload != memory['last_status']
161
+ memory['last_status'] = payload
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_github_received_events_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_github_received_events_agent/github_received_events_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::GithubReceivedEventsAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::GithubReceivedEventsAgent.new.default_options
7
+ @checker = Agents::GithubReceivedEventsAgent.new(:name => "GithubReceivedEventsAgent", :options => @valid_options)
8
+ @checker.user = users(:bob)
9
+ @checker.save!
10
+ end
11
+
12
+ pending "add specs here"
13
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_github_received_events_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Germain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: huginn_agent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write a longer description or delete this line.
56
+ email:
57
+ - ngermain@hihouhou.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - lib/huginn_github_received_events_agent.rb
64
+ - lib/huginn_github_received_events_agent/github_received_events_agent.rb
65
+ - spec/github_received_events_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_github_received_events_agent
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Write a short summary, because Rubygems requires one.
89
+ test_files:
90
+ - spec/github_received_events_agent_spec.rb