-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified deliveries/notifiers structure
- Loading branch information
Showing
45 changed files
with
570 additions
and
753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class AdminTelegramNotifier < CompanyNotifier | ||
self.driver = proc do |data| | ||
Pullmetry::Container['api.telegram.client'].send_message( | ||
bot_secret: Rails.application.credentials.dig(:telegram_oauth, Rails.env.to_sym, :bot_secret), | ||
chat_id: data[:chat_id], | ||
text: data[:body] | ||
) | ||
end | ||
|
||
def job_execution_report | ||
notification( | ||
chat_id: Rails.application.credentials[:reports_telegram_chat_id], | ||
body: "#{params[:job_name]} is run at #{DateTime.now}" | ||
) | ||
end | ||
|
||
def feedback_created | ||
notification( | ||
chat_id: Rails.application.credentials[:reports_telegram_chat_id], | ||
body: feedback_created_payload(params[:id]) | ||
) | ||
end | ||
|
||
private | ||
|
||
def feedback_created_payload(id) | ||
feedback = Feedback.find_by(id: id) | ||
return '' unless feedback | ||
|
||
"User - #{feedback.user_id}\nFeedback created - #{feedback.title}\n#{feedback.description}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Reports | ||
module Company | ||
module Custom | ||
class LongTimeReview < Reports::Company::LongTimeReview | ||
def call(insightable:) | ||
grouped_pull_requests = grouped_pull_requests(insightable) | ||
return no_error_label(insightable) if grouped_pull_requests.empty? | ||
|
||
grouped_pull_requests.values.map do |pull_requests| | ||
{ | ||
title: title(pull_requests.first[:repositories_title]), | ||
metrics: pull_requests.map { |pull_request| metrics(pull_request) } | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def metrics(pull_request) | ||
{ | ||
pull_number: pull_request[:pull_number], | ||
in_progress_seconds: DateTime.now.to_i - pull_request[:created_at].to_i | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
app/notifiers/reports/company/custom/repository_insights.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Reports | ||
module Company | ||
module Custom | ||
class RepositoryInsights < Reports::Company::RepositoryInsights | ||
def call(insightable:) | ||
insights = insights(insightable) | ||
return no_error_label(insightable) if insights.empty? | ||
|
||
insights.map do |insight| | ||
{ | ||
title: title(insight[:repositories_title]), | ||
accessable: accessable_message(insight[:repositories_accessable]), | ||
metrics: metrics(insight) | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def metrics(insight) | ||
{ | ||
average_comment_seconds: insight[:average_comment_time].to_i, | ||
average_review_seconds: insight[:average_review_time].to_i, | ||
average_merge_seconds: insight[:average_merge_time].to_i, | ||
comments_count: insight[:comments_count].to_i, | ||
changed_loc: insight[:changed_loc].to_i, | ||
open_pull_requests_count: insight[:open_pull_requests_count].to_i | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Reports | ||
module Company | ||
module Discord | ||
class LongTimeReview < Reports::Company::LongTimeReview | ||
include Deps[time_representer: 'services.converters.seconds_to_text'] | ||
|
||
def call(insightable:) | ||
grouped_pull_requests = grouped_pull_requests(insightable) | ||
return no_error_label(insightable) if grouped_pull_requests.empty? | ||
|
||
grouped_pull_requests.values.map { |pull_requests| | ||
[ | ||
"**#{title(pull_requests.first[:repositories_title])}**", | ||
pull_requests.map { |pull_request| metrics(pull_request) }.join("\n") | ||
].join("\n") | ||
}.join("\n\n") | ||
end | ||
|
||
private | ||
|
||
def metrics(pull_request) | ||
in_progress_time = time_representer.call(value: DateTime.now.to_i - pull_request[:created_at].to_i) | ||
|
||
[ | ||
"**Pull number:** #{pull_request[:pull_number]}", | ||
"**In review time:** #{in_progress_time}" | ||
].join(', ') | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
app/notifiers/reports/company/discord/repository_insights.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Reports | ||
module Company | ||
module Discord | ||
class RepositoryInsights < Reports::Company::RepositoryInsights | ||
include Deps[time_representer: 'services.converters.seconds_to_text'] | ||
|
||
def call(insightable:) | ||
insights = insights(insightable) | ||
return no_error_label(insightable) if insights.empty? | ||
|
||
insights.map { |insight| | ||
[ | ||
"**#{title(insight[:repositories_title])}**", | ||
"**#{accessable_message(insight[:repositories_accessable])}**", | ||
metrics(insight) | ||
].join("\n") | ||
}.join("\n\n") | ||
end | ||
|
||
private | ||
|
||
# rubocop: disable Metrics/AbcSize | ||
def metrics(insight) | ||
average_comment_time = time_representer.call(value: insight[:average_comment_time].to_i) | ||
average_review_time = time_representer.call(value: insight[:average_review_time].to_i) | ||
average_merge_time = time_representer.call(value: insight[:average_merge_time].to_i) | ||
|
||
[ | ||
"**Average comment time:** #{average_comment_time}", | ||
"**Average review time:** #{average_review_time}", | ||
"**Average merge time:** #{average_merge_time}", | ||
"**Total comments:** #{insight[:comments_count].to_i}", | ||
"**Changed LOC:** #{insight[:changed_loc].to_i}", | ||
"**Open pull requests:** #{insight[:open_pull_requests_count].to_i}" | ||
].join(', ') | ||
end | ||
# rubocop: enable Metrics/AbcSize | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Reports | ||
module Company | ||
class LongTimeReview | ||
private | ||
|
||
def no_error_label(insightable) | ||
"Company #{insightable.title} doesn't have long time review" | ||
end | ||
|
||
def title(title) | ||
"Repository long time review of #{title}" | ||
end | ||
|
||
def grouped_pull_requests(insightable) | ||
insightable | ||
.pull_requests | ||
.opened | ||
.where(pull_requests: { created_at: ...(insightable.configuration.long_time_review_hours || 48).hours.ago }) | ||
.joins(:repository) | ||
.order(created_at: :asc) | ||
.hashable_pluck(:created_at, :pull_number, :repository_id, 'repositories.title') | ||
.group_by { |element| element[:repository_id] } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Reports | ||
module Company | ||
class RepositoryInsights | ||
private | ||
|
||
def no_error_label(insightable) | ||
"Company #{insightable.title} doesn't have repository insights" | ||
end | ||
|
||
def title(title) | ||
"Repository insights of #{title}" | ||
end | ||
|
||
def accessable_message(accessable) | ||
return '' if accessable | ||
|
||
'Repository has access error' | ||
end | ||
|
||
def insights(insightable) | ||
::Repositories::Insight | ||
.actual | ||
.joins(:repository) | ||
.where(repositories: { company_id: insightable.id }) | ||
.hashable_pluck( | ||
:average_comment_time, :average_review_time, :average_merge_time, | ||
:comments_count, :changed_loc, :open_pull_requests_count, | ||
'repositories.title', 'repositories.accessable' | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.