Skip to content

Commit

Permalink
add enough information to get metrics from minitry brands
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Apr 11, 2024
1 parent ea8a7b5 commit 8b05c87
Show file tree
Hide file tree
Showing 22 changed files with 54,776 additions and 13,870 deletions.
9 changes: 5 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-04-10 18:27:42 UTC using RuboCop version 1.56.2.
# on 2024-04-11 18:41:55 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
Expand All @@ -12,7 +12,7 @@ Lint/MissingSuper:
Exclude:
- 'app/services/time_off_builder.rb'

# Offense count: 9
# Offense count: 10
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 34
Expand All @@ -28,7 +28,7 @@ Metrics/BlockLength:
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 13
# Offense count: 14
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 23
Expand All @@ -40,12 +40,13 @@ Rails/LexicallyScopedActionFilter:
Exclude:
- 'app/controllers/dynamic_datasets_controller.rb'

# Offense count: 2
# Offense count: 3
# Configuration parameters: Include.
# Include: db/**/*.rb
Rails/ReversibleMigration:
Exclude:
- 'db/migrate/20240410162146_remove_index_issue.rb'
- 'db/migrate/20240411164708_change_column_type_dynamic_data_set.rb'

# Offense count: 1
Security/Eval:
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def set_project

def project_params
params.require(:project).permit(:id, :name, :customer_id, :billable, :slack_channel, :metadata, :logo_url,
:logo_background_color, :sync_source_control, :sync_ticket_tracking_system)
:logo_background_color, :sync_source_control, :sync_ticket_tracking_system,
:display_code_metrics, :display_tasks_metrics)
end

def filters_params
Expand Down
3 changes: 2 additions & 1 deletion app/models/dynamic_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# Table name: dynamic_datasets
#
# id :bigint not null, primary key
# code :string
# code :text
# name :string
# order :integer
# created_at :datetime not null
# updated_at :datetime not null
# project_id :bigint not null
Expand Down
1 change: 1 addition & 0 deletions app/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: issues
#
# id :bigint not null, primary key
# board_column :string
# bug :boolean default(FALSE), not null
# closed_date :datetime
# effort :float
Expand Down
31 changes: 31 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
# id :bigint not null, primary key
# billable :boolean default(TRUE), not null
# display_code_metrics :boolean default(FALSE), not null
# display_tasks_metrics :boolean default(FALSE), not null
# logo_background_color :string
# logo_url :string
# metadata :json
Expand Down Expand Up @@ -41,6 +43,35 @@ class Project < ApplicationRecord
validates :billable, inclusion: { in: [true, false] }
validates :slack_channel, presence: true

validate :validate_display_tasks_metrics
validate :validate_sync_ticket_tracking_system
validate :validate_sync_source_control
validate :validate_display_code_metrics

def validate_display_tasks_metrics
return unless display_tasks_metrics && !sync_ticket_tracking_system

errors.add(:display_tasks_metrics, 'cannot be true if sync_ticket_tracking_system is false')
end

def validate_display_code_metrics
return unless display_code_metrics && !sync_source_control

errors.add(:display_tasks_metrics, 'cannot be true if sync_source_control is false')
end

def validate_sync_ticket_tracking_system
return unless sync_ticket_tracking_system && customer.source_control_token.blank?

errors.add(:sync_ticket_tracking_system, "can't be true if customer's source_control_token is empty")
end

def validate_sync_source_control
return unless sync_source_control && customer.source_control_token.blank?

errors.add(:sync_source_control, "can't be true if customer's source_control_token is empty")
end

scope :active_in_period, lambda { |start_date, end_date|
where(id: StatementOfWork.active_in_period(start_date, end_date).select(:project_id).distinct)
}
Expand Down
2 changes: 1 addition & 1 deletion app/services/issues_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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)
parent_tts_id: issue.parent_tts_id, board_column: issue.board_column)
end.compact
end
rescue StandardError => e
Expand Down
28 changes: 21 additions & 7 deletions app/utils/clients/tts/azure/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ module Tts
module Azure
class Issue < Client
def list
issues_list = ::Request.post(url, customer_authorization, body)
urls = issues_list['workItems'].pluck('url')
work_items = urls.map do |url|
work_items = issues_urls.map do |url|
url_expansion = "#{url}?api-version=6.0&$expand=relations"
::Request.get(url_expansion, customer_authorization)
attempts = 0

begin
response = ::Request.get(url_expansion, customer_authorization)
rescue StandardError => e
attempts += 1
retry if attempts < 5
raise "Failed to get response for URL #{url} after 5 attempts: #{e.message}"
end

response
end

parsed_items = work_items.map do |work_item|
Expand All @@ -31,16 +39,22 @@ def url
"#{customer_url}/#{project_name}/_apis/wit/wiql?api-version=6.0"
end

def body
area_path = project.metadata['area_path']

def body(area_path)
{
'query' => 'SELECT [System.Id], [System.Title], [System.WorkItemType], [System.BoardColumn] ' \
'FROM workitems ' \
"WHERE [System.TeamProject] = '#{project_name}' AND [System.AreaPath] = '#{area_path}'"
}
end

