vcs2json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 808a2147f066558be1e90670f3979e9359150f91
4
+ data.tar.gz: 6e819f0ac8e0f882d9ad3ebcc17d3367c14a07e5
5
+ SHA512:
6
+ metadata.gz: ccc60734a7eaa93afe2d6210e9a6a8ea09046883c7ff76ca1c7fff5e736c30411c73d8b92b8eff856d17154dc2aa6ce1e60f098540efef926cf0ec39fea3a654
7
+ data.tar.gz: 8d9629e31d29a2060078543edc4ee586901dec1b111402944e23f6758b1c052b8d8130e71a32510aa25afbefac128b5efafb33ac7fe1b10beb51d3a7fdd19b80
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
4
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vcs2json.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Thomas Rolfsnes
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 THE
18
+ 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Vcs2json
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vcs2json`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vcs2json'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vcs2json
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vcs2json.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vcs2json"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/vcs2json ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/vcs2json_helper'
3
+ Vcs2JsonCLI::Main.start(ARGV)
@@ -0,0 +1 @@
1
+ require_relative '../vcs2json_helper'
data/lib/cli/main.rb ADDED
@@ -0,0 +1,14 @@
1
+ require_relative 'cli_helper'
2
+
3
+ module Vcs2JsonCLI
4
+ class Main < Thor
5
+ method_option :issue, :aliases => '-i', :type => :boolean, :default => false, :desc => "Attempt to extract issue ids from commit messages"
6
+ method_option :after, :aliases => '-a', :desc => "Only include commits after this date"
7
+ method_option :before, :aliases => '-b', :desc => "Only include commits before this date"
8
+ method_option :number, :aliases => '-n', :desc => "The number of commits to dump"
9
+ desc "git [options]","Make a dump of the change-history of system using git, output on stdout"
10
+ def git
11
+ Vcs2Json::Git.new(options).execute
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,86 @@
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
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,3 @@
1
+ module Vcs2json
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'thor'
2
+ require 'digest'
3
+ require 'json/pure'
4
+ require 'time'
5
+ require 'require_all'
6
+ require_rel '/**/*.rb'
data/vcs2json.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vcs2json/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vcs2json"
8
+ spec.version = Vcs2json::VERSION
9
+ spec.authors = ["Thomas Rolfsnes"]
10
+ spec.email = ["mail@thomasrolfsnes.com"]
11
+
12
+ spec.summary = %q{Create JSON dumps of change history from git etc.}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "bin"
17
+ spec.executables = ["vcs2json"]
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.10"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+
24
+ spec.add_runtime_dependency "thor"
25
+ spec.add_runtime_dependency "require_all"
26
+ spec.add_runtime_dependency "json_pure"
27
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vcs2json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Rolfsnes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: require_all
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json_pure
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - mail@thomasrolfsnes.com
100
+ executables:
101
+ - vcs2json
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - bin/vcs2json
115
+ - lib/cli/cli_helper.rb
116
+ - lib/cli/main.rb
117
+ - lib/vcs2json/git/json.rb
118
+ - lib/vcs2json/km/json.rb
119
+ - lib/vcs2json/version.rb
120
+ - lib/vcs2json_helper.rb
121
+ - vcs2json.gemspec
122
+ homepage:
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.2.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Create JSON dumps of change history from git etc.
146
+ test_files: []