vcs2json 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 808a2147f066558be1e90670f3979e9359150f91
4
- data.tar.gz: 6e819f0ac8e0f882d9ad3ebcc17d3367c14a07e5
3
+ metadata.gz: 15d7ae8091e66e7a08873392edccfcbb5a97fdd2
4
+ data.tar.gz: d0b611ebafc4ced7993371f8836e1f9aa81e6cbd
5
5
  SHA512:
6
- metadata.gz: ccc60734a7eaa93afe2d6210e9a6a8ea09046883c7ff76ca1c7fff5e736c30411c73d8b92b8eff856d17154dc2aa6ce1e60f098540efef926cf0ec39fea3a654
7
- data.tar.gz: 8d9629e31d29a2060078543edc4ee586901dec1b111402944e23f6758b1c052b8d8130e71a32510aa25afbefac128b5efafb33ac7fe1b10beb51d3a7fdd19b80
6
+ metadata.gz: 74b531c87495036b5f7622fc58310d9a9cb81ebe1eee55e3aa2d293cd15702ec7dc46cfdbebf97c8b2843009491d78d6f1b5b5e6e16aa1ec3b69ede98bf2f18c
7
+ data.tar.gz: e3fa836d920cc77295a10de443419fdd11e8ddef8e901b94acf85343cb5daf6de41934df344b14ce507865952d87d78281e3b10e04206243ade963b6df3b6c7a
data/lib/cli/main.rb CHANGED
@@ -8,7 +8,7 @@ module Vcs2JsonCLI
8
8
  method_option :number, :aliases => '-n', :desc => "The number of commits to dump"
9
9
  desc "git [options]","Make a dump of the change-history of system using git, output on stdout"
10
10
  def git
