# frozen_string_literal: true require_relative '../lib/git_ownership_insights/git_ownership_insight' RSpec.describe GitOwnershipInsights do EXCLUSIONS = %w[exclusion1 exclusion2].freeze TEAM_REGEX = '[A-Za-z]+' TOP_TOUCHED_FILES = 5 TOP_CONTRIBUTED_TEAMS = 5 CODEOWNERS_PATH = '.github/CODEOWNERS' BIG_FILE_SIZE = 250 CI = false DEFAULT_BRANCH = 'main' CODEOWNERS = true HOTSPOT = true CODE_EXTENSIONS = ['.swift', '.kt'].freeze EXCLUDED_FILES = 'ignore' let(:dummy_directory_path) { 'spec/fixtures' } let(:duration_in_days) { 7 } describe '#contribution_message' do before do @git_ownership_insights = GitOwnershipInsights.new( directory_path: dummy_directory_path, duration_in_days:, begin_time: DateTime.now ) allow(@git_ownership_insights).to receive(:git_files).and_return("spec/fixtures/file1.swift\nspec/fixtures/file2.kt\nspec/fixtures/file3.swift\nspec/fixtures/file4.swift\nspec/fixtures/file5.swift\nspec/fixtures/ignore.kt") allow(@git_ownership_insights).to receive(:files_with_changes).and_return("spec/fixtures/file1.swift\nspec/fixtures/file2.kt\nspec/fixtures/file3.swift\nsspec/fixtures/ignore.kt") allow(@git_ownership_insights).to receive(:git_commit_count).and_return('3', '3', '1') allow(@git_ownership_insights).to receive(:git_commit_info).and_return("FIOS-323 Commit 1\nFAND-321Commit 2\nFIOS-654 Commit 3", "FIOS-323 Commit 1\nFAND-321Commit 2\nFIOS-654 Commit 3", 'FIOS-323 Commit 1') end it 'prints contribution message' do expected_output = <<~EXPECTED *Timeframe:* #{(DateTime.now - duration_in_days).strftime('%Y-%m-%d')} to #{Time.now.strftime('%Y-%m-%d')} *Code files with a single contributor:* 50.0% *Existing files changed by many teams:* 2 *Current existing [".swift", ".kt"] files:* 4 *Cross-Squad Dependency:* *Contributions by multiple squads to the same files:* 4 *Contributions by single squads contributing to single files:* 1 *Hotspot Code Changes:* 85.71% *Churn count(commits to files by multiple teams):* 6 *Total amount of commits:* 7 *Total lines of hotspot code:* 330 *[".swift", ".kt"] files with multiple contributors:* 2 *[".swift", ".kt"] files exceeding 250 lines with multiple contributors:* 1 *Total amount of commits to [".swift", ".kt"] files:* 7 *Total [".swift", ".kt"] files changed:* 3 *Current(\\*) total number of code files longer than 250 lines:* 2 *Current(\\*) total of [".swift", ".kt"] files in the folder:* 4 *Contributors:* {"FIOS"=>5, "FAND"=>2} * means that it the current(instant) repository value, all the other metrics are done over 7 days period Hotspot changes: /file1.swift Contributors: ["FIOS", "FAND"] Commits: 3 Code ownership data: Codeownership data: FIOS: Total Count: 3 Directory: spec/fixtures Top files: file1.swift - 3 ["FIOS", "FAND"]} FAND: Total Count: 3 Directory: spec/fixtures Top files: file2.kt - 3 ["FIOS", "FAND"]} EXPECTED expect do @git_ownership_insights.contribution_message end.to output(expected_output).to_stdout end it 'handles case when CODE_EXTENSIONS is nil' do allow(File).to receive(:exist?).and_return(true) allow(File).to receive(:foreach).and_return(%w[line1 line2 line3]) allow(@git_ownership_insights).to receive(:count_big_files) expect do @git_ownership_insights.contribution_message end.not_to raise_error end end end