huginn_github_check_topic_agent 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1336cd7bfbbdc6c0bfc717b32c3a325323b4b9d77d50569811c38ffb27f62f09
|
4
|
+
data.tar.gz: c82e913a141d0d48aefaf402a77b64b33eb9d3f4ee030e7717a73fac5f01ae2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f83a28ba0425dc0026ebbc7d9a933735629ed7a9eefb6411484c52f06567bf20206ff89f88626dc6c4d113e1c4e8e2fc0a23ffaefae3163570f566c53b6efe6
|
7
|
+
data.tar.gz: bc77b1b26d024b0fc0001ac45b6681d52af5d008f74fd02c419f4ce1b8e8300b559670294299be0a364cc2894180b67f87a4525b6cf6eab5aa5f9a2ab932f8cc
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2022 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,181 @@
|
|
1
|
+
module Agents
|
2
|
+
class GithubCheckTopicAgent < 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 Check Topic agent agent checks if topics are present and creates an event if they are missing.
|
11
|
+
|
12
|
+
`owner` is the owner to check.
|
13
|
+
|
14
|
+
`wanted_topic` is the wanted topics list.
|
15
|
+
|
16
|
+
`regex_filter_name` is used to filter repositories with regex ( for example `^huginn_`).
|
17
|
+
|
18
|
+
`token` is mandatory for the queries .
|
19
|
+
|
20
|
+
`debug` for more verbosity .
|
21
|
+
|
22
|
+
`expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
|
23
|
+
that you anticipate passing without this Agent receiving an incoming Event.
|
24
|
+
MD
|
25
|
+
end
|
26
|
+
|
27
|
+
event_description <<-MD
|
28
|
+
Events look like this:
|
29
|
+
|
30
|
+
{
|
31
|
+
"repository_name": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
32
|
+
"url": "https://github.com/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
33
|
+
"missing_topics": "huginn, huginn-agent"
|
34
|
+
}
|
35
|
+
MD
|
36
|
+
|
37
|
+
def default_options
|
38
|
+
{
|
39
|
+
'debug' => 'false',
|
40
|
+
'expected_receive_period_in_days' => '2',
|
41
|
+
'token' => '',
|
42
|
+
'owner' => '',
|
43
|
+
'wanted_topic' => '',
|
44
|
+
'regex_filter_name' => ''
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
form_configurable :token, type: :string
|
49
|
+
form_configurable :owner, type: :string
|
50
|
+
form_configurable :regex_filter_name, type: :string
|
51
|
+
form_configurable :expected_receive_period_in_days, type: :string
|
52
|
+
form_configurable :debug, type: :boolean
|
53
|
+
form_configurable :wanted_topic, type: :string
|
54
|
+
|
55
|
+
def validate_options
|
56
|
+
unless options['token'].present?
|
57
|
+
errors.add(:base, "token is a required field")
|
58
|
+
end
|
59
|
+
|
60
|
+
unless options['owner'].present?
|
61
|
+
errors.add(:base, "owner is a required field")
|
62
|
+
end
|
63
|
+
|
64
|
+
unless options['wanted_topic'].present?
|
65
|
+
errors.add(:base, "wanted_topic is a required field")
|
66
|
+
end
|
67
|
+
|
68
|
+
if options.has_key?('debug') && boolify(options['debug']).nil?
|
69
|
+
errors.add(:base, "if provided, debug must be true or false")
|
70
|
+
end
|
71
|
+
|
72
|
+
unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
|
73
|
+
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")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def working?
|
78
|
+
event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
|
79
|
+
end
|
80
|
+
|
81
|
+
def check
|
82
|
+
fetch
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def parse(payload)
|
88
|
+
payload.each do |repository|
|
89
|
+
if repository['name'].match(interpolated['regex_filter_name'])
|
90
|
+
missing_topic = []
|
91
|
+
if interpolated['debug'] == 'true'
|
92
|
+
log "#{repository['name']} found"
|
93
|
+
end
|
94
|
+
topics_array = interpolated['wanted_topic'].split(" ")
|
95
|
+
topics_array.each do |topic|
|
96
|
+
found = 'false'
|
97
|
+
repository['topics'].each do |topicbis|
|
98
|
+
if interpolated['debug'] == 'true'
|
99
|
+
log "topic #{topic} topicbis #{topicbis}"
|
100
|
+
end
|
101
|
+
if topic == topicbis
|
102
|
+
found = 'true'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
if interpolated['debug'] == 'true'
|
106
|
+
if found == 'false'
|
107
|
+
log "topic not present"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
if found == 'false'
|
111
|
+
missing_topic.push(topic)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
if !missing_topic.empty?
|
115
|
+
log "topic not present -> #{missing_topic}"
|
116
|
+
create_event :payload => { "repository_name" => "#{repository['name']}", "url" => "#{repository['html_url']}", "missing_topics" => "#{missing_topic.join(", ")}" }
|
117
|
+
# repository['url']
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_next(url)
|
124
|
+
uri = URI.parse(url)
|
125
|
+
request = Net::HTTP::Get.new(uri)
|
126
|
+
request["Authorization"] = interpolated['token']
|
127
|
+
request["Accept"] = "application/vnd.github.mercy-preview+json"
|
128
|
+
|
129
|
+
req_options = {
|
130
|
+
use_ssl: uri.scheme == "https",
|
131
|
+
}
|
132
|
+
|
133
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
134
|
+
http.request(request)
|
135
|
+
end
|
136
|
+
|
137
|
+
log "fetch notification request status : #{response.code}"
|
138
|
+
|
139
|
+
payload = JSON.parse(response.body)
|
140
|
+
|
141
|
+
if interpolated['debug'] == 'true'
|
142
|
+
log payload
|
143
|
+
end
|
144
|
+
parse(payload)
|
145
|
+
end
|
146
|
+
|
147
|
+
def fetch
|
148
|
+
uri = URI.parse("https://api.github.com/users/#{interpolated['owner']}/repos?per_page=100")
|
149
|
+
request = Net::HTTP::Get.new(uri)
|
150
|
+
request["Authorization"] = interpolated['token']
|
151
|
+
request["Accept"] = "application/vnd.github.mercy-preview+json"
|
152
|
+
|
153
|
+
req_options = {
|
154
|
+
use_ssl: uri.scheme == "https",
|
155
|
+
}
|
156
|
+
|
157
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
158
|
+
http.request(request)
|
159
|
+
end
|
160
|
+
|
161
|
+
log "fetch notification request status : #{response.code}"
|
162
|
+
|
163
|
+
payload = JSON.parse(response.body)
|
164
|
+
|
165
|
+
if interpolated['debug'] == 'true'
|
166
|
+
log payload
|
167
|
+
end
|
168
|
+
parse(payload)
|
169
|
+
|
170
|
+
if interpolated['debug'] == 'true' && response.to_hash['link'].present?
|
171
|
+
log " link -> #{response.to_hash['link']}"
|
172
|
+
end
|
173
|
+
|
174
|
+
if response['link'].present?
|
175
|
+
URI.extract(response['link'], ['http', 'https']).each do |url|
|
176
|
+
get_next(url)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::GithubCheckTopicAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::GithubCheckTopicAgent.new.default_options
|
7
|
+
@checker = Agents::GithubCheckTopicAgent.new(:name => "GithubCheckTopicAgent", :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_check_topic_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Germain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-27 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_check_topic_agent.rb
|
64
|
+
- lib/huginn_github_check_topic_agent/github_check_topic_agent.rb
|
65
|
+
- spec/github_check_topic_agent_spec.rb
|
66
|
+
homepage: https://github.com/hihouhou/huginn_github_check_topic_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_check_topic_agent_spec.rb
|