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 e68ca84
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 19 deletions.
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)

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

@issues = @issues.where("(closed_date BETWEEN :start_date AND :end_date) OR (reported_at BETWEEN :start_date AND :end_date)", start_date: start_date, end_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
5 changes: 4 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,8 @@ 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) }
Rails.logger.debug(work_items.size)

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

def filtered_items(parsed_items)
parsed_items.select { |item| item.issue_type == 'Product Backlog Item' }
# 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
5 changes: 2 additions & 3 deletions app/workers/project_issues_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class ProjectIssuesWorker
include Sidekiq::Worker

def perform(project_name)
project = Project.find_by(name: project_name)
IssuesCreator.call(project)
def perform(_project_name)
reload!; project = Project.find_by(name: 'Donor Direct') ;IssuesCreator.call(project)
end
end
5 changes: 5 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,5 @@
class AddReportedOnToIssues < ActiveRecord::Migration[7.0]
def change
add_column :issues, :reported_at, :datetime
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240325040617_add_identifier_to_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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 e68ca84

Please sign in to comment.