codespicuous 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b264796715a1c06a98b0d5ffdee3492bde6852e
4
- data.tar.gz: 2d7151e47dc07ca625c4d9c32789ca18e4444ff2
3
+ metadata.gz: 32369c66cbcbd810e9205237576757eca230612a
4
+ data.tar.gz: 1ba22aea1525014e6eefcba42caee9318d6645ed
5
5
  SHA512:
6
- metadata.gz: 2f574226876b029b8c51c50d128f7dc99a96bd87592f6719723e303e658476e6f4ddeda712c97bb1def21043417952392ef1b92036ff49b709840427b9d47c44
7
- data.tar.gz: a5121a0a45b4a15fd9d4336f543e4f51d4161ff7e8243e23e8e688bfad21333c88dbc76e791808e83795d0290d4632403c4a109dfa179ed86bd519be26e9743a
6
+ metadata.gz: e913239d16e84541c593216c0c31e44825b52422082b188e00143658488be1822ec35a57ddf7df965c1360a994763a069cd4e7c22346e46599482056be6b97dc
7
+ data.tar.gz: 139729759092fc037bb447161b651d915dbd0b5fca9306e44ad40b03459c9e5865457e982767386ad01812049362c6320e74ead0696e7a6fb24202e609ff9c88
@@ -44,7 +44,7 @@ class Codespicuous
44
44
 
45
45
  def generate_output
46
46
  generator = MetricsGenerator.new
47
- generator.generate(@commit_history)
47
+ generator.generate(@config, @commit_history)
48
48
  end
49
49
 
50
50
  def list_committed_repositories
@@ -9,8 +9,11 @@ class CodespicuousConfig
9
9
  @offline = false
10
10
  @configuration_file_name = "codespicuous.yaml"
11
11
  @input_path = Pathname.new(".")
12
+ @output_path = Pathname.new(".")
12
13
  @list_repositories = false
13
14
  @svnlogdir = "svnlog"
15
+
16
+ @output_dir_csv_files = "csv_files"
14
17
  end
15
18
 
16
19
  def input_path=(path)
@@ -32,4 +35,12 @@ class CodespicuousConfig
32
35
  def path_to_cached_svn_log_dir
33
36
  (@input_path + Pathname.new(@svnlogdir)).to_s
34
37
  end
38
+
39
+ def path_to_output_dir_for_csv_files
40
+ (@output_path + Pathname.new(@output_dir_csv_files)).to_s
41
+ end
42
+
43
+ def path_to_csv_file(filename)
44
+ (Pathname.new(path_to_output_dir_for_csv_files) + Pathname.new(filename)).to_s
45
+ end
35
46
  end
@@ -51,6 +51,10 @@ class CommitHistory
51
51
  @repositories.repository_names
52
52
  end
53
53
 
54
+ def amount_of_repositories
55
+ @repositories.amount
56
+ end
57
+
54
58
  def amount_of_comitters
55
59
  @committers.amount
56
60
  end
@@ -73,4 +77,36 @@ class CommitHistory
73
77
  @commits == commit_history.commits
74
78
  end
75
79
 
80
+ def copy_repositories_without_commits
81
+ repositories = Repositories.new
82
+ @repositories.each do |repository|
83
+ repositories.add(repository.clone_without_commits)
84
+ end
85
+ repositories
86
+ end
87
+
88
+ def prune_repositories_without_commit
89
+ @repositories.prune_repositories_without_commit
90
+ end
91
+
92
+ def restrict_to_teams
93
+ restricted_commit_history = CommitHistory.new
94
+
95
+ repositories = copy_repositories_without_commits
96
+ restricted_commit_history.configure(teams.clone_without_commits, repositories)
97
+
98
+ @commits.each do |commit|
99
+ if @teams.contains_committer?(commit.committer)
100
+ new_commit = commit.clone
101
+ new_commit.repository = repositories.repository(commit.repository.name)
102
+ restricted_commit_history.add_commit(new_commit)
103
+ end
104
+
105
+ end
106
+
107
+ restricted_commit_history.prune_repositories_without_commit
108
+
109
+ restricted_commit_history
110
+ end
111
+
76
112
  end