def issues_urls
area_paths = project.metadata['area_paths']
area_paths.map do |area_path|
issues_list = ::Request.post(url, customer_authorization, body(area_path))
issues_list['workItems'].pluck('url')
end.flatten
end

def project_name
project.metadata['azure_project_name']
end
Expand Down
9 changes: 5 additions & 4 deletions app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def title
def issue_type
work_item_type = json.dig('fields', 'System.WorkItemType')

return 'PBI' if work_item_type == 'Product Backlog Item'
return 'feature' if work_item_type == 'Feature'

'task' if work_item_type == 'Task'
work_item_type.downcase.gsub(' ', '_')
end

def reported_at
Expand All @@ -61,6 +58,10 @@ def bug?
def parent_tts_id
json.dig('fields', 'System.Parent')
end

def board_column
json.dig('fields', 'System.BoardColumn')
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/projects/_project.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ json.participants project.participants.map do |participant|
end

json.extract! project, :id, :name, :billable, :slack_channel, :metadata, :slug, :logo_url,
:sync_source_control, :sync_ticket_tracking_system, :logo_background_color
:sync_source_control, :sync_ticket_tracking_system, :logo_background_color,
:display_code_metrics, :display_tasks_metrics
7 changes: 7 additions & 0 deletions db/migrate/20240410203627_add_board_column_to_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddBoardColumnToIssues < ActiveRecord::Migration[7.0]
def change
add_column :issues, :board_column, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ChangeColumnTypeDynamicDataSet < ActiveRecord::Migration[7.0]
def change
change_column :dynamic_datasets, :code, :text
end
end
8 changes: 8 additions & 0 deletions db/migrate/20240411181117_add_display_info_to_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class AddDisplayInfoToProjects < ActiveRecord::Migration[7.0]
def change
add_column :projects, :display_tasks_metrics, :boolean, default: false, null: false
add_column :projects, :display_code_metrics, :boolean, default: false, null: false
end
end
7 changes: 7 additions & 0 deletions db/migrate/20240411183807_add_order_to_dynamic_dataset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddOrderToDynamicDataset < ActiveRecord::Migration[7.0]
def change
add_column :dynamic_datasets, :order, :integer
end
end
9 changes: 6 additions & 3 deletions db/schema.rb

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

3 changes: 2 additions & 1 deletion spec/factories/dynamic_datasets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# Table name: dynamic_datasets
#
# id :bigint not null, primary key
# code :string
# code :text
# name :string
# order :integer
# created_at :datetime not null
# updated_at :datetime not null
# project_id :bigint not null
Expand Down
1 change: 1 addition & 0 deletions spec/factories/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: issues
#
# id :bigint not null, primary key
# board_column :string
# bug :boolean default(FALSE), not null
# closed_date :datetime
# effort :float
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
# id :bigint not null, primary key
# billable :boolean default(TRUE), not null
# display_code_metrics :boolean default(FALSE), not null
# display_tasks_metrics :boolean default(FALSE), not null
# logo_background_color :string
# logo_url :string
# metadata :json
Expand Down
68,495 changes: 54,651 additions & 13,844 deletions spec/fixtures/vcr_cassettes/clients_tts_azure_issue_list.yml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion spec/models/dynamic_dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# Table name: dynamic_datasets
#
# id :bigint not null, primary key
# code :string
# code :text
# name :string
# order :integer
# created_at :datetime not null
# updated_at :datetime not null
# project_id :bigint not null
Expand Down
1 change: 1 addition & 0 deletions spec/models/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: issues
#
# id :bigint not null, primary key
# board_column :string
# bug :boolean default(FALSE), not null
# closed_date :datetime
# effort :float
Expand Down
2 changes: 2 additions & 0 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
# id :bigint not null, primary key
# billable :boolean default(TRUE), not null
# display_code_metrics :boolean default(FALSE), not null
# display_tasks_metrics :boolean default(FALSE), not null
# logo_background_color :string
# logo_url :string
# metadata :json
Expand Down
12 changes: 10 additions & 2 deletions spec/services/issues_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

let(:project) do
create(:project, customer:,
metadata: { azure_project_name: '1ES', area_path: '1ES\\DDC UI Refresh\\2023' })
metadata: { azure_project_name: '1ES', area_paths: [
'1ES\\DDC UI Refresh\\2023',
'1ES\\DDC UI Refresh\\2024',
'1ES\\DDC UI Refresh'
] })
end

it 'creates a list of issues' do
Expand All @@ -38,9 +42,13 @@
feature = issues.find { |issue| issue.tts_id == '163794' }
expect(feature.issue_type).to eq('feature')
pbi = issues.find { |issue| issue.tts_id == '168900' }
expect(pbi.issue_type).to eq('PBI')
expect(pbi.issue_type).to eq('product_backlog_item')
task = issues.find { |issue| issue.tts_id == '169223' }
expect(task.issue_type).to eq('task')
epic = issues.find { |issue| issue.tts_id == '160528' }
expect(epic.issue_type).to eq('epic')
release = issues.find { |issue| issue.tts_id == '165516' }
expect(release.issue_type).to eq('release')
bug = issues.find { |issue| issue.tts_id == '168646' }
expect(bug.bug).to be_truthy
end
Expand Down

0 comments on commit 8b05c87

Please sign in to comment.