archaeologist 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/bin/commitlang.rb +27 -0
- data/lib/archaeologist.rb +2 -0
- data/lib/archaeologist/analyzer.rb +32 -0
- data/lib/archaeologist/repowalker.rb +99 -0
- data/spec/multibranch_spec.rb +91 -0
- data/spec/repos/multibranch/LICENSE.md +21 -0
- data/spec/repos/multibranch/fzbz.py +23 -0
- data/spec/repos/multibranch/tests.py +25 -0
- data/spec/repos/singlebranch/LICENSE.md +21 -0
- data/spec/repos/singlebranch/fzbz.py +23 -0
- data/spec/repos/singlebranch/tests.py +25 -0
- data/spec/singlebranch_spec.rb +82 -0
- data/spec/spec_helper.rb +104 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e754532a6e43d088fe8a28dd035f8f44c47ed9d7ac83bf0a1a47fbb3c612fcb3
|
4
|
+
data.tar.gz: 97a4d419d7213d6e1f1e73a7626620f05993ba3353f21fa22b9d7ac5cbca3182
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3dfd228c744e129bb10b925084e7f63c3462d8c38bdd1401ba32ff5c5ceb6d8bc4aa92a50e9bf5832561b25350e7c6ba812ac49d5e7d20eaeedc77d7c7f01cb
|
7
|
+
data.tar.gz: bae1e824602d0f586875905bfc733ed27851bb0c6dda795dc8951a69354cf1a2bf9a40df9a07025e8cf31a1f2b6930b1bb006d87d4b7f06cad756bd4674e9988
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# The MIT License
|
2
|
+
|
3
|
+
Copyright 2019- Hiroaki Yamamoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
18
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/bin/commitlang.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'json/ext'
|
4
|
+
require_relative "../lib/repowalker.rb"
|
5
|
+
require_relative "../lib/analyzer.rb"
|
6
|
+
require 'parallel'
|
7
|
+
|
8
|
+
def main(repo_path, email)
|
9
|
+
walker = Archaeologist::RepoWalker.new(repo_path, email)
|
10
|
+
commits = []
|
11
|
+
walker.each { |c, lang|
|
12
|
+
commits << [c, lang]
|
13
|
+
}
|
14
|
+
results = Parallel.map(commits){ |el|
|
15
|
+
c = el[0]
|
16
|
+
lang = el[1]
|
17
|
+
a = Archaeologist::GitStatLangAnalyser.new(c, lang)
|
18
|
+
ar = a.analyze()
|
19
|
+
{ 'oid': c.oid, 'languages': ar, 'time': c.time }.to_json
|
20
|
+
}
|
21
|
+
results.map! {|js| JSON.parse js}
|
22
|
+
puts(JSON.pretty_generate(results))
|
23
|
+
end
|
24
|
+
|
25
|
+
if __FILE__ == $0
|
26
|
+
main(ARGV[0], ARGV[1])
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
module Archaeologist
|
4
|
+
class GitStatLangAnalyser
|
5
|
+
def initialize(cobj, lang)
|
6
|
+
@c = cobj
|
7
|
+
@lang = lang
|
8
|
+
end
|
9
|
+
|
10
|
+
def analyze()
|
11
|
+
result = {}
|
12
|
+
diff = (@c.parents.empty?) ?
|
13
|
+
@c.diff(nil, reverse: true):
|
14
|
+
@c.parents[0].diff(@c)
|
15
|
+
diff.find_similar!()
|
16
|
+
@lang.breakdown_by_file().each { |l, files|
|
17
|
+
diff.deltas.zip(diff.patches).each { |el|
|
18
|
+
delta = el[0]
|
19
|
+
patch = el[1]
|
20
|
+
if files.include?(delta.new_file[:path]) ||
|
21
|
+
files.include?(delta.old_file[:path])
|
22
|
+
status = result.fetch(l, {'add': 0, 'del': 0})
|
23
|
+
status[:add] += patch.additions
|
24
|
+
status[:del] += patch.deletions
|
25
|
+
result[l] = status
|
26
|
+
end
|
27
|
+
}
|
28
|
+
}
|
29
|
+
return result
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'rugged'
|
4
|
+
require 'linguist'
|
5
|
+
|
6
|
+
class Linguist::Repository
|
7
|
+
protected
|
8
|
+
def compute_stats(old_commit_oid, cache = nil)
|
9
|
+
# Patch normal compute_stats to calculate deleted files.
|
10
|
+
return {} if current_tree.count_recursive(MAX_TREE_SIZE) >= MAX_TREE_SIZE
|
11
|
+
|
12
|
+
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
|
13
|
+
read_index
|
14
|
+
diff = Rugged::Tree.diff(repository, old_tree, current_tree)
|
15
|
+
|
16
|
+
# Clear file map and fetch full diff if any .gitattributes files are changed
|
17
|
+
if cache && diff.each_delta.any? { |delta| File.basename(delta.new_file[:path]) == ".gitattributes" }
|
18
|
+
diff = Rugged::Tree.diff(repository, old_tree = nil, current_tree)
|
19
|
+
file_map = {}
|
20
|
+
else
|
21
|
+
file_map = cache ? cache.dup : {}
|
22
|
+
end
|
23
|
+
|
24
|
+
diff.each_delta do |delta|
|
25
|
+
old = delta.old_file[:path]
|
26
|
+
new = delta.new_file[:path]
|
27
|
+
|
28
|
+
file_map.delete(old)
|
29
|
+
next if delta.binary
|
30
|
+
|
31
|
+
if [:added, :modified].include? delta.status
|
32
|
+
# Skip submodules and symlinks
|
33
|
+
mode = delta.new_file[:mode]
|
34
|
+
mode_format = (mode & 0170000)
|
35
|
+
next if mode_format == 0120000 || mode_format == 040000 || mode_format == 0160000
|
36
|
+
|
37
|
+
blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8))
|
38
|
+
|
39
|
+
if blob.include_in_language_stats?
|
40
|
+
file_map[new] = [blob.language.group.name, blob.size]
|
41
|
+
end
|
42
|
+
|
43
|
+
blob.cleanup!
|
44
|
+
end
|
45
|
+
# NOTE: These lines are newly added. When the behavor of this function
|
46
|
+
# is changed, make sure below lines are included:
|
47
|
+
if delta.status == :deleted
|
48
|
+
mode = delta.old_file[:mode]
|
49
|
+
mode_format = (mode & 0170000)
|
50
|
+
next if mode_format == 0120000 || mode_format == 040000 || mode_format == 0160000
|
51
|
+
|
52
|
+
blob = Linguist::LazyBlob.new(repository, delta.old_file[:oid], old, mode.to_s(8))
|
53
|
+
|
54
|
+
if blob.include_in_language_stats?
|
55
|
+
file_map[old] = [blob.language.group.name, blob.size]
|
56
|
+
end
|
57
|
+
|
58
|
+
blob.cleanup!
|
59
|
+
end
|
60
|
+
# NOTE: the end of the new behavior.
|
61
|
+
end
|
62
|
+
|
63
|
+
file_map
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module Archaeologist
|
68
|
+
class RepoWalker
|
69
|
+
def initialize(repo, email)
|
70
|
+
@repo = Rugged::Repository.new(repo)
|
71
|
+
@email = email
|
72
|
+
end
|
73
|
+
|
74
|
+
def each()
|
75
|
+
walker = Rugged::Walker.new(@repo)
|
76
|
+
already_walked = []
|
77
|
+
@repo.branches.each { |br|
|
78
|
+
cur_l = nil
|
79
|
+
cur_oid = nil
|
80
|
+
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
|
81
|
+
walker.push(br.target_id)
|
82
|
+
walker.each { |c|
|
83
|
+
cur_l = c.parents.empty? ?
|
84
|
+
Linguist::Repository.new(@repo, c.oid) :
|
85
|
+
Linguist::Repository.incremental(
|
86
|
+
@repo, c.oid, cur_oid, cur_l.cache
|
87
|
+
)
|
88
|
+
cur_oid = c.oid
|
89
|
+
if (c.author[:email] == @email || !@email&.size) &&
|
90
|
+
!already_walked.include?(c.oid)
|
91
|
+
already_walked << c.oid
|
92
|
+
yield(c, cur_l)
|
93
|
+
end
|
94
|
+
}
|
95
|
+
}
|
96
|
+
walker.reset()
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require_relative "../lib/archaeologist";
|
4
|
+
|
5
|
+
describe "Multi Branch" do
|
6
|
+
describe "With Email" do
|
7
|
+
before :example do
|
8
|
+
walker = Archaeologist::RepoWalker.new(File.join(
|
9
|
+
File.dirname(__FILE__), "repos", "multibranch"
|
10
|
+
), "5356011+hiroaki-yamamoto@users.noreply.github.com")
|
11
|
+
@commits = []
|
12
|
+
walker.each { |c, lang|
|
13
|
+
@commits << [c, lang]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
it "Should have proper ruby and python changes" do
|
17
|
+
results = JSON.parse(@commits.map { |el|
|
18
|
+
c = el[0]
|
19
|
+
lang = el[1]
|
20
|
+
a = Archaeologist::GitStatLangAnalyser.new(c, lang)
|
21
|
+
ar = a.analyze()
|
22
|
+
{ 'oid': c.oid, 'languages': ar, 'time': c.time }
|
23
|
+
}.to_json())
|
24
|
+
expect(results).to eql JSON.parse([
|
25
|
+
{
|
26
|
+
"oid": '9fb8d2b9dac1d76c66f93e6f0da0a267f32e0f8d',
|
27
|
+
"languages": {
|
28
|
+
"Python": { "add": 0, "del": 48 },
|
29
|
+
"Ruby": {"add": 172, "del": 0}
|
30
|
+
},
|
31
|
+
"time": "2019-01-15 20:53:40 +0900"
|
32
|
+
}
|
33
|
+
].to_json())
|
34
|
+
end
|
35
|
+
end
|
36
|
+
describe "Without Email" do
|
37
|
+
before :example do
|
38
|
+
walker = Archaeologist::RepoWalker.new(
|
39
|
+
File.join(File.dirname(__FILE__), "repos", "multibranch"), nil
|
40
|
+
)
|
41
|
+
@commits = []
|
42
|
+
walker.each { |c, lang|
|
43
|
+
@commits << [c, lang]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
it "Should analyze all commits" do
|
47
|
+
results = JSON.parse(@commits.map { |el|
|
48
|
+
c = el[0]
|
49
|
+
lang = el[1]
|
50
|
+
a = Archaeologist::GitStatLangAnalyser.new(c, lang)
|
51
|
+
ar = a.analyze()
|
52
|
+
{ 'oid': c.oid, 'languages': ar, 'time': c.time }
|
53
|
+
}.to_json())
|
54
|
+
expect(results).to match_array JSON.parse([
|
55
|
+
{
|
56
|
+
"oid": "0c7377bff42588dbb596b65bfba91977f41eb5c9",
|
57
|
+
"languages": { "Python": { "add": 22, "del": 0 } },
|
58
|
+
"time": "2019-01-15 09:34:02 +0900"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"oid": "ce2672b453c35b76b37c3beeac6b7308097a83be",
|
62
|
+
"languages": { "Python": { "add": 34, "del": 1 } },
|
63
|
+
"time": "2019-01-15 09:46:32 +0900"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"oid": "a6617fec33cd3bba4e243b467c29596c28331953",
|
67
|
+
"languages": { "Python": { "add": 4, "del": 11 } },
|
68
|
+
"time": "2019-01-15 09:46:55 +0900"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"oid": 'cddcaa40e9e160c7aec09bc79d2c2d25c3e6bb88',
|
72
|
+
"languages": { "Python": { "add": 6, "del": 6 } },
|
73
|
+
"time": "2019-01-15 10:34:59 +0900"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"oid"=>"9eb9d80f358538df8c43eb986b3c7b7047be8756",
|
77
|
+
"languages": {},
|
78
|
+
"time": "2019-01-15 19:25:35 +0900"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"oid": '9fb8d2b9dac1d76c66f93e6f0da0a267f32e0f8d',
|
82
|
+
"languages": {
|
83
|
+
"Python": { "add": 0, "del": 48 },
|
84
|
+
"Ruby": {"add": 172, "del": 0}
|
85
|
+
},
|
86
|
+
"time": "2019-01-15 20:53:40 +0900"
|
87
|
+
}
|
88
|
+
].to_json)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# The MIT License
|
2
|
+
|
3
|
+
Copyright 2019- Hiroaki Yamamoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
18
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""Test fixture that is written in python."""
|
5
|
+
|
6
|
+
class FizzBuzz(object):
|
7
|
+
"""FizzBuzz."""
|
8
|
+
|
9
|
+
def __init__(self, init: int=0):
|
10
|
+
"""Init."""
|
11
|
+
self.__num = init
|
12
|
+
|
13
|
+
def __call__(self) -> str:
|
14
|
+
"""Call."""
|
15
|
+
ret = []
|
16
|
+
if self.__num % 3 == 0:
|
17
|
+
ret.append("Fizz")
|
18
|
+
if self.__num % 5 == 0:
|
19
|
+
ret.append("Buzz")
|
20
|
+
if not ret:
|
21
|
+
ret.append(str(self.__num))
|
22
|
+
self.__num += 1
|
23
|
+
return ("").join(ret)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""The tests."""
|
5
|
+
|
6
|
+
from unittest import TestCase
|
7
|
+
from fzbz import FizzBuzz
|
8
|
+
|
9
|
+
class FzBzTest(TestCase):
|
10
|
+
"""Fizz Buzz Test."""
|
11
|
+
|
12
|
+
def setUp(self):
|
13
|
+
"""Setup."""
|
14
|
+
self.obj = FizzBuzz()
|
15
|
+
|
16
|
+
def test_num(self):
|
17
|
+
"""The return value should be based of FizzBuzz."""
|
18
|
+
for n in range(100):
|
19
|
+
with self.subTest(n=n):
|
20
|
+
ret = self.obj()
|
21
|
+
exp = "FizzBuzz" if n % 3 == 0 and n % 5 == 0 else \
|
22
|
+
"Fizz" if n % 3 == 0 and n % 5 != 0 else \
|
23
|
+
"Buzz" if n % 3 != 0 and n % 5 == 0 else \
|
24
|
+
str(n)
|
25
|
+
self.assertEqual(ret, exp)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# The MIT License
|
2
|
+
|
3
|
+
Copyright 2019- Hiroaki Yamamoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
18
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""Test fixture that is written in python."""
|
5
|
+
|
6
|
+
class FizzBuzz(object):
|
7
|
+
"""FizzBuzz."""
|
8
|
+
|
9
|
+
def __init__(self, init: int=0):
|
10
|
+
"""Init."""
|
11
|
+
self.__num = init
|
12
|
+
|
13
|
+
def __call__(self) -> str:
|
14
|
+
"""Call."""
|
15
|
+
ret = []
|
16
|
+
if self.__num % 3 == 0:
|
17
|
+
ret.append("Fizz")
|
18
|
+
if self.__num % 5 == 0:
|
19
|
+
ret.append("Buzz")
|
20
|
+
if not ret:
|
21
|
+
ret.append(str(self.__num))
|
22
|
+
self.__num += 1
|
23
|
+
return ("").join(ret)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""The tests."""
|
5
|
+
|
6
|
+
from unittest import TestCase
|
7
|
+
from fzbz import FizzBuzz
|
8
|
+
|
9
|
+
class FzBzTest(TestCase):
|
10
|
+
"""Fizz Buzz Test."""
|
11
|
+
|
12
|
+
def setUp(self):
|
13
|
+
"""Setup."""
|
14
|
+
self.obj = FizzBuzz()
|
15
|
+
|
16
|
+
def test_num(self):
|
17
|
+
"""The return value should be based of FizzBuzz."""
|
18
|
+
for n in range(100):
|
19
|
+
with self.subTest(n=n):
|
20
|
+
ret = self.obj()
|
21
|
+
exp = "FizzBuzz" if n % 3 == 0 and n % 5 == 0 else \
|
22
|
+
"Fizz" if n % 3 == 0 and n % 5 != 0 else \
|
23
|
+
"Buzz" if n % 3 != 0 and n % 5 == 0 else \
|
24
|
+
str(n)
|
25
|
+
self.assertEqual(ret, exp)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'json/ext'
|
4
|
+
|
5
|
+
require_relative "../lib/archaeologist"
|
6
|
+
|
7
|
+
describe "Single Branch" do
|
8
|
+
describe "With Email" do
|
9
|
+
before :example do
|
10
|
+
walker = Archaeologist::RepoWalker.new(File.join(
|
11
|
+
File.dirname(__FILE__), "repos", "singlebranch"
|
12
|
+
), "testing@githistorydigger.com")
|
13
|
+
@commits = []
|
14
|
+
walker.each { |c, lang|
|
15
|
+
@commits << [c, lang]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
it "Should be 6 add and 6 del with python code" do
|
19
|
+
results = JSON.parse(@commits.map { |el|
|
20
|
+
c = el[0]
|
21
|
+
lang = el[1]
|
22
|
+
a = Archaeologist::GitStatLangAnalyser.new(c, lang)
|
23
|
+
ar = a.analyze()
|
24
|
+
{ 'oid': c.oid, 'languages': ar, 'time': c.time }
|
25
|
+
}.to_json())
|
26
|
+
expect(results).to eql JSON.parse([
|
27
|
+
{
|
28
|
+
"oid": 'cddcaa40e9e160c7aec09bc79d2c2d25c3e6bb88',
|
29
|
+
"languages": { "Python": { "add": 6, "del": 6 } },
|
30
|
+
"time": "2019-01-15 10:34:59 +0900"
|
31
|
+
}
|
32
|
+
].to_json())
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe "Without Email" do
|
36
|
+
before :example do
|
37
|
+
walker = Archaeologist::RepoWalker.new(
|
38
|
+
File.join(File.dirname(__FILE__), "repos", "singlebranch"), nil
|
39
|
+
)
|
40
|
+
@commits = []
|
41
|
+
walker.each { |c, lang|
|
42
|
+
@commits << [c, lang]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
it "Should analyze all commits" do
|
46
|
+
results = JSON.parse(@commits.map { |el|
|
47
|
+
c = el[0]
|
48
|
+
lang = el[1]
|
49
|
+
a = Archaeologist::GitStatLangAnalyser.new(c, lang)
|
50
|
+
ar = a.analyze()
|
51
|
+
{ 'oid': c.oid, 'languages': ar, 'time': c.time }
|
52
|
+
}.to_json())
|
53
|
+
expect(results).to match_array JSON.parse([
|
54
|
+
{
|
55
|
+
"oid": "0c7377bff42588dbb596b65bfba91977f41eb5c9",
|
56
|
+
"languages": { "Python": { "add": 22, "del": 0 } },
|
57
|
+
"time": "2019-01-15 09:34:02 +0900"
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"oid": "ce2672b453c35b76b37c3beeac6b7308097a83be",
|
61
|
+
"languages": { "Python": { "add": 34, "del": 1 } },
|
62
|
+
"time": "2019-01-15 09:46:32 +0900"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"oid": "a6617fec33cd3bba4e243b467c29596c28331953",
|
66
|
+
"languages": { "Python": { "add": 4, "del": 11 } },
|
67
|
+
"time": "2019-01-15 09:46:55 +0900"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"oid": 'cddcaa40e9e160c7aec09bc79d2c2d25c3e6bb88',
|
71
|
+
"languages": { "Python": { "add": 6, "del": 6 } },
|
72
|
+
"time": "2019-01-15 10:34:59 +0900"
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"oid"=>"9eb9d80f358538df8c43eb986b3c7b7047be8756",
|
76
|
+
"languages": {},
|
77
|
+
"time": "2019-01-15 19:25:35 +0900"
|
78
|
+
}
|
79
|
+
].to_json)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
require 'simplecov'
|
17
|
+
SimpleCov.start {
|
18
|
+
add_filter %r{^/spec/}
|
19
|
+
}
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# rspec-expectations config goes here. You can use an alternate
|
22
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
23
|
+
# assertions if you prefer.
|
24
|
+
config.expect_with :rspec do |expectations|
|
25
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
26
|
+
# and `failure_message` of custom matchers include text for helper methods
|
27
|
+
# defined using `chain`, e.g.:
|
28
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
29
|
+
# # => "be bigger than 2 and smaller than 4"
|
30
|
+
# ...rather than:
|
31
|
+
# # => "be bigger than 2"
|
32
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
36
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
37
|
+
config.mock_with :rspec do |mocks|
|
38
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
39
|
+
# a real object. This is generally recommended, and will default to
|
40
|
+
# `true` in RSpec 4.
|
41
|
+
mocks.verify_partial_doubles = true
|
42
|
+
end
|
43
|
+
|
44
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
45
|
+
# have no way to turn it off -- the option exists only for backwards
|
46
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
47
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
48
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
49
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
50
|
+
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
53
|
+
=begin
|
54
|
+
# This allows you to limit a spec run to individual examples or groups
|
55
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
56
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
57
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
58
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
59
|
+
config.filter_run_when_matching :focus
|
60
|
+
|
61
|
+
# Allows RSpec to persist some state between runs in order to support
|
62
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
63
|
+
# you configure your source control system to ignore this file.
|
64
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
65
|
+
|
66
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
67
|
+
# recommended. For more details, see:
|
68
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
69
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
70
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
71
|
+
config.disable_monkey_patching!
|
72
|
+
|
73
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
74
|
+
# be too noisy due to issues in dependencies.
|
75
|
+
config.warnings = true
|
76
|
+
|
77
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
78
|
+
# file, and it's useful to allow more verbose output when running an
|
79
|
+
# individual spec file.
|
80
|
+
if config.files_to_run.one?
|
81
|
+
# Use the documentation formatter for detailed output,
|
82
|
+
# unless a formatter has already been configured
|
83
|
+
# (e.g. via a command-line flag).
|
84
|
+
config.default_formatter = "doc"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Print the 10 slowest examples and example groups at the
|
88
|
+
# end of the spec run, to help surface which specs are running
|
89
|
+
# particularly slow.
|
90
|
+
config.profile_examples = 10
|
91
|
+
|
92
|
+
# Run specs in random order to surface order dependencies. If you find an
|
93
|
+
# order dependency and want to debug it, you can fix the order by providing
|
94
|
+
# the seed, which is printed after each run.
|
95
|
+
# --seed 1234
|
96
|
+
config.order = :random
|
97
|
+
|
98
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
99
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
100
|
+
# test failures related to randomization by passing the same `--seed` value
|
101
|
+
# as the one that triggered the failure.
|
102
|
+
Kernel.srand config.seed
|
103
|
+
=end
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: archaeologist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroaki Yamamoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: github-linguist
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parallel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.16.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.16.1
|
69
|
+
description: Github-linguist based language detector per a commit
|
70
|
+
email: rubygems@hysoftware.net
|
71
|
+
executables:
|
72
|
+
- commitlang.rb
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.md
|
77
|
+
- bin/commitlang.rb
|
78
|
+
- lib/archaeologist.rb
|
79
|
+
- lib/archaeologist/analyzer.rb
|
80
|
+
- lib/archaeologist/repowalker.rb
|
81
|
+
- spec/multibranch_spec.rb
|
82
|
+
- spec/repos/multibranch/LICENSE.md
|
83
|
+
- spec/repos/multibranch/fzbz.py
|
84
|
+
- spec/repos/multibranch/tests.py
|
85
|
+
- spec/repos/singlebranch/LICENSE.md
|
86
|
+
- spec/repos/singlebranch/fzbz.py
|
87
|
+
- spec/repos/singlebranch/tests.py
|
88
|
+
- spec/singlebranch_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage:
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.0.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Language detector for git
|
113
|
+
test_files:
|
114
|
+
- spec/multibranch_spec.rb
|
115
|
+
- spec/repos/multibranch/LICENSE.md
|
116
|
+
- spec/repos/multibranch/fzbz.py
|
117
|
+
- spec/repos/multibranch/tests.py
|
118
|
+
- spec/repos/singlebranch/LICENSE.md
|
119
|
+
- spec/repos/singlebranch/fzbz.py
|
120
|
+
- spec/repos/singlebranch/tests.py
|
121
|
+
- spec/singlebranch_spec.rb
|
122
|
+
- spec/spec_helper.rb
|