Skip to content

Commit

Permalink
improve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Mar 25, 2024
1 parent 2e697fe commit cc9a701
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 28 deletions.
18 changes: 6 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-12-20 18:20:53 UTC using RuboCop version 1.56.2.
# on 2024-03-25 17:29:24 UTC using RuboCop version 1.56.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Lint/NestedMethodDefinition:
Exclude:
- 'app/models/maintenance_contract_model.rb'

# Offense count: 4
# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 34

# Offense count: 4
# Offense count: 12
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 23

# Offense count: 3
# Offense count: 4
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Expand All @@ -31,9 +25,9 @@ Style/OptionalBooleanParameter:
- 'app/models/maintenance_contract_model.rb'
- 'app/utils/analytics/finances/models/financial_statements_of_work.rb'

# Offense count: 2
# Offense count: 9
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 124
Max: 130
12 changes: 11 additions & 1 deletion app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ class IssuesController < ApplicationController
before_action :set_project, only: %i[index]

def index
@issues = Issue.where.not(closed_date: nil).where(project: @project, closed_date: start_date..end_date)
@issues = Issue.where(project: @project)

@issues = @issues.where.not(closed_date: nil) if closed == 'true'

@issues = @issues.where(
'(closed_date BETWEEN :start_date AND :end_date) OR (reported_at BETWEEN :start_date AND :end_date)', start_date:, end_date:
)
end

private
Expand All @@ -20,4 +26,8 @@ def start_date
def end_date
params[:end_date]
end

def closed
params[:closed]
end
end
2 changes: 2 additions & 0 deletions app/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
# closed_date :datetime
# effort :float
# issue_type :string
# reported_at :datetime
# state :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# issue_id :string
# project_id :bigint not null
# tts_id :string
# user_id :bigint not null
#
# Indexes
Expand Down
19 changes: 12 additions & 7 deletions app/services/issues_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ def initialize(project)
end

def call
@project.issues.destroy_all
ActiveRecord::Base.transaction do
@project.issues.destroy_all

issues = issues_client_class.new(@project).list
issues.map do |issue|
next unless issue.user
issues = issues_client_class.new(@project).list
issues.map do |issue|
next unless issue.user

Issue.create!(project: @project, effort: issue.effort, user: issue.user, state: issue.state,
closed_date: issue.closed_date, issue_id: issue.issue_id, title: issue.title,
issue_type: issue.issue_type)
Issue.create!(project: @project, effort: issue.effort, user: issue.user, state: issue.state,
closed_date: issue.closed_date, title: issue.title,
issue_type: issue.issue_type, reported_at: issue.reported_at, tts_id: issue.tts_id)
end
end
rescue StandardError => e
Rails.logger.error("Failed to process issues due to error: #{e.message}")
raise
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/utils/clients/tts/azure/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def list
issues_list = ::Request.post(url, customer_authorization, body)
urls = issues_list['workItems'].pluck('url')
work_items = urls.map { |url| ::Request.get(url, customer_authorization) }

parsed_items = work_items.map do |work_item|
parser.new(work_item, project)
end
Expand All @@ -16,7 +17,7 @@ def list
end

def filtered_items(parsed_items)
parsed_items.select { |item| item.issue_type == 'Product Backlog Item' }
parsed_items
end

def parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def issue_type
'Task'
end

def issue_id
def reported_at
json.dig('fields', 'System.CreatedDate')
end

def tts_id
json['id'].to_s
end
end
Expand Down
6 changes: 1 addition & 5 deletions app/views/issues/_issue.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# frozen_string_literal: true

json.extract! issue, :id, :effort, :user_id, :state, :closed_date

json.user do |json|
json.partial! 'users/user', user: issue.user
end
json.extract! issue, :id, :effort, :user_id, :state, :closed_date, :title, :issue_type, :reported_at, :tts_id
7 changes: 7 additions & 0 deletions db/migrate/20240325011015_add_reported_on_to_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddReportedOnToIssues < ActiveRecord::Migration[7.0]
def change
add_column :issues, :reported_at, :datetime
end
end
7 changes: 7 additions & 0 deletions db/migrate/20240325040617_add_identifier_to_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddIdentifierToIssues < ActiveRecord::Migration[7.0]
def change
add_column :issues, :tts_id, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/factories/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
# closed_date :datetime
# effort :float
# issue_type :string
# reported_at :datetime
# state :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# issue_id :string
# project_id :bigint not null
# tts_id :string
# user_id :bigint not null
#
# Indexes
Expand Down
2 changes: 2 additions & 0 deletions spec/models/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
# closed_date :datetime
# effort :float
# issue_type :string
# reported_at :datetime
# state :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# issue_id :string
# project_id :bigint not null
# tts_id :string
# user_id :bigint not null
#
# Indexes
Expand Down

0 comments on commit cc9a701

Please sign in to comment.