@@ -24,6 +24,11 @@ class CommitHistoryBuilder
24
24
  self
25
25
  end
26
26
 
27
+ def without_team
28
+ @team = nil
29
+ self
30
+ end
31
+
27
32
  def at(date)
28
33
  @commit_date = date
29
34
  add_commit_to_history
@@ -43,7 +48,7 @@ class CommitHistoryBuilder
43
48
  commit.date = DateTime.parse(@commit_date)
44
49
  commit.repository = @current_repository
45
50
  @commit_history.add_commit(commit)
46
- @commit_history.add_team_member(@team, @author)
51
+ @commit_history.add_team_member(@team, @author) if @team
47
52
  end
48
53
  end
49
54
 
@@ -9,6 +9,14 @@ class Committer
9
9
  @commits = Commits.new
10
10
  end
11
11
 
12
+ def clone_without_commits
13
+ cloned_committer = Committer.new(username)
14
+ cloned_committer.first_name = first_name
15
+ cloned_committer.last_name = last_name
16
+ cloned_committer.email = email
17
+ cloned_committer
18
+ end
19
+
12
20
  def self.create_committer(login, firstname, lastname, email)
13
21
  committer = Committer.new(login)
14
22
  committer.first_name = firstname
@@ -18,7 +26,7 @@ class Committer
18
26
  end
19
27
 
20
28
  def in_team_with_name?(team_name)
21
- @team.name == team_name
29
+ !@team.nil? && @team.name == team_name
22
30
  end
23
31
 
24
32
  def add_commit commit
@@ -2,21 +2,22 @@
2
2
 
3
3
  class MetricsGenerator
4
4
 
5
- attr_accessor :commit_history
5
+ attr_accessor :commit_history, :config
6
6
 
7
- def generate(commit_history)
7
+ def generate(config, commit_history)
8
8
  @commit_history = commit_history
9
+ @config = config
9
10
  generate_daniel
10
- generate_csv
11
+ generate_csv_files
11
12
  end
12
13
 
13
14
  def generate_daniel
14
- daniel = MetricsGeneratorDaniel.new(@commit_history)
15
+ daniel = MetricsGeneratorDaniel.new(@config, @commit_history)
15
16
  daniel.generate
16
17
  end
17
18
 
18
- def generate_csv
19
- csv = MetricsGeneratorCsv.new(@commit_history)
19
+ def generate_csv_files
20
+ csv = MetricsGeneratorCsvFiles.new(@config, @commit_history)
20
21
  csv.generate
21
22
  end
22
23
  end
