From facc908085e8dc0f83c58ff958cd59c3017f1283 Mon Sep 17 00:00:00 2001 From: Kaio Magalhaes Date: Wed, 15 May 2024 11:42:24 -0300 Subject: [PATCH] add start and end sprint date to issues --- app/models/issue.rb | 36 ++++++++++--------- app/services/issues_creator.rb | 3 +- app/utils/clients/tts/azure/issue.rb | 10 +++++- .../azure/parsers/ministry_brands_parser.rb | 5 +-- ...240515131152_add_sprints_data_to_issues.rb | 8 +++++ db/schema.rb | 4 ++- spec/factories/issues.rb | 36 ++++++++++--------- spec/models/issue_spec.rb | 36 ++++++++++--------- 8 files changed, 82 insertions(+), 56 deletions(-) create mode 100644 db/migrate/20240515131152_add_sprints_data_to_issues.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index dc9bb08..8ea3634 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -4,23 +4,25 @@ # # Table name: issues # -# id :bigint not null, primary key -# board_column :string -# bug :boolean default(FALSE), not null -# closed_date :datetime -# effort :float -# issue_type :string -# reported_at :datetime -# sprint :string -# state :string -# title :string -# created_at :datetime not null -# updated_at :datetime not null -# issue_id :string -# parent_tts_id :string -# project_id :bigint not null -# tts_id :string -# user_id :bigint +# id :bigint not null, primary key +# board_column :string +# bug :boolean default(FALSE), not null +# closed_date :datetime +# effort :float +# issue_type :string +# reported_at :datetime +# sprint :string +# sprint_end_date :datetime +# sprint_start_date :datetime +# state :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# issue_id :string +# parent_tts_id :string +# project_id :bigint not null +# tts_id :string +# user_id :bigint # # Indexes # diff --git a/app/services/issues_creator.rb b/app/services/issues_creator.rb index 469295c..9c76e68 100644 --- a/app/services/issues_creator.rb +++ b/app/services/issues_creator.rb @@ -17,7 +17,8 @@ def call 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, bug: issue.bug?, - parent_tts_id: issue.parent_tts_id, board_column: issue.board_column, sprint: issue.sprint) + parent_tts_id: issue.parent_tts_id, board_column: issue.board_column, sprint: issue.sprint, + sprint_start_date: issue.sprint_start_date, sprint_end_date: issue.sprint_end_date) end.compact end rescue StandardError => e diff --git a/app/utils/clients/tts/azure/issue.rb b/app/utils/clients/tts/azure/issue.rb index cc15dcc..cad32b5 100644 --- a/app/utils/clients/tts/azure/issue.rb +++ b/app/utils/clients/tts/azure/issue.rb @@ -21,7 +21,7 @@ def list end parsed_items = work_items.map do |work_item| - parser.new(work_item, project) + parser.new(work_item, project, iteractions) end filtered_items(parsed_items) @@ -65,6 +65,14 @@ def issues_urls def project_name project.metadata['azure_project_name'] end + + def iteractions + return @iteractions if @iteractions + + iterations_url = "#{customer_url}/#{project_name}/_apis/work/teamsettings/iterations?api-version=6.0" + response = ::Request.get(iterations_url, customer_authorization) + @iteractions = response['value'] + end end end end 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 f7f0d06..bb67ee7 100644 --- a/app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb +++ b/app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb @@ -5,11 +5,12 @@ module Tts module Azure module Parsers class MinistryBrandsParser - attr_reader :json, :project + attr_reader :json, :project, :iterations - def initialize(json, project) + def initialize(json, project, iterations) @json = json @project = project + @iterations = iterations end def valid? diff --git a/db/migrate/20240515131152_add_sprints_data_to_issues.rb b/db/migrate/20240515131152_add_sprints_data_to_issues.rb new file mode 100644 index 0000000..3267084 --- /dev/null +++ b/db/migrate/20240515131152_add_sprints_data_to_issues.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddSprintsDataToIssues < ActiveRecord::Migration[7.0] + def change + add_column :issues, :sprint_start_date, :datetime + add_column :issues, :sprint_end_date, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 1f8f25b..f6045a1 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_05_13_143928) do +ActiveRecord::Schema[7.0].define(version: 2024_05_15_131152) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -131,6 +131,8 @@ t.string "parent_tts_id" t.string "board_column" t.string "sprint" + t.datetime "sprint_start_date" + t.datetime "sprint_end_date" t.index ["project_id"], name: "index_issues_on_project_id" end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 070dcbf..b2398af 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -4,23 +4,25 @@ # # Table name: issues # -# id :bigint not null, primary key -# board_column :string -# bug :boolean default(FALSE), not null -# closed_date :datetime -# effort :float -# issue_type :string -# reported_at :datetime -# sprint :string -# state :string -# title :string -# created_at :datetime not null -# updated_at :datetime not null -# issue_id :string -# parent_tts_id :string -# project_id :bigint not null -# tts_id :string -# user_id :bigint +# id :bigint not null, primary key +# board_column :string +# bug :boolean default(FALSE), not null +# closed_date :datetime +# effort :float +# issue_type :string +# reported_at :datetime +# sprint :string +# sprint_end_date :datetime +# sprint_start_date :datetime +# state :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# issue_id :string +# parent_tts_id :string +# project_id :bigint not null +# tts_id :string +# user_id :bigint # # Indexes # diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 6d392e6..05271f6 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -4,23 +4,25 @@ # # Table name: issues # -# id :bigint not null, primary key -# board_column :string -# bug :boolean default(FALSE), not null -# closed_date :datetime -# effort :float -# issue_type :string -# reported_at :datetime -# sprint :string -# state :string -# title :string -# created_at :datetime not null -# updated_at :datetime not null -# issue_id :string -# parent_tts_id :string -# project_id :bigint not null -# tts_id :string -# user_id :bigint +# id :bigint not null, primary key +# board_column :string +# bug :boolean default(FALSE), not null +# closed_date :datetime +# effort :float +# issue_type :string +# reported_at :datetime +# sprint :string +# sprint_end_date :datetime +# sprint_start_date :datetime +# state :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# issue_id :string +# parent_tts_id :string +# project_id :bigint not null +# tts_id :string +# user_id :bigint # # Indexes #