Skip to content

Commit

Permalink
add sync options to project controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Apr 10, 2024
1 parent 292bc22 commit 0fa9c48
Show file tree
Hide file tree
Showing 13 changed files with 108,104 additions and 6,201 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
.env
latest.dump

.next
.next
.DS_Store
11 changes: 9 additions & 2 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-03-29 19:48:59 UTC using RuboCop version 1.56.2.
# on 2024-04-10 16:30:19 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 @@ -27,6 +27,13 @@ Metrics/CyclomaticComplexity:
Metrics/MethodLength:
Max: 23

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

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

# Offense count: 10
# Offense count: 11
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def set_project

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

def filters_params
Expand Down
7 changes: 3 additions & 4 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
# bug :boolean default(FALSE), not null
# closed_date :datetime
# effort :float
# issue_type :string
Expand All @@ -16,19 +17,17 @@
# issue_id :string
# project_id :bigint not null
# tts_id :string
# user_id :bigint not null
# user_id :bigint
#
# Indexes
#
# index_issues_on_project_id (project_id)
# index_issues_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (project_id => projects.id)
# fk_rails_... (user_id => users.id)
#
class Issue < ApplicationRecord
belongs_to :user
belongs_to :user, optional: true
belongs_to :project
end
6 changes: 3 additions & 3 deletions app/services/issues_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def call

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

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
issue_type: issue.issue_type, reported_at: issue.reported_at, tts_id: issue.tts_id, bug: issue.bug?)
end.compact
end
rescue StandardError => e
Rails.logger.error("Failed to process issues due to error: #{e.message}")
Expand Down
16 changes: 13 additions & 3 deletions app/utils/clients/tts/azure/parsers/ministry_brands_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def initialize(json, project)
@project = project
end

def valid?
!title.match?(/\[QA\]/i)
end

def effort
json['fields']['Microsoft.VSTS.Scheduling.Effort']&.to_i
end
Expand All @@ -34,10 +38,12 @@ def title
end

def issue_type
return 'Bug' if title.match?(/.*Bug.*/i)
return 'Product Backlog Item' if json.dig('fields', 'System.WorkItemType') == 'Product Backlog Item'
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'
'task' if work_item_type == 'Task'
end

def reported_at
Expand All @@ -47,6 +53,10 @@ def reported_at
def tts_id
json['id'].to_s
end

def bug?
title.match?(/.*Bug.*/i)
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20240410160513_add_bug_to_issue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddBugToIssue < ActiveRecord::Migration[7.0]
def change
add_column :issues, :bug, :boolean, default: false, null: false
end
end
9 changes: 9 additions & 0 deletions db/migrate/20240410162146_remove_index_issue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class RemoveIndexIssue < ActiveRecord::Migration[7.0]
def change
remove_index :issues, column: :user_id, name: :index_issues_on_user_id
remove_foreign_key :issues, column: :user_id
change_column :issues, :user_id, :bigint, null: true
end
end
8 changes: 3 additions & 5 deletions db/schema.rb

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

5 changes: 2 additions & 3 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
# bug :boolean default(FALSE), not null
# closed_date :datetime
# effort :float
# issue_type :string
Expand All @@ -16,17 +17,15 @@
# issue_id :string
# project_id :bigint not null
# tts_id :string
# user_id :bigint not null
# user_id :bigint
#
# Indexes
#
# index_issues_on_project_id (project_id)
# index_issues_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (project_id => projects.id)
# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
factory :issue do
Expand Down
114,197 changes: 108,023 additions & 6,174 deletions spec/fixtures/vcr_cassettes/clients_tts_azure_issue_list.yml

Large diffs are not rendered by default.

5 changes: 2 additions & 3 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
# bug :boolean default(FALSE), not null
# closed_date :datetime
# effort :float
# issue_type :string
Expand All @@ -16,17 +17,15 @@
# issue_id :string
# project_id :bigint not null
# tts_id :string
# user_id :bigint not null
# user_id :bigint
#
# Indexes
#
# index_issues_on_project_id (project_id)
# index_issues_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (project_id => projects.id)
# fk_rails_... (user_id => users.id)
#
require 'rails_helper'

Expand Down
29 changes: 27 additions & 2 deletions spec/services/issues_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe '#call' do
context 'when the customer uses Azure DevOps' do
let(:customer) do
create(:customer, name: 'Ministry Brands', ticket_tracking_system_token: 'place-real-token-here',
create(:customer, name: 'Ministry Brands', ticket_tracking_system_token: 'place-real-token-here=',
ticket_tracking_system: 'azure')
end

Expand All @@ -27,10 +27,35 @@
user
expect do
IssuesCreator.call(project)
end.to change(Issue, :count).by(11)
end.to change(Issue, :count).by(1203)
end
end

it 'sets the issue types correctly' do
VCR.use_cassette('clients#tts#azure#issue#list') do
user
issues = IssuesCreator.call(project)
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')
task = issues.find { |issue| issue.tts_id == '169223' }
expect(task.issue_type).to eq('task')
bug = issues.find { |issue| issue.tts_id == '168646' }
expect(bug.bug).to be_truthy
end
end

it 'ignores the issues that are not valid' do
VCR.use_cassette('clients#tts#azure#issue#list') do
user
issues = IssuesCreator.call(project)
issue_should_be_ignored = issues.find { |issue| issue.tts_id == '169068' }
expect(issue_should_be_ignored).to be_nil
end
end
end

context 'when the customer uses Asana' do
let(:customer) do
create(:customer, name: 'Taylor Summit',
Expand Down

0 comments on commit 0fa9c48

Please sign in to comment.