11
- Vcs2Json::Git.new(options).execute
11
+ $stdout.puts Vcs2Json::Git.new(options).execute
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class AmbigiousDate < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class CouldNotFindFormatOfDate < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class CouldNotParseDate < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class NoBasePath < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class NoDateField < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class NoFileSection < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Vcs2Json
2
+ module Exceptions
3
+ module KM
4
+ class NoTimeDataInChaFilesField < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,109 @@
1
+ require_relative '../vcs2json_helper'
2
+
3
+ module Vcs2Json
4
+ class Git
5
+ def initialize(opts)
6
+ @opts = opts
7
+ end
8
+
9
+
10
+ # simply un-abbreviates the status code given by --name-status
11
+ def parse_status(abbreviated_status)
12
+ case abbreviated_status
13
+ when "A"
14
+ "added"
15
+ when "M"
16
+ "modified"
17
+ when "D"
18
+ "deleted"
19
+ end
20
+ end
21
+
22
+
23
+ # attempts to parse an issue/bug id from the given commit message
24
+ def parse_issue(message)
25
+ if match = /(bug|issue) (?<id>\d+)/i.match(message)
26
+ return match[:id]
27
+ else
28
+ return ""
29
+ end
30
+ end
31
+
32
+
33
+ def execute
34
+ before = @opts[:before].nil? ? '' : "--before=\"#{@opts[:before]}\""
35
+ after = @opts[:after].nil? ? '' : "--after=\"#{@opts[:after]}\""
36
+ number = @opts[:number].nil? ? '' : "-n #{@opts[:number]}"
37
+ options = "#{before} #{after} #{number} --no-merges"
38
+
39
+ # Generate separators between fields and commits
40
+ field_sep = Digest::SHA256.hexdigest Time.new.to_s + "field_sep"
41
+ commit_sep = Digest::SHA256.hexdigest Time.new.to_s + "commit_sep"
42
+
43
+ # Create a new hash that defaults to creating new hashes given hash[:key]
44
+ # so we can do 'commit[:commit][:author][:name] = .. ' without creating the :commit and :author hashes first
45
+ commits = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc) }
46
+
47
+ #TODO: log this => print "Getting metadata on the commits..\r"
48
+ raw_commits = `git log #{options} --pretty=format:'%H#{field_sep}%cn#{field_sep}%ce#{field_sep}%cd#{field_sep}%ad#{field_sep}%B#{commit_sep}'`
49
+ commits_info = raw_commits.encode('UTF-8', :invalid => :replace).split(commit_sep)
50
+
51
+ commits_info.each do |commit|
52
+ fields = commit.split(field_sep)
53
+ sha = fields[0].delete("\n") #remove astray newlines
54
+ commits[sha][:sha] = sha
55
+ commits[sha][:name] = fields[1]
56
+ commits[sha][:email] = fields[2]
57
+ commits[sha][:date] = Time.parse fields[3]
58
+ commits[sha][:author_date] = Time.parse fields[4]
59
+ commits[sha][:message] = fields[5]
60
+
61
+ # attempt to parse an issue id from the commit message
62
+ if @opts.issue?
63
+ commits[commit[0]][:issue] = parse_issue(commits[sha][:message])
64
+ end
65
+ end
66
+
67
+
68
+ commits_changes_type = `git log --pretty=format:'#{field_sep}%H' --name-status #{options}`.split(field_sep)
69
+ commits_changes_type.each do |commit|
70
+ if !commit.empty?
71
+ lines = commit.split("\n")
72
+ sha = lines[0]
73
+ commits[sha][:changes][:all] = []
74
+ if lines.size > 1
75
+ lines[1..-1].each do |line|
76
+ if !line.empty?
77
+ file_info = line.split("\t")
78
+ file_name = file_info[1]
79
+ status = file_info[0]
80
+ commits[sha][:changes][:all] << file_name
81
+ commits[sha][:changes][:details][file_name][:filename] = file_name
82
+ commits[sha][:changes][:details][file_name][:status] = parse_status(status)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ # create file_name -> integer mapping
90
+ mapping = Hash.new
91
+ index_counter = 0
92
+ commits.each do |sha,info|
93
+ integer_representation = []
94
+ info[:changes][:all].each do |file|
95
+ if mapping[file].nil?
96
+ mapping[file] = index_counter
97
+ index_counter += 1
98
+ end
99
+ integer_representation << mapping[file]
100
+ info[:changes][:details][file][:id] = mapping[file]
101
+ end
102
+ info[:changes][:all].clear
103
+ info[:changes][:all] = integer_representation
104
+ end
105
+
106
+ JSON.pretty_generate(commits.sort_by {|id,commit| commit[:date]}.reverse.map {|(sha,commit)| commit})
107
+ end
108
+ end
109
+ end
@@ -1,3 +1,3 @@
1
1
  module Vcs2json
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,5 +2,7 @@ require 'thor'
2
2
  require 'digest'
3
3
  require 'json/pure'
4
4
  require 'time'
5
+ require 'csv'
6
+ require 'chronic'
5
7
  require 'require_all'
6
8
  require_rel '/**/*.rb'
data/vcs2json.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "thor"
25
25
  spec.add_runtime_dependency "require_all"
26
26
  spec.add_runtime_dependency "json_pure"
27
+ spec.add_runtime_dependency "chronic"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcs2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Rolfsnes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-23 00:00:00.000000000 Z
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: chronic
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description:
98
112
  email:
99
113
  - mail@thomasrolfsnes.com
@@ -114,8 +128,14 @@ files:
114
128
  - bin/vcs2json
115
129
  - lib/cli/cli_helper.rb
116
130
  - lib/cli/main.rb
117
- - lib/vcs2json/git/json.rb
118
- - lib/vcs2json/km/json.rb
131
+ - lib/exceptions/ambigious_date.rb
132
+ - lib/exceptions/could_not_find_format_of_date.rb
133
+ - lib/exceptions/could_not_parse_date.rb
134
+ - lib/exceptions/no_base_path.rb
135
+ - lib/exceptions/no_date_field.rb
136
+ - lib/exceptions/no_file_section.rb
137
+ - lib/exceptions/no_time_data_in_chafiles_field.rb
138
+ - lib/vcs2json/git.rb
119
139
  - lib/vcs2json/version.rb
120
140
  - lib/vcs2json_helper.rb
121
141
  - vcs2json.gemspec
@@ -139,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
159
  version: '0'
140
160
  requirements: []
141
161
  rubyforge_project:
142
- rubygems_version: 2.2.2
162
+ rubygems_version: 2.4.6
143
163
  signing_key:
