Skip to content

Commit 33ebcb3

Browse files
authored
Merge pull request #294 from kortirso/issue_285
IS-285 Conventional comments tracking
2 parents 0869ad8 + e9c6271 commit 33ebcb3

25 files changed

Lines changed: 149 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8+
### Added
9+
- parsing body of comments with checking convention
10+
- rendering conventional comments count
11+
812
### Modified
913
- fetching commented and uniq accepted reviews from Github
1014
- calculating commented PRs

app/javascript/atoms/Insights/Insights.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Arrow } from '../../svg';
55
const SHORT_INSIGHT_NAMES = {
66
required_reviews_count: 'Req reviews',
77
comments_count: 'Comments',
8+
conventional_comments_count: 'Good comments',
89
reviews_count: 'Reviews',
910
bad_reviews_count: 'Bad reviews',
1011
review_involving: 'Involving',
@@ -21,6 +22,7 @@ const SHORT_INSIGHT_NAMES = {
2122
const INSIGHT_TOOLTIPS = {
2223
required_reviews_count: 'Required reviews',
2324
comments_count: 'Total comments',
25+
conventional_comments_count: 'Good comments',
2426
reviews_count: 'Total reviews',
2527
bad_reviews_count: 'Total bad reviews',
2628
review_involving: 'Review involving',

app/javascript/atoms/Insights/RepositoryInsights.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const RepositoryInsights = ({ insightTypes, insights, ratioType }) => {
8888
<div className="p-4 rounded border border-stone-200">
8989
<h4 className="mb-4">Additional stats</h4>
9090
<p>Comments - {renderRepositoryInsight('comments_count')}</p>
91+
<p>Good comments - {renderRepositoryInsight('conventional_comments_count')}</p>
9192
<p>Avg comments - {renderRepositoryInsight('average_comments_count')}</p>
9293
<p>Changed LOC - {renderRepositoryInsight('changed_loc')}</p>
9394
<p>Avg changed LOC - {renderRepositoryInsight('average_changed_loc')}</p>

app/models/insight.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Insight < ApplicationRecord
1414
SHORT_ATTRIBUTE_NAMES = {
1515
required_reviews_count: 'Required reviews',
1616
comments_count: 'Comments count',
17+
conventional_comments_count: 'Good comments',
1718
reviews_count: 'Reviews count',
1819
bad_reviews_count: 'Bad reviews count',
1920
review_involving: 'Review involving',

app/models/jsonb_columns/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Configuration
2424
%i[
2525
required_reviews_count
2626
comments_count
27+
conventional_comments_count
2728
reviews_count
2829
bad_reviews_count
2930
average_review_seconds

app/models/jsonb_columns/insight.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Insight
77
# attributes representing user reviewing
88
attribute :required_reviews_count, :boolean
99
attribute :comments_count, :boolean
10+
attribute :conventional_comments_count, :boolean
1011
attribute :reviews_count, :boolean
1112
attribute :bad_reviews_count, :boolean
1213
attribute :review_involving, :boolean

app/models/repositories/insight.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Insight < ApplicationRecord
77
DEFAULT_ATTRIBUTES = %i[
88
open_pull_requests_count commented_pull_requests_count reviewed_pull_requests_count merged_pull_requests_count
99
average_comment_time average_review_time average_merge_time
10-
comments_count average_comments_count changed_loc average_changed_loc
10+
comments_count conventional_comments_count average_comments_count changed_loc average_changed_loc
1111
].freeze
1212
REVERSE_ORDER_ATTRIBUTES = %i[average_comment_time average_review_time average_merge_time].freeze
1313
DECIMAL_ATTRIBUTES = %i[average_comments_count average_changed_loc].freeze
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Import
4+
module Concerns
5+
module CommentParseable
6+
COMMENT_MATCH_REGEXP = /\*\*(.*)\*\*\:(.*)/
7+
8+
private
9+
10+
def parse_comment_body(value)
11+
return unless value
12+
return if COMMENT_MATCH_REGEXP.match(value).nil?
13+
14+
header = value[/\*\*(.*)\*\*/, 1] # extract data between **...**
15+
{
16+
title: header.split.first,
17+
subject: value[/\*\*:(.*)/, 1].strip, # extract data after **:...
18+
decorations: header[/\((.*)\)/, 1]&.split(',')
19+
}
20+
end
21+
end
22+
end
23+
end

app/services/import/representers/github/comments.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ module Representers
55
module Github
66
class Comments
77
include Deps[entity_representer: 'services.import.representers.github.entity']
8+
include Import::Concerns::CommentParseable
89

910
def call(data:)
1011
data.map do |payload|
1112
payload = payload.with_indifferent_access
13+
# payload [:reactions] contains hash
14+
# "+1"=>0, "-1"=>0, "laugh"=>0, "hooray"=>0, "confused"=>0, "heart"=>0, "rocket"=>0, "eyes"=>0
1215
{
1316
external_id: payload[:id].to_s,
1417
comment_created_at: payload[:created_at],
15-
author: entity_representer.call(data: payload[:user])
18+
author: entity_representer.call(data: payload[:user]),
19+
parsed_body: parse_comment_body(payload[:body]&.lines&.first)
1620
}
1721
end
1822
end

app/services/import/representers/gitlab/comments.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ module Representers
55
module Gitlab
66
class Comments
77
include Deps[entity_representer: 'services.import.representers.gitlab.entity']
8+
include Import::Concerns::CommentParseable
89

910
def call(data:)
1011
data.map do |payload|
1112
payload = payload.with_indifferent_access
1213
{
1314
external_id: payload[:id].to_s,
1415
comment_created_at: payload[:created_at],
15-
author: entity_representer.call(data: payload[:author])
16+
author: entity_representer.call(data: payload[:author]),
17+
parsed_body: parse_comment_body(payload[:body]&.lines&.first)
1618
}
1719
end
1820
end

0 commit comments

Comments
 (0)