meta_commit 0.1.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/meta_commit +5 -0
- data/lib/meta_commit/adapters/dump.rb +31 -0
- data/lib/meta_commit/adapters/git_notes.rb +28 -0
- data/lib/meta_commit/cli.rb +32 -0
- data/lib/meta_commit/git/repo.rb +60 -0
- data/lib/meta_commit/models/ast_path.rb +111 -0
- data/lib/meta_commit/models/changes/commit.rb +27 -0
- data/lib/meta_commit/models/changes/file.rb +27 -0
- data/lib/meta_commit/models/changes/repository.rb +18 -0
- data/lib/meta_commit/models/diffs/addition.rb +34 -0
- data/lib/meta_commit/models/diffs/changes_in_method.rb +14 -0
- data/lib/meta_commit/models/diffs/class_creation.rb +20 -0
- data/lib/meta_commit/models/diffs/class_deletion.rb +16 -0
- data/lib/meta_commit/models/diffs/class_rename.rb +11 -0
- data/lib/meta_commit/models/diffs/deletion.rb +37 -0
- data/lib/meta_commit/models/diffs/diff.rb +34 -0
- data/lib/meta_commit/models/diffs/method_creation.rb +22 -0
- data/lib/meta_commit/models/diffs/method_deletion.rb +22 -0
- data/lib/meta_commit/models/diffs/module_creation.rb +14 -0
- data/lib/meta_commit/models/diffs/module_deletion.rb +14 -0
- data/lib/meta_commit/models/diffs/module_rename.rb +11 -0
- data/lib/meta_commit/models/diffs/replacement.rb +19 -0
- data/lib/meta_commit/models/factories/ast_path_factory.rb +40 -0
- data/lib/meta_commit/models/factories/diff_factory.rb +39 -0
- data/lib/meta_commit/models/line.rb +5 -0
- data/lib/meta_commit/services/change_saver.rb +41 -0
- data/lib/meta_commit/services/commit_message_builder.rb +23 -0
- data/lib/meta_commit/services/diff_examiner.rb +121 -0
- data/lib/meta_commit/services/diff_index_examiner.rb +112 -0
- data/lib/meta_commit/version.rb +3 -0
- data/lib/meta_commit.rb +35 -0
- data/meta_commit.gemspec +30 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a91401c347971a081402085e903f5f38e481dec2
|
4
|
+
data.tar.gz: e3baa26014b744d0f3a0f3bf65bef1096588d6ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4853da029ca727831f4c6e12ce8b3daaa637ae9aed11d3a6e76f25348682a9776c15d33cade68fa3e5771ba4f08ed6199f997fdd12834825cdc5051a298a786
|
7
|
+
data.tar.gz: d7321d80c6bf1377633f889d829ca7379039b019948c0931c24cf1f901b84f8402ea0a5df72e30bb7539182f3c86f6b57d8b2fefb1095de6501ba0f6dd03cd13
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Stanislav Dobrovolskiy
|
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,40 @@
|
|
1
|
+
# meta commit
|
2
|
+
|
3
|
+
> Enrich commit diffs with programing language insights
|
4
|
+
|
5
|
+
|
6
|
+
## Description
|
7
|
+
|
8
|
+
[![v0.1 demonstration](https://asciinema.org/a/6nlvujsgeoa1xtp9l9qhx8lry.png)](https://asciinema.org/a/6nlvujsgeoa1xtp9l9qhx8lry?autoplay=1)
|
9
|
+
|
10
|
+
meta commit - is set of commands for git repository, which extracts useful information from commits and allows to get more insights from usual actions with repository.
|
11
|
+
|
12
|
+
Git is universal distributed version control system and works with minimal common units which exist in any file - strings. Meta commit is utility which gives git information about content of files in repo and changes between commits on level of programming language.
|
13
|
+
|
14
|
+
|
15
|
+
## Installing meta_commit
|
16
|
+
|
17
|
+
You can install gem with the following command in a terminal:
|
18
|
+
|
19
|
+
$ gem install meta_commit
|
20
|
+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Message
|
25
|
+
|
26
|
+
``` meta_commit message [--repo=$(pwd)] ```
|
27
|
+
|
28
|
+
Prints description of current changes in repository index
|
29
|
+
|
30
|
+
### Index
|
31
|
+
|
32
|
+
``` meta_commit index [--branch=master] [--repo=$(pwd)] ```
|
33
|
+
|
34
|
+
Walks over repository commits and writes meta information to git notes
|
35
|
+
|
36
|
+
### Changelog (NOT IMPLEMENTED)
|
37
|
+
|
38
|
+
``` meta_commit changelog [--from] [--to] [--repo=$(pwd)] ```
|
39
|
+
|
40
|
+
Walks over commits between tags ``` from ``` and ``` to ``` and writes main changes to changelog.md
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "meta_commit"
|
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
data/exe/meta_commit
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module MetaCommit::Adapters
|
2
|
+
class Dump
|
3
|
+
attr_accessor :repository, :commit, :file
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def write_repository_change_chunk(repository_change)
|
10
|
+
puts '---'
|
11
|
+
puts "repo id: #{repository_change.repo_id}"
|
12
|
+
puts '---'
|
13
|
+
end
|
14
|
+
|
15
|
+
def write_commit_change_chunk(commit_change)
|
16
|
+
puts "> commit : #{commit_change.commit_id}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def write_file_change_chunk(file_change)
|
20
|
+
puts "file : #{file_change.file_path}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_diff(diff)
|
24
|
+
puts " - #{diff}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_lines
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MetaCommit::Adapters
|
2
|
+
class GitNotes
|
3
|
+
attr_accessor :repository, :commit, :file
|
4
|
+
|
5
|
+
def initialize(repository)
|
6
|
+
@repository = repository
|
7
|
+
end
|
8
|
+
|
9
|
+
def write_repository_change_chunk(repository, repository_changes)
|
10
|
+
repository_changes.each do |commit_changes|
|
11
|
+
diffs=[]
|
12
|
+
commit_changes.each do |file_changes|
|
13
|
+
uniques_file_changes = file_changes.changes.uniq { |diff| diff.to_s }
|
14
|
+
uniques_file_changes.each do |diff|
|
15
|
+
diffs.push(" - #{diff.string_representation}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
write_to_notes(repository.path, commit_changes.new_commit_id, diffs.join("\n"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_to_notes(repo_path, commit_id, message)
|
23
|
+
# @TODO escape command
|
24
|
+
# @TODO add --ref=meta_commit
|
25
|
+
system("git --git-dir '#{repo_path}' notes add -f -m '#{message}' #{commit_id}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module MetaCommit
|
4
|
+
class ApplicationInterface < Thor
|
5
|
+
desc 'message [DIRECTORY]', 'generate message with summary of changes in repo located at DIRECTORY (or current directory if argument not passed)'
|
6
|
+
def message(repository_path=nil)
|
7
|
+
repository_path ||= Dir.pwd
|
8
|
+
repository = MetaCommit::Git::Repo.new(repository_path)
|
9
|
+
examiner = MetaCommit::Services::DiffIndexExaminer.new(repository)
|
10
|
+
meta = examiner.index_meta
|
11
|
+
message_builder = MetaCommit::Services::CommitMessageBuilder.new(repository)
|
12
|
+
message = message_builder.build(meta)
|
13
|
+
say(message)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'changelog', 'IS NOT IMPLEMENTED'
|
17
|
+
def changelog(path=nil)
|
18
|
+
raise('IS NOT IMPLEMENTED')
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'index [DIRECTORY]', 'indexing repository located at DIRECTORY (or current directory if argument not passed)'
|
22
|
+
def index(repository_path=nil)
|
23
|
+
repository_path ||= Dir.pwd
|
24
|
+
repository = MetaCommit::Git::Repo.new(repository_path)
|
25
|
+
examiner = MetaCommit::Services::DiffExaminer.new(repository)
|
26
|
+
meta = examiner.meta
|
27
|
+
change_saver = MetaCommit::Services::ChangeSaver.new(repository)
|
28
|
+
change_saver.store_meta(meta)
|
29
|
+
say('repository successfully indexed')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
|
3
|
+
module MetaCommit::Git
|
4
|
+
class Repo
|
5
|
+
attr_accessor :repo
|
6
|
+
|
7
|
+
def initialize(repo_path)
|
8
|
+
@repo = Rugged::Repository.new(repo_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def walker
|
12
|
+
walker = Rugged::Walker.new(@repo)
|
13
|
+
walker.sorting(Rugged::SORT_REVERSE)
|
14
|
+
walker.push(@repo.last_commit.oid)
|
15
|
+
walker
|
16
|
+
end
|
17
|
+
|
18
|
+
def walk_by_commits
|
19
|
+
walker = Rugged::Walker.new(@repo)
|
20
|
+
walker.sorting(Rugged::SORT_REVERSE)
|
21
|
+
walker.push(@repo.last_commit.oid)
|
22
|
+
previous_commit = nil
|
23
|
+
walker.each do |current_commit|
|
24
|
+
# skip first commit
|
25
|
+
previous_commit = current_commit if previous_commit.nil?
|
26
|
+
next if previous_commit == current_commit
|
27
|
+
yield(previous_commit, current_commit)
|
28
|
+
previous_commit = current_commit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def diff(left, right, options)
|
33
|
+
@repo.diff(left, right, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def index_diff(options)
|
37
|
+
@repo.index.diff(@repo.head.target.tree, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_blob_at(revision, path, default = nil)
|
41
|
+
blob = @repo.blob_at(revision, path)
|
42
|
+
return blob.content unless blob.nil?
|
43
|
+
default
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_content_of(rel_repo_file_path, default = nil)
|
47
|
+
absolute_file_path = @repo.path.reverse.sub('/.git'.reverse, '').reverse + rel_repo_file_path
|
48
|
+
begin
|
49
|
+
content = open(absolute_file_path).read
|
50
|
+
rescue Errno::ENOENT
|
51
|
+
content = default
|
52
|
+
end
|
53
|
+
content
|
54
|
+
end
|
55
|
+
|
56
|
+
def path
|
57
|
+
@repo.path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module MetaCommit::Models
|
2
|
+
class AstPath
|
3
|
+
attr_accessor :ast, :path
|
4
|
+
|
5
|
+
# region helpers
|
6
|
+
def is_module_definition?(node)
|
7
|
+
node.type == :module
|
8
|
+
end
|
9
|
+
|
10
|
+
def is_class_definition?(node)
|
11
|
+
node.type == :class
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_method_definition?(node)
|
15
|
+
node.type == :def
|
16
|
+
end
|
17
|
+
|
18
|
+
def extract_module_name(node)
|
19
|
+
node.children.first.children.last.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def extract_class_name(node)
|
23
|
+
node.children.first.children.last.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def extract_method_name(node)
|
27
|
+
node.children.first.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def empty_ast?
|
31
|
+
@ast.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
# endregion
|
35
|
+
|
36
|
+
# region external helpers
|
37
|
+
def is_module?
|
38
|
+
@ast.type == :module
|
39
|
+
end
|
40
|
+
|
41
|
+
def is_class?
|
42
|
+
@ast.type == :class
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_method?
|
46
|
+
@ast.type == :def
|
47
|
+
end
|
48
|
+
|
49
|
+
# on created class only first line goes to diff
|
50
|
+
def is_name_of_class?
|
51
|
+
(@ast.type == :const) and (@path.length > 1) and (@path[@path.length - 1 - 1].type == :class)
|
52
|
+
end
|
53
|
+
|
54
|
+
# on created module only first line goes to diff
|
55
|
+
def is_name_of_module?
|
56
|
+
(@ast.type == :const) and (@path.length > 1) and (@path[@path.length - 1 - 1].type == :module)
|
57
|
+
end
|
58
|
+
|
59
|
+
def module_name
|
60
|
+
@ast.children.first.children.last.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def class_name
|
64
|
+
@ast.children.first.children.last.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
def method_name
|
68
|
+
@ast.children.first.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def name_of_context_module
|
72
|
+
@path.reverse.each do |parent|
|
73
|
+
return extract_module_name(parent) if is_module_definition?(parent)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def name_of_context_class
|
78
|
+
@path.reverse.each do |parent|
|
79
|
+
return extract_class_name(parent) if is_class_definition?(parent)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def name_of_context_method
|
84
|
+
@path.reverse.each do |parent|
|
85
|
+
return extract_method_name(parent) if is_method_definition?(parent)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def is_in_context_of_module?
|
90
|
+
@path.each do |parent|
|
91
|
+
return true if is_module_definition?(parent)
|
92
|
+
end
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
def is_in_context_of_class?
|
97
|
+
@path.each do |parent|
|
98
|
+
return true if is_class_definition?(parent)
|
99
|
+
end
|
100
|
+
false
|
101
|
+
end
|
102
|
+
|
103
|
+
def is_in_context_of_method?
|
104
|
+
@path.each do |parent|
|
105
|
+
return true if is_method_definition?(parent)
|
106
|
+
end
|
107
|
+
false
|
108
|
+
end
|
109
|
+
# endregion
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MetaCommit::Models::Changes
|
2
|
+
class Commit
|
3
|
+
attr_accessor :old_commit_id, :new_commit_id, :file_changes
|
4
|
+
|
5
|
+
def initialize(old_commit_id, new_commit_id)
|
6
|
+
@old_commit_id = old_commit_id
|
7
|
+
@new_commit_id = new_commit_id
|
8
|
+
@file_changes = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def push(file_change)
|
12
|
+
@file_changes.push(file_change)
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit_id
|
16
|
+
if @old_commit_id == @new_commit_id
|
17
|
+
@new_commit_id
|
18
|
+
else
|
19
|
+
"#{@old_commit_id} -> #{@new_commit_id}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def each(&block)
|
24
|
+
@file_changes.each(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MetaCommit::Models::Changes
|
2
|
+
class File
|
3
|
+
attr_accessor :old_file_path, :new_file_path, :changes
|
4
|
+
|
5
|
+
def initialize(old_file_path, new_file_path)
|
6
|
+
@old_file_path = old_file_path
|
7
|
+
@new_file_path = new_file_path
|
8
|
+
@changes = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def push(change)
|
12
|
+
@changes.push(change)
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_path
|
16
|
+
if @new_file_path == @new_file_path
|
17
|
+
@new_file_path
|
18
|
+
else
|
19
|
+
"#{@old_file_path} -> #{@new_file_path}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def each(&block)
|
24
|
+
@changes.each(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MetaCommit::Models::Changes
|
2
|
+
class Repository
|
3
|
+
attr_accessor :repo_id, :commit_changes
|
4
|
+
|
5
|
+
def initialize(repo_id)
|
6
|
+
@repo_id = repo_id
|
7
|
+
@commit_changes = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def push(commit_change)
|
11
|
+
@commit_changes.push(commit_change)
|
12
|
+
end
|
13
|
+
|
14
|
+
def each(&block)
|
15
|
+
@commit_changes.each(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class Addition < Diff
|
3
|
+
def string_representation
|
4
|
+
action = 'created'
|
5
|
+
if @new_ast_path.is_class?
|
6
|
+
if @new_ast_path.is_in_context_of_module?
|
7
|
+
return "#{action} #{new_ast_path.name_of_context_module}::#{new_ast_path.class_name}"
|
8
|
+
end
|
9
|
+
return "#{action} class #{new_ast_path.class_name}"
|
10
|
+
end
|
11
|
+
if @new_ast_path.is_name_of_class?
|
12
|
+
if @new_ast_path.is_in_context_of_module?
|
13
|
+
return "#{action} #{new_ast_path.name_of_context_module}::#{new_ast_path.name_of_context_class}"
|
14
|
+
end
|
15
|
+
return "#{action} class #{new_ast_path.name_of_context_class}"
|
16
|
+
end
|
17
|
+
if @new_ast_path.is_method?
|
18
|
+
if @new_ast_path.is_in_context_of_class?
|
19
|
+
return "#{action} #{new_ast_path.name_of_context_class}##{new_ast_path.method_name}"
|
20
|
+
end
|
21
|
+
if @new_ast_path.is_in_context_of_module?
|
22
|
+
if @new_ast_path.is_in_context_of_class?
|
23
|
+
return "#{action} #{new_ast_path.name_of_context_module}::#{new_ast_path.name_of_context_class}##{new_ast_path.method_name}"
|
24
|
+
end
|
25
|
+
return "#{action} #{new_ast_path.name_of_context_module}##{new_ast_path.method_name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if @new_ast_path.is_in_context_of_method?
|
29
|
+
return "changes in method #{@new_ast_path.name_of_context_method}"
|
30
|
+
end
|
31
|
+
'addition was performed'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class ChangesInMethod < Diff
|
3
|
+
def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
|
4
|
+
type == MetaCommit::Models::Diffs::Diff::TYPE_REPLACE && !old_ast_path.empty_ast? && !new_ast_path.empty_ast? && old_ast_path.is_in_context_of_method? && new_ast_path.is_in_context_of_method?
|
5
|
+
end
|
6
|
+
|
7
|
+
def string_representation
|
8
|
+
if @new_ast_path.is_in_context_of_class?
|
9
|
+
return "changes in #{new_ast_path.name_of_context_class}##{new_ast_path.name_of_context_method}"
|
10
|
+
end
|
11
|
+
"changes in ##{new_ast_path.name_of_context_method}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class ClassCreation < Diff
|
3
|
+
def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
|
4
|
+
type == MetaCommit::Models::Diffs::Diff::TYPE_ADDITION && !new_ast_path.empty_ast? && (new_ast_path.is_class? || new_ast_path.is_name_of_class?)
|
5
|
+
end
|
6
|
+
|
7
|
+
def string_representation
|
8
|
+
if @new_ast_path.is_class?
|
9
|
+
if @new_ast_path.is_in_context_of_module?
|
10
|
+
return "created #{new_ast_path.name_of_context_module}::#{new_ast_path.class_name}"
|
11
|
+
end
|
12
|
+
return "created class #{new_ast_path.class_name}"
|
13
|
+
end
|
14
|
+
if @new_ast_path.is_in_context_of_module?
|
15
|
+
return "created #{new_ast_path.name_of_context_module}::#{new_ast_path.name_of_context_class}"
|
16
|
+
end
|
17
|
+
"created class #{new_ast_path.name_of_context_class}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class ClassDeletion < Diff
|
3
|
+
def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
|
4
|
+
type == MetaCommit::Models::Diffs::Diff::TYPE_DELETION && !old_ast_path.empty_ast? && (old_ast_path.is_class? || old_ast_path.is_name_of_class?)
|
5
|
+
end
|
6
|
+
|
7
|
+
def string_representation
|
8
|
+
if @old_ast_path.is_class?
|
9
|
+
if @old_ast_path.is_in_context_of_module?
|
10
|
+
return "removed class #{old_ast_path.class_name} from module #{old_ast_path.name_of_context_module}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
"removed class #{old_ast_path.name_of_context_class}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class ClassRename < Diff
|
3
|
+
def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
|
4
|
+
type == MetaCommit::Models::Diffs::Diff::TYPE_REPLACE && !old_ast_path.nil? && !new_ast_path.nil? && old_ast_path.is_name_of_class? && new_ast_path.is_name_of_class?
|
5
|
+
end
|
6
|
+
|
7
|
+
def string_representation
|
8
|
+
"renamed class #{old_ast_path.name_of_context_class} to #{new_ast_path.name_of_context_class}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class Deletion < Diff
|
3
|
+
def string_representation
|
4
|
+
action = 'removed'
|
5
|
+
if @old_ast_path.is_module?
|
6
|
+
return "#{action} module #{old_ast_path.module_name}"
|
7
|
+
end
|
8
|
+
if @old_ast_path.is_name_of_module?
|
9
|
+
return "#{action} module #{old_ast_path.name_of_context_module}"
|
10
|
+
end
|
11
|
+
if @old_ast_path.is_class?
|
12
|
+
if @_ast_path.is_in_context_of_module?
|
13
|
+
return "#{action} #{name_of_context_module}::#{new_ast_path.class_name}"
|
14
|
+
end
|
15
|
+
return "#{action} class #{old_ast_path.class_name}"
|
16
|
+
end
|
17
|
+
if @old_ast_path.is_name_of_class?
|
18
|
+
return "#{action} class #{old_ast_path.name_of_context_class}"
|
19
|
+
end
|
20
|
+
if @old_ast_path.is_method?
|
21
|
+
if @old_ast_path.is_in_context_of_class?
|
22
|
+
return "#{action} #{old_ast_path.name_of_context_class}##{old_ast_path.method_name}"
|
23
|
+
end
|
24
|
+
if @old_ast_path.is_in_context_of_module?
|
25
|
+
if @old_ast_path.is_in_context_of_class?
|
26
|
+
return "#{action} #{old_ast_path.name_of_context_module}::#{old_ast_path.name_of_context_class}##{old_ast_path.method_name}"
|
27
|
+
end
|
28
|
+
return "#{action} method #{old_ast_path.method_name} from module #{old_ast_path.name_of_context_module}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if @old_ast_path.is_in_context_of_method?
|
32
|
+
return "changes in method #{@old_ast_path.name_of_context_method}"
|
33
|
+
end
|
34
|
+
'deletion was performed'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module MetaCommit::Models::Diffs
|
2
|
+
class Diff
|
3
|
+
|
4
|
+
TYPE_ADDITION = :addition
|
5
|
+
TYPE_DELETION = :deletion
|
6
|
+
TYPE_REPLACE = :replace
|
7
|
+
|
8
|
+
attr_accessor :diff_type
|
9
|
+
attr_accessor :commit_old, :commit_new
|
10
|
+
attr_accessor :old_file, :new_file
|
11
|
+
attr_accessor :old_lineno, :new_lineno
|
12
|
+
attr_accessor :old_ast_path, :new_ast_path
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
string_representation
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
string_representation
|
20
|
+
end
|
21
|
+
|
22
|
+
def string_representation
|
23
|
+
"#{diff_type} was performed"
|
24
|
+
end
|
25
|
+
|
26
|
+
def supports_change_of_type(type)
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|