bas 1.4.0 → 1.4.1
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/lib/bas/bot/create_work_item.rb +7 -6
- data/lib/bas/bot/fetch_github_issues.rb +27 -5
- data/lib/bas/bot/format_do_bill_alert.rb +3 -5
- data/lib/bas/bot/update_work_item.rb +54 -5
- data/lib/bas/bot/verify_issue_existance_in_notion.rb +4 -3
- data/lib/bas/utils/notion/fetch_database_record.rb +46 -0
- data/lib/bas/utils/notion/types.rb +0 -4
- data/lib/bas/utils/notion/update_db_page.rb +44 -0
- data/lib/bas/version.rb +1 -1
- metadata +4 -3
- data/lib/bas/bot/write_github_issue_requests.rb +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b66afc50b75886393d36686a909055c677de6c84cea65580c40142487440097
|
4
|
+
data.tar.gz: 454565030fbbea5d60a54ec5f6bf7ec43f996f64ed5bc372908470a7173a09cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d6a66d745da40e8498b63eb12a2e8e006d727313c08a8924cbbf5fe960362fe6621b9059ecc430103a1bcf3740618dcfa55d3ed11f21e8b8847cb7b6767a723
|
7
|
+
data.tar.gz: ebb4c84192b579df371022608bf0195f177b8fcd9d7cbacfb03c77d724ceef8e0d25cff3281c78e92db28e3ba8deb07281fb4611608afc4bff667b65fe7e101e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 1.4.1 (12.08.2024)
|
4
|
+
- [Add github issues assignees to work items](https://github.com/kommitters/bas/issues/92)
|
5
|
+
|
3
6
|
# 1.4.0 (26.07.2024)
|
4
7
|
- [Add bots to synchronize issues with notion work items](https://github.com/kommitters/bas/issues/87)
|
5
8
|
- [Update fetch pto from notion bot](https://github.com/kommitters/bas/issues/75)
|
@@ -56,6 +56,7 @@ module Bot
|
|
56
56
|
include Utils::Notion::Types
|
57
57
|
|
58
58
|
UPDATE_REQUEST = "UpdateWorkItemRequest"
|
59
|
+
STATUS = "Backlog"
|
59
60
|
|
60
61
|
# read function to execute the PostgresDB Read component
|
61
62
|
#
|
@@ -117,17 +118,17 @@ module Bot
|
|
117
118
|
|
118
119
|
def properties # rubocop:disable Metrics/AbcSize
|
119
120
|
{
|
120
|
-
"Responsible domain": select(
|
121
|
-
"Github Issue
|
122
|
-
"Status": status(
|
121
|
+
"Responsible domain": select(read_response.data["domain"]),
|
122
|
+
"Github Issue Id": rich_text(read_response.data["issue"]["id"].to_s),
|
123
|
+
"Status": status(STATUS),
|
123
124
|
"Detail": title(read_response.data["issue"]["title"])
|
124
125
|
}.merge(work_item_type)
|
125
126
|
end
|
126
127
|
|
127
128
|
def work_item_type
|
128
|
-
case
|
129
|
-
when "activity" then { "Activity": relation(
|
130
|
-
when "project" then { "Project": relation(
|
129
|
+
case read_response.data["work_item_type"]
|
130
|
+
when "activity" then { "Activity": relation(read_response.data["type_id"]) }
|
131
|
+
when "project" then { "Project": relation(read_response.data["type_id"]) }
|
131
132
|
else {}
|
132
133
|
end
|
133
134
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "./base"
|
4
|
-
require_relative "../read/
|
4
|
+
require_relative "../read/postgres"
|
5
5
|
require_relative "../utils/github/octokit_client"
|
6
6
|
require_relative "../write/postgres"
|
7
7
|
|
@@ -32,6 +32,15 @@ module Bot
|
|
32
32
|
# repo: "repository name",
|
33
33
|
# filters: "hash with filters",
|
34
34
|
# organization: "GitHub organization name"
|
35
|
+
# connection: {
|
36
|
+
# host: "localhost",
|
37
|
+
# port: 5432,
|
38
|
+
# dbname: "bas",
|
39
|
+
# user: "postgres",
|
40
|
+
# password: "postgres"
|
41
|
+
# },
|
42
|
+
# db_table: "github_issues",
|
43
|
+
# tag: "GithubIssueRequest"
|
35
44
|
# },
|
36
45
|
# write_options: {
|
37
46
|
# connection: {
|
@@ -50,7 +59,7 @@ module Bot
|
|
50
59
|
# bot.execute
|
51
60
|
#
|
52
61
|
class FetchGithubIssues < Bot::Base
|
53
|
-
ISSUE_PARAMS = %i[id html_url title body labels state created_at updated_at].freeze
|
62
|
+
ISSUE_PARAMS = %i[id html_url title body labels state created_at updated_at state].freeze
|
54
63
|
PER_PAGE = 100
|
55
64
|
|
56
65
|
# read function to execute the PostgresDB Read component
|
@@ -69,9 +78,9 @@ module Bot
|
|
69
78
|
if octokit[:client]
|
70
79
|
repo_issues = octokit[:client].issues(@process_options[:repo], filters)
|
71
80
|
|
72
|
-
|
81
|
+
normalize_response(repo_issues).each { |issue| create_request(issue) }
|
73
82
|
|
74
|
-
{ success: {
|
83
|
+
{ success: { created: true } }
|
75
84
|
else
|
76
85
|
{ error: octokit[:error] }
|
77
86
|
end
|
@@ -107,7 +116,7 @@ module Bot
|
|
107
116
|
def filters
|
108
117
|
default_filter = { per_page: PER_PAGE }
|
109
118
|
|
110
|
-
filters =
|
119
|
+
filters = process_options[:filters]
|
111
120
|
filters = filters.merge({ since: read_response.inserted_at }) unless read_response.nil?
|
112
121
|
|
113
122
|
filters.is_a?(Hash) ? default_filter.merge(filters) : default_filter
|
@@ -121,5 +130,18 @@ module Bot
|
|
121
130
|
end
|
122
131
|
end
|
123
132
|
end
|
133
|
+
|
134
|
+
def create_request(issue)
|
135
|
+
write_data = {
|
136
|
+
success: {
|
137
|
+
issue:,
|
138
|
+
work_item_type: process_options[:work_item_type],
|
139
|
+
type_id: process_options[:type_id],
|
140
|
+
domain: process_options[:domain]
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
Write::Postgres.new(process_options, write_data).execute
|
145
|
+
end
|
124
146
|
end
|
125
147
|
end
|
@@ -93,11 +93,9 @@ module Bot
|
|
93
93
|
balance = read_response.data["billing"]["month_to_date_balance"]
|
94
94
|
threshold = process_options[:threshold]
|
95
95
|
|
96
|
-
"
|
97
|
-
Current balance: #{balance}
|
98
|
-
|
99
|
-
Current daily usage: #{daily_usage.round(3)}
|
100
|
-
"""
|
96
|
+
":warning: The **DigitalOcean** daily usage was exceeded. \
|
97
|
+
Current balance: #{balance}, Threshold: #{threshold}, \
|
98
|
+
Current daily usage: #{daily_usage.round(3)}"
|
101
99
|
end
|
102
100
|
end
|
103
101
|
end
|
@@ -8,6 +8,8 @@ require_relative "../read/postgres"
|
|
8
8
|
require_relative "../utils/notion/request"
|
9
9
|
require_relative "../utils/notion/types"
|
10
10
|
require_relative "../utils/notion/delete_page_blocks"
|
11
|
+
require_relative "../utils/notion/fetch_database_record"
|
12
|
+
require_relative "../utils/notion/update_db_page"
|
11
13
|
require_relative "../write/postgres"
|
12
14
|
|
13
15
|
module Bot
|
@@ -53,6 +55,7 @@ module Bot
|
|
53
55
|
include Utils::Notion::Types
|
54
56
|
|
55
57
|
DESCRIPTION = "Issue Description"
|
58
|
+
GITHUB_COLUMN = "Username"
|
56
59
|
|
57
60
|
# read function to execute the PostgresDB Read component
|
58
61
|
#
|
@@ -67,11 +70,11 @@ module Bot
|
|
67
70
|
def process
|
68
71
|
return { success: { updated: nil } } if unprocessable_response
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
response = Utils::Notion::Request.execute(params)
|
73
|
+
response = process_wi
|
73
74
|
|
74
75
|
if response.code == 200
|
76
|
+
update_assigness
|
77
|
+
|
75
78
|
{ success: { issue: read_response.data["issue"] } }
|
76
79
|
else
|
77
80
|
{ error: { message: response.parsed_response, status_code: response.code } }
|
@@ -95,6 +98,12 @@ module Bot
|
|
95
98
|
}
|
96
99
|
end
|
97
100
|
|
101
|
+
def process_wi
|
102
|
+
delete_wi
|
103
|
+
|
104
|
+
Utils::Notion::Request.execute(params)
|
105
|
+
end
|
106
|
+
|
98
107
|
def params
|
99
108
|
{
|
100
109
|
endpoint: "blocks/#{read_response.data["notion_wi"]}/children",
|
@@ -121,12 +130,52 @@ module Bot
|
|
121
130
|
end
|
122
131
|
|
123
132
|
def delete_wi
|
124
|
-
|
133
|
+
options = {
|
125
134
|
page_id: read_response.data["notion_wi"],
|
126
135
|
secret: process_options[:secret]
|
127
136
|
}
|
128
137
|
|
129
|
-
Utils::Notion::DeletePageBlocks.new(
|
138
|
+
Utils::Notion::DeletePageBlocks.new(options).execute
|
139
|
+
end
|
140
|
+
|
141
|
+
def update_assigness
|
142
|
+
relation = users.map { |user| user_id(user) }
|
143
|
+
|
144
|
+
options = {
|
145
|
+
page_id: read_response.data["notion_wi"],
|
146
|
+
secret: process_options[:secret],
|
147
|
+
body: { properties: { People: { relation: } }.merge(status) }
|
148
|
+
}
|
149
|
+
|
150
|
+
Utils::Notion::UpdateDatabasePage.new(options).execute
|
151
|
+
end
|
152
|
+
|
153
|
+
def users
|
154
|
+
options = {
|
155
|
+
database_id: process_options[:users_database_id],
|
156
|
+
secret: process_options[:secret],
|
157
|
+
body: { filter: { or: github_usernames } }
|
158
|
+
}
|
159
|
+
|
160
|
+
Utils::Notion::FetchDatabaseRecord.new(options).execute
|
161
|
+
end
|
162
|
+
|
163
|
+
def github_usernames
|
164
|
+
read_response.data["issue"]["assignees"].map do |username|
|
165
|
+
{ property: GITHUB_COLUMN, rich_text: { equals: username } }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def user_id(user)
|
170
|
+
relation = user.dig("properties", "People", "relation")
|
171
|
+
|
172
|
+
relation.nil? ? {} : relation.first
|
173
|
+
end
|
174
|
+
|
175
|
+
def status
|
176
|
+
return {} unless read_response.data["issue"]["state"] == "closed"
|
177
|
+
|
178
|
+
{ Status: { status: { name: "Done" } } }
|
130
179
|
end
|
131
180
|
end
|
132
181
|
end
|
@@ -50,6 +50,7 @@ module Bot
|
|
50
50
|
#
|
51
51
|
class VerifyIssueExistanceInNotion < Bot::Base
|
52
52
|
NOT_FOUND = "not found"
|
53
|
+
NOTION_PROPERTY = "Github Issue Id"
|
53
54
|
|
54
55
|
# read function to execute the PostgresDB Read component
|
55
56
|
#
|
@@ -70,7 +71,7 @@ module Bot
|
|
70
71
|
if response.code == 200
|
71
72
|
result = response.parsed_response["results"].first
|
72
73
|
|
73
|
-
{ success:
|
74
|
+
{ success: read_response.data.merge({ notion_wi: notion_wi_id(result) }) }
|
74
75
|
else
|
75
76
|
{ error: { message: response.parsed_response, status_code: response.code } }
|
76
77
|
end
|
@@ -107,8 +108,8 @@ module Bot
|
|
107
108
|
def body
|
108
109
|
{
|
109
110
|
filter: {
|
110
|
-
property:
|
111
|
-
rich_text: { equals: read_response.data["
|
111
|
+
property: NOTION_PROPERTY,
|
112
|
+
rich_text: { equals: read_response.data["issue"]["id"].to_s }
|
112
113
|
}
|
113
114
|
}
|
114
115
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
require_relative "request"
|
5
|
+
|
6
|
+
module Utils
|
7
|
+
module Notion
|
8
|
+
##
|
9
|
+
# This module is a Notion utility for fetching record from a database.
|
10
|
+
#
|
11
|
+
class FetchDatabaseRecord
|
12
|
+
# Implements the fetch page process logic to Notion.
|
13
|
+
#
|
14
|
+
# <br>
|
15
|
+
# <b>Params:</b>
|
16
|
+
# * <tt>database_id</tt> Id of the notion database.
|
17
|
+
# * <tt>secret</tt> Notion secret.
|
18
|
+
# * <tt>body</tt> Body with the filters.
|
19
|
+
#
|
20
|
+
# <br>
|
21
|
+
# <b>returns</b> <tt>HTTParty::Response</tt>
|
22
|
+
#
|
23
|
+
#
|
24
|
+
def initialize(options)
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute
|
29
|
+
records = Utils::Notion::Request.execute(params)
|
30
|
+
|
31
|
+
records.parsed_response["results"] || []
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def params
|
37
|
+
{
|
38
|
+
endpoint: "databases/#{@options[:database_id]}/query",
|
39
|
+
secret: @options[:secret],
|
40
|
+
method: "post",
|
41
|
+
body: @options[:body]
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
require_relative "request"
|
5
|
+
|
6
|
+
module Utils
|
7
|
+
module Notion
|
8
|
+
##
|
9
|
+
# This module is a Notion utility for updating database properties.
|
10
|
+
#
|
11
|
+
class UpdateDatabasePage
|
12
|
+
# Implements the update database properties process logic to Notion.
|
13
|
+
#
|
14
|
+
# <br>
|
15
|
+
# <b>Params:</b>
|
16
|
+
# * <tt>page_id</tt> Id of the notion page.
|
17
|
+
# * <tt>secret</tt> Notion secret.
|
18
|
+
# * <tt>body</tt> Request body with the properties to be updated.
|
19
|
+
#
|
20
|
+
# <br>
|
21
|
+
# <b>returns</b> <tt>HTTParty::Response</tt>
|
22
|
+
#
|
23
|
+
#
|
24
|
+
def initialize(options)
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute
|
29
|
+
Utils::Notion::Request.execute(params)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def params
|
35
|
+
{
|
36
|
+
endpoint: "pages/#{@options[:page_id]}",
|
37
|
+
secret: @options[:secret],
|
38
|
+
method: "patch",
|
39
|
+
body: @options[:body]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/bas/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kommitters Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gmail_xoauth
|
@@ -213,7 +213,6 @@ files:
|
|
213
213
|
- lib/bas/bot/update_work_item.rb
|
214
214
|
- lib/bas/bot/verify_issue_existance_in_notion.rb
|
215
215
|
- lib/bas/bot/write_domain_review_requests.rb
|
216
|
-
- lib/bas/bot/write_github_issue_requests.rb
|
217
216
|
- lib/bas/bot/write_media_review_in_notion.rb
|
218
217
|
- lib/bas/bot/write_media_review_requests.rb
|
219
218
|
- lib/bas/read/base.rb
|
@@ -228,8 +227,10 @@ files:
|
|
228
227
|
- lib/bas/utils/google/send_email.rb
|
229
228
|
- lib/bas/utils/imap/request.rb
|
230
229
|
- lib/bas/utils/notion/delete_page_blocks.rb
|
230
|
+
- lib/bas/utils/notion/fetch_database_record.rb
|
231
231
|
- lib/bas/utils/notion/request.rb
|
232
232
|
- lib/bas/utils/notion/types.rb
|
233
|
+
- lib/bas/utils/notion/update_db_page.rb
|
233
234
|
- lib/bas/utils/notion/update_db_state.rb
|
234
235
|
- lib/bas/utils/openai/run_assistant.rb
|
235
236
|
- lib/bas/utils/postgres/request.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./base"
|
4
|
-
require_relative "../read/postgres"
|
5
|
-
require_relative "../write/postgres"
|
6
|
-
|
7
|
-
module Bot
|
8
|
-
##
|
9
|
-
# The Bot::WriteGithubIssueRequests class serves as a bot implementation to write GitHub issues
|
10
|
-
# request to be sent individually.
|
11
|
-
#
|
12
|
-
# <br>
|
13
|
-
# <b>Example</b>
|
14
|
-
#
|
15
|
-
# options = {
|
16
|
-
# read_options: {
|
17
|
-
# connection: {
|
18
|
-
# host: "localhost",
|
19
|
-
# port: 5432,
|
20
|
-
# dbname: "bas",
|
21
|
-
# user: "postgres",
|
22
|
-
# password: "postgres"
|
23
|
-
# },
|
24
|
-
# db_table: "github_issues",
|
25
|
-
# tag: "FetchGithubIssues"
|
26
|
-
# },
|
27
|
-
# process_options: {
|
28
|
-
# connection: {
|
29
|
-
# host: "localhost",
|
30
|
-
# port: 5432,
|
31
|
-
# dbname: "bas",
|
32
|
-
# user: "postgres",
|
33
|
-
# password: "postgres"
|
34
|
-
# },
|
35
|
-
# db_table: "github_issues",
|
36
|
-
# tag: "GithubIssueRequest"
|
37
|
-
# },
|
38
|
-
# write_options: {
|
39
|
-
# connection: {
|
40
|
-
# host: "localhost",
|
41
|
-
# port: 5432,
|
42
|
-
# dbname: "bas",
|
43
|
-
# user: "postgres",
|
44
|
-
# password: "postgres"
|
45
|
-
# },
|
46
|
-
# db_table: "github_issues",
|
47
|
-
# tag: "WriteGithubIssueRequests"
|
48
|
-
# }
|
49
|
-
# }
|
50
|
-
#
|
51
|
-
# bot = Bot::WriteGithubIssueRequests.new(options)
|
52
|
-
# bot.execute
|
53
|
-
#
|
54
|
-
class WriteGithubIssueRequests < Bot::Base
|
55
|
-
# read function to execute the PostgresDB Read component
|
56
|
-
#
|
57
|
-
def read
|
58
|
-
reader = Read::Postgres.new(read_options.merge(conditions))
|
59
|
-
|
60
|
-
reader.execute
|
61
|
-
end
|
62
|
-
|
63
|
-
# Process function to write GitHub issues requests.
|
64
|
-
#
|
65
|
-
def process
|
66
|
-
return { success: { created: nil } } if unprocessable_response
|
67
|
-
|
68
|
-
read_response.data["issues"].each { |request| create_request(request) }
|
69
|
-
|
70
|
-
{ success: { created: true } }
|
71
|
-
end
|
72
|
-
|
73
|
-
# Write function to execute the PostgresDB write component
|
74
|
-
#
|
75
|
-
def write
|
76
|
-
write = Write::Postgres.new(write_options, process_response)
|
77
|
-
|
78
|
-
write.execute
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
def conditions
|
84
|
-
{
|
85
|
-
where: "archived=$1 AND tag=$2 AND stage=$3 ORDER BY inserted_at ASC",
|
86
|
-
params: [false, read_options[:tag], "unprocessed"]
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
def create_request(request)
|
91
|
-
write_data = { success: { request: } }
|
92
|
-
|
93
|
-
Write::Postgres.new(process_options, write_data).execute
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|