bas 1.5.3 → 1.6.0
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +92 -50
- data/lib/bas/bot/base.rb +37 -54
- data/lib/bas/shared_storage/base.rb +35 -0
- data/lib/bas/shared_storage/default.rb +18 -0
- data/lib/bas/shared_storage/postgres.rb +95 -0
- data/lib/bas/shared_storage/types/read.rb +22 -0
- data/lib/bas/utils/openai/run_assistant.rb +1 -0
- data/lib/bas/utils/postgres/request.rb +3 -1
- data/lib/bas/version.rb +1 -1
- metadata +8 -41
- data/lib/bas/bot/compare_wip_limit_count.rb +0 -92
- data/lib/bas/bot/create_work_item.rb +0 -142
- data/lib/bas/bot/fetch_billing_from_digital_ocean.rb +0 -87
- data/lib/bas/bot/fetch_birthdays_from_notion.rb +0 -128
- data/lib/bas/bot/fetch_domain_services_from_notion.rb +0 -93
- data/lib/bas/bot/fetch_domains_wip_counts_from_notion.rb +0 -121
- data/lib/bas/bot/fetch_domains_wip_limit_from_notion.rb +0 -134
- data/lib/bas/bot/fetch_emails_from_imap.rb +0 -99
- data/lib/bas/bot/fetch_github_issues.rb +0 -147
- data/lib/bas/bot/fetch_images_from_discord.rb +0 -78
- data/lib/bas/bot/fetch_media_from_notion.rb +0 -186
- data/lib/bas/bot/fetch_next_week_birthdays_from_notion.rb +0 -142
- data/lib/bas/bot/fetch_next_week_ptos_from_notion.rb +0 -197
- data/lib/bas/bot/fetch_ptos_from_notion.rb +0 -160
- data/lib/bas/bot/format_birthdays.rb +0 -97
- data/lib/bas/bot/format_do_bill_alert.rb +0 -108
- data/lib/bas/bot/format_emails.rb +0 -124
- data/lib/bas/bot/format_wip_limit_exceeded.rb +0 -97
- data/lib/bas/bot/garbage_collector.rb +0 -85
- data/lib/bas/bot/humanize_pto.rb +0 -117
- data/lib/bas/bot/notify_discord.rb +0 -96
- data/lib/bas/bot/notify_do_bill_alert_email.rb +0 -94
- data/lib/bas/bot/review_domain_availability.rb +0 -96
- data/lib/bas/bot/review_media.rb +0 -139
- data/lib/bas/bot/update_review_media_state.rb +0 -102
- data/lib/bas/bot/update_work_item.rb +0 -181
- data/lib/bas/bot/verify_issue_existance_in_notion.rb +0 -131
- data/lib/bas/bot/write_domain_review_requests.rb +0 -104
- data/lib/bas/bot/write_media_review_in_discord.rb +0 -98
- data/lib/bas/bot/write_media_review_requests.rb +0 -104
- data/lib/bas/read/base.rb +0 -30
- data/lib/bas/read/default.rb +0 -16
- data/lib/bas/read/postgres.rb +0 -44
- data/lib/bas/read/types/response.rb +0 -18
- data/lib/bas/write/base.rb +0 -31
- data/lib/bas/write/postgres.rb +0 -45
- data/lib/bas/write/postgres_update.rb +0 -49
@@ -1,98 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
require_relative "./base"
|
6
|
-
require_relative "../read/postgres"
|
7
|
-
require_relative "../write/postgres"
|
8
|
-
require_relative "../utils/discord/request"
|
9
|
-
|
10
|
-
module Bot
|
11
|
-
##
|
12
|
-
# The Bot::WriteMediaReviewInDiscord class serves as a bot implementation to read from a postgres
|
13
|
-
# shared storage images object blocks and send them to a thread of Discord channel
|
14
|
-
#
|
15
|
-
# <br>
|
16
|
-
# <b>Example</b>
|
17
|
-
#
|
18
|
-
# options = {
|
19
|
-
# read_options: {
|
20
|
-
# connection: {
|
21
|
-
# host: "localhost",
|
22
|
-
# port: 5432,
|
23
|
-
# dbname: "bas",
|
24
|
-
# user: "postgres",
|
25
|
-
# password: "postgres"
|
26
|
-
# },
|
27
|
-
# db_table: "review_media",
|
28
|
-
# tag: "FormatMediaReview"
|
29
|
-
# },
|
30
|
-
# process_options: {
|
31
|
-
# secret_token: "discord_bot_token"
|
32
|
-
# },
|
33
|
-
# write_options: {
|
34
|
-
# connection: {
|
35
|
-
# host: "localhost",
|
36
|
-
# port: 5432,
|
37
|
-
# dbname: "bas",
|
38
|
-
# user: "postgres",
|
39
|
-
# password: "postgres"
|
40
|
-
# },
|
41
|
-
# db_table: "review_media",
|
42
|
-
# tag: "WriteMediaReviewInDiscord"
|
43
|
-
# }
|
44
|
-
# }
|
45
|
-
#
|
46
|
-
# bot = Bot::WriteMediaReviewInDiscord.new(options)
|
47
|
-
# bot.execute
|
48
|
-
#
|
49
|
-
class WriteMediaReviewInDiscord < Bot::Base
|
50
|
-
# read function to execute the PostgresDB Read component
|
51
|
-
#
|
52
|
-
def read
|
53
|
-
reader = Read::Postgres.new(read_options.merge(conditions))
|
54
|
-
|
55
|
-
reader.execute
|
56
|
-
end
|
57
|
-
|
58
|
-
# process function to execute the Discord utility to send image feedback to a thread of a Discord channel
|
59
|
-
#
|
60
|
-
def process
|
61
|
-
return { success: { review_added: nil } } if unprocessable_response
|
62
|
-
|
63
|
-
response = Utils::Discord::Request.split_paragraphs(params)
|
64
|
-
|
65
|
-
if !response.empty?
|
66
|
-
{ success: { message_id: read_response.data["message_id"], property: read_response.data["property"] } }
|
67
|
-
else
|
68
|
-
{ error: { message: "Response is empty" } }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# write function to execute the PostgresDB write component
|
73
|
-
#
|
74
|
-
def write
|
75
|
-
write = Write::Postgres.new(write_options, process_response)
|
76
|
-
|
77
|
-
write.execute
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def conditions
|
83
|
-
{
|
84
|
-
where: "archived=$1 AND tag=$2 AND stage=$3 ORDER BY inserted_at ASC",
|
85
|
-
params: [false, read_options[:tag], "unprocessed"]
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
def params
|
90
|
-
{
|
91
|
-
body: read_response.data["review"],
|
92
|
-
secret_token: process_options[:secret_token],
|
93
|
-
message_id: read_response.data["message_id"],
|
94
|
-
channel_id: read_response.data["channel_id"]
|
95
|
-
}
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./base"
|
4
|
-
require_relative "../read/postgres"
|
5
|
-
require_relative "../utils/notion/update_db_state"
|
6
|
-
require_relative "../write/postgres"
|
7
|
-
|
8
|
-
module Bot
|
9
|
-
##
|
10
|
-
# The Bot::WriteMediaReviewRequests class serves as a bot implementation to read from a postgres
|
11
|
-
# shared storage a set of review media requests and create single request on the shared storage to
|
12
|
-
# be processed one by one.
|
13
|
-
#
|
14
|
-
# <br>
|
15
|
-
# <b>Example</b>
|
16
|
-
#
|
17
|
-
# options = {
|
18
|
-
# read_options: {
|
19
|
-
# connection: {
|
20
|
-
# host: "localhost",
|
21
|
-
# port: 5432,
|
22
|
-
# dbname: "bas",
|
23
|
-
# user: "postgres",
|
24
|
-
# password: "postgres"
|
25
|
-
# },
|
26
|
-
# db_table: "review_images",
|
27
|
-
# tag: "FetchMediaFromDiscord"
|
28
|
-
# },
|
29
|
-
# process_options: {
|
30
|
-
# connection: {
|
31
|
-
# host: "localhost",
|
32
|
-
# port: 5432,
|
33
|
-
# dbname: "bas",
|
34
|
-
# user: "postgres",
|
35
|
-
# password: "postgres"
|
36
|
-
# },
|
37
|
-
# db_table: "review_images",
|
38
|
-
# tag: "ReviewMediaRequest"
|
39
|
-
# },
|
40
|
-
# write_options: {
|
41
|
-
# connection: {
|
42
|
-
# host: "localhost",
|
43
|
-
# port: 5432,
|
44
|
-
# dbname: "bas",
|
45
|
-
# user: "postgres",
|
46
|
-
# password: "postgres"
|
47
|
-
# },
|
48
|
-
# db_table: "review_images",
|
49
|
-
# tag: "WriteMediaReviewRequests"
|
50
|
-
# }
|
51
|
-
# }
|
52
|
-
#
|
53
|
-
# bot = Bot::WriteMediaReviewRequests.new(options)
|
54
|
-
# bot.execute
|
55
|
-
#
|
56
|
-
class WriteMediaReviewRequests < Bot::Base
|
57
|
-
# read function to execute the PostgresDB Read component
|
58
|
-
#
|
59
|
-
def read
|
60
|
-
reader = Read::Postgres.new(read_options.merge(conditions))
|
61
|
-
|
62
|
-
reader.execute
|
63
|
-
end
|
64
|
-
|
65
|
-
# Process function to execute the Discord utility create single review requests
|
66
|
-
#
|
67
|
-
def process
|
68
|
-
return { success: { created: nil } } if unprocessable_response
|
69
|
-
|
70
|
-
read_response.data["results"].each { |request| create_request(request) }
|
71
|
-
|
72
|
-
{ success: { created: true } }
|
73
|
-
end
|
74
|
-
|
75
|
-
# Write function to execute the PostgresDB write component
|
76
|
-
#
|
77
|
-
def write
|
78
|
-
write = Write::Postgres.new(write_options, process_response)
|
79
|
-
|
80
|
-
write.execute
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def conditions
|
86
|
-
{
|
87
|
-
where: "archived=$1 AND tag=$2 AND stage=$3 ORDER BY inserted_at ASC",
|
88
|
-
params: [false, read_options[:tag], "unprocessed"]
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
def create_request(request)
|
93
|
-
write_data = write_request(request)
|
94
|
-
|
95
|
-
Write::Postgres.new(process_options, write_data).execute
|
96
|
-
end
|
97
|
-
|
98
|
-
def write_request(request)
|
99
|
-
return { error: request } if request["media"].empty? || !request["error"].nil?
|
100
|
-
|
101
|
-
{ success: request }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/bas/read/base.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../utils/exceptions/function_not_implemented"
|
4
|
-
|
5
|
-
module Read
|
6
|
-
##
|
7
|
-
# The Read::Base class serves as the foundation for implementing specific data read components within
|
8
|
-
# the Read module. Operating as an interface, this class defines essential attributes and methods,
|
9
|
-
# providing a blueprint for creating custom read components tailored to different data sources.
|
10
|
-
#
|
11
|
-
class Base
|
12
|
-
attr_reader :config
|
13
|
-
|
14
|
-
# Initializes the read with essential configuration parameters.
|
15
|
-
#
|
16
|
-
def initialize(config = {})
|
17
|
-
@config = config
|
18
|
-
end
|
19
|
-
|
20
|
-
# A method meant to execute the read request from an specific <b>common storage</b>.
|
21
|
-
# Must be overridden by subclasses, with specific logic based on the storage source.
|
22
|
-
#
|
23
|
-
# <br>
|
24
|
-
# <b>raises</b> <tt>Utils::Exceptions::FunctionNotImplemented</tt> when missing implementation.
|
25
|
-
#
|
26
|
-
def execute
|
27
|
-
raise Utils::Exceptions::FunctionNotImplemented
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/bas/read/default.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./base"
|
4
|
-
require_relative "./types/response"
|
5
|
-
|
6
|
-
module Read
|
7
|
-
##
|
8
|
-
# This class is an implementation of the Read::Base interface, specifically designed
|
9
|
-
# for bots who don't read from a <b>common storage</b>".
|
10
|
-
#
|
11
|
-
class Default < Read::Base
|
12
|
-
def execute
|
13
|
-
Read::Types::Response.new
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/bas/read/postgres.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
require_relative "./base"
|
6
|
-
require_relative "../utils/postgres/request"
|
7
|
-
require_relative "./types/response"
|
8
|
-
|
9
|
-
module Read
|
10
|
-
##
|
11
|
-
# This class is an implementation of the Read::Base interface, specifically designed
|
12
|
-
# to read from a PostgresDB used as <b>common storage</b>.
|
13
|
-
#
|
14
|
-
class Postgres < Read::Base
|
15
|
-
# Execute the Postgres utility to read data from the <b>common storage</b>
|
16
|
-
#
|
17
|
-
def execute
|
18
|
-
response = Utils::Postgres::Request.execute(params)
|
19
|
-
|
20
|
-
unless response.values == []
|
21
|
-
id = response.values.first[0]
|
22
|
-
data = JSON.parse(response.values.first[1])
|
23
|
-
inserted_at = response.values.first[2]
|
24
|
-
end
|
25
|
-
|
26
|
-
Read::Types::Response.new(id, data, inserted_at)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def params
|
32
|
-
{
|
33
|
-
connection: config[:connection],
|
34
|
-
query: build_query
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def build_query
|
39
|
-
query = "SELECT id, data, inserted_at FROM #{config[:db_table]} WHERE status='success' AND #{config[:where]}"
|
40
|
-
|
41
|
-
[query, config[:params]]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Read
|
4
|
-
module Types
|
5
|
-
##
|
6
|
-
# Represents a response from a read component. It encapsulates the requested data
|
7
|
-
# from the <b>common storage</b> to be processed by a Bot.
|
8
|
-
class Response
|
9
|
-
attr_reader :id, :data, :inserted_at
|
10
|
-
|
11
|
-
def initialize(id = nil, response = {}, inserted_at = nil)
|
12
|
-
@id = id
|
13
|
-
@data = response
|
14
|
-
@inserted_at = inserted_at
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/bas/write/base.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../utils/exceptions/function_not_implemented"
|
4
|
-
|
5
|
-
module Write
|
6
|
-
##
|
7
|
-
# The Write::Base class serves as the foundation for implementing specific data write components within
|
8
|
-
# the Write module. Operating as an interface, this class defines essential attributes and methods,
|
9
|
-
# providing a blueprint for creating custom write components tailored to different data storages.
|
10
|
-
#
|
11
|
-
class Base
|
12
|
-
attr_reader :config, :process_response
|
13
|
-
|
14
|
-
# Initializes the write with essential configuration parameters.
|
15
|
-
#
|
16
|
-
def initialize(config, process_response = nil)
|
17
|
-
@config = config
|
18
|
-
@process_response = process_response
|
19
|
-
end
|
20
|
-
|
21
|
-
# A method meant to execute the write request to an specific <b>common storage</b>.
|
22
|
-
# Must be overridden by subclasses, with specific logic based on the storage destination.
|
23
|
-
#
|
24
|
-
# <br>
|
25
|
-
# <b>raises</b> <tt>Utils::Exceptions::FunctionNotImplemented</tt> when missing implementation.
|
26
|
-
#
|
27
|
-
def execute
|
28
|
-
raise Utils::Exceptions::FunctionNotImplemented
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/bas/write/postgres.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./base"
|
4
|
-
require_relative "../version"
|
5
|
-
require_relative "../utils/postgres/request"
|
6
|
-
|
7
|
-
module Write
|
8
|
-
##
|
9
|
-
# This class is an implementation of the Write::Base interface, specifically designed
|
10
|
-
# to wtite to a PostgresDB used as <b>common storage</b>.
|
11
|
-
#
|
12
|
-
class Postgres < Write::Base
|
13
|
-
PTO_PARAMS = "data, tag, archived, stage, status, error_message, version"
|
14
|
-
|
15
|
-
# Execute the Postgres utility to write data in the <b>common storage</b>
|
16
|
-
#
|
17
|
-
def execute
|
18
|
-
Utils::Postgres::Request.execute(params)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def params
|
24
|
-
{
|
25
|
-
connection: config[:connection],
|
26
|
-
query: build_query
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def build_query
|
31
|
-
query = "INSERT INTO #{config[:db_table]} (#{PTO_PARAMS}) VALUES ($1, $2, $3, $4, $5, $6, $7);"
|
32
|
-
params = build_params
|
33
|
-
|
34
|
-
[query, params]
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_params
|
38
|
-
if process_response[:success]
|
39
|
-
[process_response[:success].to_json, config[:tag], false, "unprocessed", "success", nil, Bas::VERSION]
|
40
|
-
else
|
41
|
-
[nil, config[:tag], false, "unprocessed", "failed", process_response[:error].to_json, Bas::VERSION]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./base"
|
4
|
-
require_relative "../version"
|
5
|
-
require_relative "../utils/postgres/request"
|
6
|
-
|
7
|
-
module Write
|
8
|
-
##
|
9
|
-
# This class is an implementation of the Write::Base interface, specifically designed
|
10
|
-
# to update to a PostgresDB used as <b>common storage</b>.
|
11
|
-
#
|
12
|
-
class PostgresUpdate < Write::Base
|
13
|
-
PTO_PARAMS = "data, tag, archived, stage, status, version"
|
14
|
-
|
15
|
-
# Execute the Postgres utility to update data in the <b>common storage</b>
|
16
|
-
#
|
17
|
-
def execute
|
18
|
-
Utils::Postgres::Request.execute(params)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def params
|
24
|
-
{
|
25
|
-
connection: config[:connection],
|
26
|
-
query: build_query
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def build_query
|
31
|
-
params, values = build_params
|
32
|
-
query = "UPDATE #{config[:db_table]} SET #{params} WHERE #{config[:conditions]}"
|
33
|
-
|
34
|
-
[query, values]
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_params
|
38
|
-
params = ""
|
39
|
-
values = []
|
40
|
-
|
41
|
-
config[:params].each_with_index do |(param, value), idx|
|
42
|
-
params += "#{param}=$#{idx + 1}"
|
43
|
-
values << value
|
44
|
-
end
|
45
|
-
|
46
|
-
[params, values]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|