@@ -0,0 +1,45 @@
1
+
2
+ class MetricsGeneratorCsvFiles
3
+
4
+ attr_reader :all_csv_generator, :teams_csv_generator
5
+
6
+ def create_csv_files_output_directory
7
+ Dir.mkdir(@config.path_to_output_dir_for_csv_files) unless Dir.exists?(@config.path_to_output_dir_for_csv_files)
8
+ end
9
+
10
+ def initialize(config, commit_history)
11
+ @config = config
12
+ @all_csv_generator = MetricsGeneratorCsv.new(commit_history)
13
+ @restricted_history = commit_history.restrict_to_teams
14
+ @teams_csv_generator = MetricsGeneratorCsv.new(@restricted_history)
15
+ end
16
+
17
+ def generate
18
+ create_csv_files_output_directory
19
+ create_commit_table_with_week_and_repository_info
20
+ create_commit_table_with_weeks_and_team_commits
21
+ create_commit_table_with_committers_and_repository_info
22
+ create_commit_table_with_weeks_and_committers
23
+ end
24
+
25
+ def create_commit_table_with_week_and_repository_info
26
+ File.write(@config.path_to_csv_file("all_week_and_repository_info.csv"), @all_csv_generator.create_commit_table_with_week_and_repository_info)
27
+ File.write(@config.path_to_csv_file("teams_week_and_repository_info.csv"), @teams_csv_generator.create_commit_table_with_week_and_repository_info)
28
+ end
29
+
30
+ def create_commit_table_with_weeks_and_team_commits
31
+ File.write(@config.path_to_csv_file("teams_week_and_team_commits.csv"), @teams_csv_generator.create_commit_table_with_weeks_and_team_commits)
32
+ end
33
+
34
+ def create_commit_table_with_committers_and_repository_info
35
+ File.write(@config.path_to_csv_file("teams_committer_and_repository_info.csv"), @teams_csv_generator.create_commit_table_with_committers_and_repository_info)
36
+ end
37
+
38
+ def create_commit_table_with_weeks_and_committers
39
+ File.write(@config.path_to_csv_file("teams_weeks_and_committers_info.csv"), @all_csv_generator.create_commit_table_with_weeks_and_committers)
40
+ @restricted_history.teams.each do | team |
41
+ File.write(@config.path_to_csv_file("teams_weeks_and_committers_info_#{team.name}.csv"), @all_csv_generator.create_commit_table_with_weeks_and_committers(team.name))
42
+ end
43
+
44
+ end
45
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  class MetricsGeneratorDaniel
4
4
 
5
- def initialize(commit_history)
5
+ def initialize(config, commit_history)
6
6
  end
7
7
 
8
8
  def generate
@@ -15,10 +15,18 @@ class Repository
15
15
  @commits = Commits.new
16
16
  end
17
17
 
18
+ def clone_without_commits
19
+ Repository.new(@name, @url)
20
+ end
21
+
18
22
  def add_commit commit
19
23
  @commits.add(commit)
20
24
  end
21
25
 
26
+ def amount_of_commits
27
+ @commits.amount
28
+ end
29
+
22
30
  def amount_of_commits_in_week(week_start)
23
31
  @commits.amount_of_commits_to_repository_in_week(name, week_start)
24
32
  end
@@ -61,6 +69,10 @@ class Repositories
61
69
  }
62
70
  end
63
71
 
72
+ def prune_repositories_without_commit
73
+ @repositories.delete_if { |key, value| value.amount_of_commits == 0 }
74
+ end
75
+
64
76
  def empty?
65
77
  @repositories.empty?
66
78
  end
@@ -8,6 +8,14 @@ class Team
8
8
  @members = {}
9
9
  end
10
10
 
11
+ def clone_without_commits
12
+ cloned_team = Team.new(name)
13
+ members.each do | member |
14
+ cloned_team.add_member(member.clone_without_commits)
15
+ end
16
+ cloned_team
17
+ end
18
+
11
19
  def add_member(member)
12
20
  @members[member.username] = member
13
21
  member.team = self
@@ -62,6 +70,14 @@ class Teams
62
70
  @teams = {}
63
71
  end
64
72
 
73
+ def clone_without_commits
74
+ cloned_teams = Teams.new
75
+ teams.each do | name, team|
76
+ cloned_teams.add(team.clone_without_commits)
77
+ end
78
+ cloned_teams
79
+ end
80
+
65
81
  def find_by_name(name)
66
82
  @teams[name]
67
83
  end
@@ -76,6 +92,13 @@ class Teams
76
92
  }
77
93
  end
78
94
 
95
+ def contains_committer?(committer)
96
+ each_member { |team, member|
97
+ return true if member.username == committer.username
98
+ }
99
+ false
100
+ end
101
+
79
102
  def committers
80
103
  committers = Committers.new
81
104
  each_member { |team, committer| committers.add(committer) }
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Codespicuous
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
data/lib/codespicuous.rb CHANGED
@@ -31,6 +31,7 @@ require_relative 'codespicuous/codespicuous_config.rb'
31
31
  require_relative 'codespicuous/metrics_generator.rb'
