Module: Diggit::DevelopersActivity::ActivityExtractor

Extended by:
ActivityExtractor
Included in:
ActivityExtractor, Diggit::DevelopersActivity::Analyses::ActivityAnalysis
Defined in:
lib/diggit/developers_activity/activity_extractor.rb,
lib/diggit/developers_activity/activity_extractor/authors.rb,
lib/diggit/developers_activity/activity_extractor/modules.rb,
lib/diggit/developers_activity/activity_extractor/renames.rb

Overview

Set of functions extracting developers activity for a given set of commits

Defined Under Namespace

Modules: Authors, Modules, Renames

Instance Method Summary collapse

Instance Method Details

#extract_developers_activity(source, commits, commits_group_id = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/diggit/developers_activity/activity_extractor.rb', line 15

def extract_developers_activity(source, commits, commits_group_id = nil)
	return [] if commits.empty?
	contributions = Hash.new { |hash, key| hash[key] = { touches: 0, churn: 0 } }
	num_commits = 0

	commits.each do |commit|
		num_commits += 1

		author = Authors.get_author(commit)

		commit.parents.each do |parent|
			diff = parent.diff(commit, DIFF_OPTIONS)
			diff.find_similar!(DIFF_RENAME_OPTIONS)
			diff.each do |patch|
				maudule = Modules.get_patch_module(patch)
				next if maudule.nil?

				key = { author: author, 'module' => maudule }
				contributions[key] = { touches: contributions[key][:touches] + 1,
															churn: contributions[key][:churn] + patch.stat[0] + patch.stat[1] }
			end
		end
	end

	first_commit_date = commits[0].author[:time]

	# compute metrics and write to result
	developer_metrics = []
	contributions.each do |key, value|
		developer_metrics << { project: source.url, developer: key[:author], 'module' => key['module'],
			touches: value[:touches], churn: value[:churn], releaseDate: first_commit_date,
			commits_group_id: commits_group_id }
	end
	developer_metrics
end