diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 30235ab..60a143c 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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 @@ -20,4 +26,8 @@ def start_date def end_date params[:end_date] end + + def closed + params[:closed] + end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 1e415f2..82a46b2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/app/services/issues_creator.rb b/app/services/issues_creator.rb index 0499033..f84bc5e 100644 --- a/app/services/issues_creator.rb +++ b/app/services/issues_creator.rb @@ -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 diff --git a/app/utils/clients/tts/azure/issue.rb b/app/utils/clients/tts/azure/issue.rb index e3163bf..241fb64 100644 --- a/app/utils/clients/tts/azure/issue.rb +++ b/app/utils/clients/tts/azure/issue.rb @@ -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 @@ -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 diff --git a/app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb b/app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb index 242a889..4671603 100644 --- a/app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb +++ b/app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb @@ -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 diff --git a/app/views/issues/_issue.json.jbuilder b/app/views/issues/_issue.json.jbuilder index d499ddb..ef85fd2 100644 --- a/app/views/issues/_issue.json.jbuilder +++ b/app/views/issues/_issue.json.jbuilder @@ -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 \ No newline at end of file diff --git a/app/workers/project_issues_worker.rb b/app/workers/project_issues_worker.rb index b3e80e3..702320c 100644 --- a/app/workers/project_issues_worker.rb +++ b/app/workers/project_issues_worker.rb @@ -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 diff --git a/db/migrate/20240325011015_add_reported_on_to_issues.rb b/db/migrate/20240325011015_add_reported_on_to_issues.rb new file mode 100644 index 0000000..1c9e19b --- /dev/null +++ b/db/migrate/20240325011015_add_reported_on_to_issues.rb @@ -0,0 +1,5 @@ +class AddReportedOnToIssues < ActiveRecord::Migration[7.0] + def change + add_column :issues, :reported_at, :datetime + end +end diff --git a/db/migrate/20240325040617_add_identifier_to_issues.rb b/db/migrate/20240325040617_add_identifier_to_issues.rb new file mode 100644 index 0000000..fbf102d --- /dev/null +++ b/db/migrate/20240325040617_add_identifier_to_issues.rb @@ -0,0 +1,5 @@ +class AddIdentifierToIssues < ActiveRecord::Migration[7.0] + def change + add_column :issues, :tts_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 6bc2128..ae763ce 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_03_21_110927) do +ActiveRecord::Schema[7.0].define(version: 2024_03_25_040617) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -76,6 +76,8 @@ t.string "issue_id" t.string "issue_type" t.string "title" + t.datetime "reported_at" + t.string "tts_id" t.index ["project_id"], name: "index_issues_on_project_id" t.index ["user_id"], name: "index_issues_on_user_id" end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 8b5e35a..897af17 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -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 diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index d1b028f..8b943b0 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -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