32
32
  require_relative 'codespicuous/metrics_generator_daniel.rb'
33
33
  require_relative 'codespicuous/metrics_generator_csv.rb'
34
+ require_relative 'codespicuous/metrics_generator_csv_files.rb'
34
35
 
35
36
  require_relative 'codespicuous/repository_lister.rb'
36
37
  # App
@@ -63,7 +63,7 @@ describe "Codespicuous command line" do
63
63
  it "generates output" do
64
64
  generator = MetricsGenerator.new
65
65
  expect(MetricsGenerator).to receive(:new).and_return(generator)
66
- expect(generator).to receive(:generate).with(subject.commit_history)
66
+ expect(generator).to receive(:generate).with(subject.config, subject.commit_history)
67
67
  subject.generate_output
68
68
  end
69
69
 
@@ -53,5 +53,49 @@ describe "Team commits per week table" do
53
53
  expect(@commit_history.amount_of_commits_for_team_in_week("Cheese", DateTime.new(2016,03,28))).to eq 1
54
54
  end
55
55
 
56
+ context "extracting a subset of the commit history" do
57
+
58
+ before (:each) do
59
+ @large_commit_history = CommitHistoryBuilder.new.
60
+ in_repository("one").
61
+ commits_of("basvodde").of_team("Wine").
62
+ at("2016-04-18").times(2).
63
+ commits_of("daniel").of_team("Cheese").
64
+ at("2016-03-28").
65
+ commits_of("janne").without_team.
66
+ at("2016-08-18").times(2).
67
+ in_repository("cpputest").
68
+ commits_of("janne").without_team.
69
+ at("2016-02-29").
70
+ build
71
+
72
+ @restricted_commit_history = @large_commit_history.restrict_to_teams
73
+ end
74
+
75
+ it "will only have two committers in the restricted commit history" do
76
+ expect(@large_commit_history.amount_of_comitters).to eq 3
77
+ expect(@restricted_commit_history.amount_of_comitters).to eq 2
78
+ end
79
+
80
+ it "will only have the repositories of the restricted committers" do
81
+ expect(@large_commit_history.amount_of_repositories).to eq 2
82
+ expect(@restricted_commit_history.amount_of_repositories).to eq 1
83
+ end
84
+
85
+ it "will also be able to get the right amount of commits via the reposities" do
86
+ expect(@large_commit_history.repository("one").amount_of_commits).to eq 5
87
+ expect(@restricted_commit_history.repository("one").amount_of_commits).to eq 3
88
+ end
89
+
90
+ it "will also be able to get the right amount of commits via the comitter" do
91
+ expect(@large_commit_history.committer("basvodde").amount_of_commits).to eq 2
92
+ expect(@restricted_commit_history.committer("basvodde").amount_of_commits).to eq 2
93
+ end
94
+
95
+ it "will also be able to get the right amount of team members in the teams" do
96
+ expect(@large_commit_history.team("Wine").amount_of_members).to eq 1
97
+ expect(@restricted_commit_history.team("Wine").amount_of_members).to eq 1
98
+ end
99
+ end
56
100
  end
57
101
 
@@ -34,6 +34,11 @@ describe "The committers and the teams that we're examining" do
34
34
  expect(@teams.amount).to eq 2
35
35
  end
36
36
 
37
+ it "is not in the team with name if th committer is not in a team" do
38
+ committer = Committer.new("lonely_guy")
39
+ expect(committer.in_team_with_name?("nice team")).to eq false
40
+ end
41
+
37
42
  it "has all the committer information" do
38
43
  bas = @committers.find_by_username('basvodde')
39
44
  expect(bas.first_name).to eq "Bas"