144
164
  specification_version: 4
145
165
  summary: Create JSON dumps of change history from git etc.
@@ -1,86 +0,0 @@
1
- require_relative '../../vcs2json_helper'
2
-
3
- module Vcs2Json
4
- class Git
5
- def initialize(opts)
6
- @opts = opts
7
- end
8
-
9
-
10
- # simply un-abbreviates the status code given by --name-status
11
- def parse_status(abbreviated_status)
12
- case abbreviated_status
13
- when "A"
14
- "added"
15
- when "M"
16
- "modified"
17
- when "D"
18
- "deleted"
19
- end
20
- end
21
-
22
-
23
- # attempts to parse an issue/bug id from the given commit message
24
- def parse_issue(message)
25
- if match = /(bug|issue) (?<id>\d+)/i.match(message)
26
- return match[:id]
27
- else
28
- return ""
29
- end
30
- end
31
-
32
-
33
- def execute
34
- before = @opts[:before].nil? ? '' : "--before=\"#{@opts[:before]}\""
35
- after = @opts[:after].nil? ? '' : "--after=\"#{@opts[:after]}\""
36
- number = @opts[:number].nil? ? '' : "-n #{@opts[:number]}"
37
- options = "#{before} #{after} #{number} --no-merges"
38
-
39
- # Generate separators between fields and commits
40
- field_sep = Digest::SHA256.hexdigest Time.new.to_s + "field_sep"
41
- commit_sep = Digest::SHA256.hexdigest Time.new.to_s + "commit_sep"
42
-
43
- # Create a new hash that defaults to creating new hashes given hash[:key]
44
- # so we can do 'commit[:commit][:author][:name] = .. ' without creating the :commit and :author hashes first
45
- commits = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc) }
46
-
47
- #TODO: log this => print "Getting metadata on the commits..\r"
48
- raw_commits = `git log #{options} --pretty=format:'%h#{field_sep}%cn#{field_sep}%ce#{field_sep}%cd#{field_sep}%ad#{field_sep}%B#{commit_sep}'`
49
- commits_info = raw_commits.encode('UTF-8', :invalid => :replace).split(commit_sep)
50
-
51
- commits_info.each do |commit|
52
- fields = commit.split(field_sep)
53
- sha = fields[0].delete("\n") #remove astray newlines
54
- commits[sha][:sha] = sha
55
- commits[sha][:name] = fields[1]
56
- commits[sha][:email] = fields[2]
57
- commits[sha][:date] = Time.parse fields[3]
58
- commits[sha][:author_date] = Time.parse fields[4]
59
- commits[sha][:message] = fields[5]
60
-
61
- # attempt to parse an issue id from the commit message
62
- if @opts.issue?
63
- commits[commit[0]][:issue] = parse_issue(commits[sha][:message])
64
- end
65
- end
66
-
67
-
68
- #TODO: log this => print "Adding info on files changed.. \r"
69
- commits_changes_type = `git log --pretty=format:'%h' --name-status #{options}`.split("\n\n")
70
- commits_changes_type.each do |commit|
71
- lines = commit.split("\n")
72
- sha = lines[0]
73
- commits[sha][:changes][:all] = []
74
- lines[1..-1].each do |line|
75
- file_info = line.split("\t")
76
- file_name = file_info[1]
77
- status = file_info[0]
78
- commits[sha][:changes][:all] << file_name
79
- commits[sha][:changes][:details][file_name][:filename] = file_name
80
- commits[sha][:changes][:details][file_name][:status] = parse_status(status)
81
- end
82
- end
83
- $stdout.puts JSON.pretty_generate(commits.sort_by {|id,commit| commit[:date]}.reverse.map {|(sha,commit)| commit})
84
- end
85
- end
86
- end
@@ -1,14 +0,0 @@
1
- require_relative '../../vcs2json_helper'
2
-
3
- module Tarma
4
- module TransactionExtractor
5
- ##
6
- # This is primarily a version history parser for KMs use of the Track tool
7
- module Track
8
-
9
- def initialize(opts)
10
- self.opts = opts
11
- end
12
- end
13
- end
14
- end