@@ -0,0 +1,77 @@
1
+
2
+ describe "Generate csv metric files" do
3
+
4
+ before (:each) do
5
+ @commit_history = CommitHistory.new
6
+ @generator = MetricsGeneratorCsvFiles.new(CodespicuousConfig.new, @commit_history)
7
+ end
8
+
9
+ it "generates different type of csv file metrics" do
10
+
11
+ expect(@generator).to receive(:create_csv_files_output_directory)
12
+ expect(@generator).to receive(:create_commit_table_with_week_and_repository_info)
13
+ expect(@generator).to receive(:create_commit_table_with_weeks_and_team_commits)
14
+ expect(@generator).to receive(:create_commit_table_with_committers_and_repository_info)
15
+ expect(@generator).to receive(:create_commit_table_with_weeks_and_committers)
16
+
17
+ @generator.generate
18
+ end
19
+
20
+ it "Should create an output directory when it doesn't exists" do
21
+ expect(Dir).to receive(:exists?).with("csv_files").and_return(false)
22
+ expect(Dir).to receive(:mkdir).with("csv_files")
23
+ @generator.create_csv_files_output_directory
24
+ end
25
+
26
+ it "Should not create an output directory when it does exists" do
27
+ expect(Dir).to receive(:exists?).with("csv_files").and_return(true)
28
+ expect(Dir).not_to receive(:mkdir).with("csv_files")
29
+ @generator.create_csv_files_output_directory
30
+ end
31
+
32
+ it "can generate the week and repository files" do
33
+ expect(@generator.all_csv_generator).to receive(:create_commit_table_with_week_and_repository_info).and_return("all_csv_data")
34
+ expect(@generator.teams_csv_generator).to receive(:create_commit_table_with_week_and_repository_info).and_return("teams_csv_data")
35
+ expect(File).to receive(:write).with("csv_files/all_week_and_repository_info.csv", "all_csv_data")
36
+ expect(File).to receive(:write).with("csv_files/teams_week_and_repository_info.csv", "teams_csv_data")
37
+
38
+ @generator.create_commit_table_with_week_and_repository_info
39
+ end
40
+
41
+ it "can generate the week and team commit files" do
42
+ expect(@generator.teams_csv_generator).to receive(:create_commit_table_with_weeks_and_team_commits).and_return("csv_data")
43
+ expect(File).to receive(:write).with("csv_files/teams_week_and_team_commits.csv", "csv_data")
44
+
45
+ @generator.create_commit_table_with_weeks_and_team_commits
46
+ end
47
+
48
+ it "can generate the commit and repository info files" do
49
+ expect(@generator.teams_csv_generator).to receive(:create_commit_table_with_committers_and_repository_info).and_return("csv_data")
50
+ expect(File).to receive(:write).with("csv_files/teams_committer_and_repository_info.csv", "csv_data")
51
+
52
+ @generator.create_commit_table_with_committers_and_repository_info
53
+ end
54
+
55
+ it "can generate the weeks and committers info files" do
56
+ expect(@generator.all_csv_generator).to receive(:create_commit_table_with_weeks_and_committers).and_return("csv_data")
57
+ expect(File).to receive(:write).with("csv_files/teams_weeks_and_committers_info.csv", "csv_data")
58
+
59
+ @generator.create_commit_table_with_weeks_and_committers
60
+ end
61
+
62
+ it "can generate the weeks and committers per team info files" do
63
+ team = Team.new("teamx")
64
+ teams = Teams.new
65
+ teams.add(team)
66
+ @commit_history.configure(teams, @commit_history.repositories)
67
+ @generator = MetricsGeneratorCsvFiles.new(CodespicuousConfig.new, @commit_history)
68
+
69
+ expect(@generator.all_csv_generator).to receive(:create_commit_table_with_weeks_and_committers).and_return("csv_data")
70
+ expect(@generator.all_csv_generator).to receive(:create_commit_table_with_weeks_and_committers).with("teamx").and_return("csv_data2")
71
+ expect(File).to receive(:write).with("csv_files/teams_weeks_and_committers_info.csv", "csv_data")
72
+ expect(File).to receive(:write).with("csv_files/teams_weeks_and_committers_info_teamx.csv", "csv_data2")
73
+
74
+ @generator.create_commit_table_with_weeks_and_committers
75
+ end
76
+
77
+ end
@@ -3,7 +3,8 @@ describe "Daniel format metrics generator" do
3
3
 
4
4
  it "exists" do
5
5
  commit_history = CommitHistory.new
6
- daniel = MetricsGeneratorDaniel.new(commit_history)
6
+ config = CodespicuousConfig.new
7
+ daniel = MetricsGeneratorDaniel.new(config, commit_history)
7
8
  daniel.generate
8
9
  end
9
10
 
@@ -3,21 +3,24 @@ describe "Generate different types of code metrics" do
3
3
 
4
4
  before (:each) do
5
5
  @commit_history = CommitHistory.new
6
+ @config = CodespicuousConfig.new
6
7
  @subject = MetricsGenerator.new
8
+
9
+ @subject.commit_history = @commit_history
10
+ @subject.config = @config
7
11
  end
8
12
 
9
13
  it "can generate different metrics" do
10
14
  expect(@subject).to receive(:generate_daniel)
11
- expect(@subject).to receive(:generate_csv)
15
+ expect(@subject).to receive(:generate_csv_files)
12
16
 
13
- @subject.generate(@commit_history)
17
+ @subject.generate(@config, @commit_history)
14
18
  end
15
19
 
16
20
  it "generate daniel format metrics" do
17
- @subject.commit_history = @commit_history
18
21
 
19
- daniel = MetricsGeneratorDaniel.new(@commit_history)
20
- expect(MetricsGeneratorDaniel).to receive(:new).with(@commit_history).and_return(daniel)
22
+ daniel = MetricsGeneratorDaniel.new(@config, @commit_history)
23
+ expect(MetricsGeneratorDaniel).to receive(:new).with(@config, @commit_history).and_return(daniel)
21
24
  expect(daniel).to receive(:generate)
22
25
 
23
26
  @subject.generate_daniel
@@ -26,10 +29,10 @@ describe "Generate different types of code metrics" do
26
29
  it "generate csv format metrics" do
27
30
  @subject.commit_history = @commit_history
28
31
 
29
- csv = MetricsGeneratorCsv.new(@commit_history)
30
- expect(MetricsGeneratorCsv).to receive(:new).with(@commit_history).and_return(csv)
32
+ csv = MetricsGeneratorCsvFiles.new(@config, @commit_history)
33
+ expect(MetricsGeneratorCsvFiles).to receive(:new).with(@config, @commit_history).and_return(csv)
31
34
  expect(csv).to receive(:generate)
32
35
 
33
- @subject.generate_csv
36
+ @subject.generate_csv_files
34
37
  end
35
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codespicuous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bas Vodde
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-16 00:00:00.000000000 Z
11
+ date: 2017-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -91,6 +91,7 @@ files:
91
91
  - lib/codespicuous/dateutil.rb
92
92
  - lib/codespicuous/metrics_generator.rb
93
93
  - lib/codespicuous/metrics_generator_csv.rb
94
+ - lib/codespicuous/metrics_generator_csv_files.rb
94
95
  - lib/codespicuous/metrics_generator_daniel.rb
95
96
  - lib/codespicuous/participantsparser_from_csv.rb
96
97
  - lib/codespicuous/repositories.rb
@@ -108,6 +109,7 @@ files:
108
109
  - spec/committers_spec.rb
109
110
  - spec/danielparser_spec.rb
110
111
  - spec/integration_filezilla_spec.rb
112
+ - spec/metrics_generator_csv_files_spec.rb
111
113
  - spec/metrics_generator_csv_spec.rb
112
114
  - spec/metrics_generator_daniel_spec.rb
113
115
  - spec/metrics_generator_spec.rb