snaptoken 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 786cbd31e529a228b77a591237e1b43a0b64424e
4
- data.tar.gz: 92ed1c09c7e9bc60f10c6ca20dd2e69a47370cc9
3
+ metadata.gz: 6b7019ae6a9665013d03b3377750af5879bfa4ec
4
+ data.tar.gz: 39193a2e3bd1e88f24313e075b061da0cdc6bda0
5
5
  SHA512:
6
- metadata.gz: ab86847bef210f8b8462a6e152188d512e8cc3872d82178a4dc23b98e76fc75a4495a2a681a64077f5c912687b0b2e69c79317ea4e9f428b93a745404f453d10
7
- data.tar.gz: 14896c6ba8d42520d098b09ca2d62c4a2207ea1cb9e54cbf43c479d0c9d702f1358ffd3595f4a407c953b6a4d64a20c8c775dbd16345f14c8181f235d5f094fd
6
+ metadata.gz: a5da6724aa5aa4a7d7ded49658fb4cd0ee59996443312a46243b01bcb36d2c004eb2f84b851fde4d01f8ad38a6f2c4fe607a26f4108f62338601798bdb1978ce
7
+ data.tar.gz: 84dac34cc1d79540920043e3edcd1ca71b8dd3ccddd704c1a2384696bb7d8478606215782fc47b0a45bd224cbfb3ef99d3e3759ee6f87229e1726e89366c8ff4
@@ -91,14 +91,13 @@ class Snaptoken::Commands::BaseCommand
91
91
 
92
92
  def steps
93
93
  @steps ||= Dir[File.join(@config[:path], "steps/*")].map do |f|
94
- name = File.basename(f)
95
- name if File.directory?(f) && name =~ /\A\d+(\.\d+)*(-\w+)*\z/
96
- end.compact.sort_by { |s| s.split(".").map(&:to_i) }.reject { |s| s.to_i.zero? }
94
+ Snaptoken::Step.from_folder_name(File.basename(f)) if File.directory?(f)
95
+ end.compact.sort_by(&:number)
97
96
  end
98
97
 
99
98
  def current_step
100
99
  if @config[:step_path]
101
- File.basename(@config[:step_path])
100
+ Snaptoken::Step.from_folder_name(File.basename(@config[:step_path]))
102
101
  end
103
102
  end
104
103
 
@@ -110,19 +109,12 @@ class Snaptoken::Commands::BaseCommand
110
109
  current_step || latest_step
111
110
  end
112
111
 
113
- def step_name(step)
114
- parts = step.split('-')
115
- if parts.length > 1
116
- parts[1..-1].join('-')
117
- end
118
- end
119
-
120
112
  def step_path(step)
121
- File.join(@config[:path], "steps", step)
113
+ File.join(@config[:path], "steps", step.folder_name)
122
114
  end
123
115
 
124
116
  def select_step(step, &block)
125
- puts "Selecting step: #{step}"
117
+ puts "Selecting step: #{step.folder_name}"
126
118
  FileUtils.cd(step_path(step), &block)
127
119
  end
128
120
  end
@@ -19,12 +19,8 @@ class Snaptoken::Commands::Diff < Snaptoken::Commands::BaseCommand
19
19
  # skip
20
20
  elsif line =~ /^Subject: \[[^\]]*\](.*)$/
21
21
  f << "\n" unless step_num == 1
22
- step_name = $1.strip
23
- if step_name =~ /^\w+(-\w+)*$/
24
- f << "~~~ step: #{step_name}\n"
25
- else
26
- f << "~~~ step\n"
27
- end
22
+ step = Snaptoken::Step.from_commit_msg(step_num, $1.strip)
23
+ f << "~~~ step: #{step.commit_msg}\n"
28
24
  step_num += 1
29
25
  elsif line.chomp.length > 0
30
26
  f << line
@@ -72,19 +72,13 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
72
72
  diffs = {}
73
73
  FileUtils.cd("../steps") do
74
74
  FileUtils.mkdir_p("0")
75
- last_step = "0"
76
- Dir["*"].sort_by(&:to_i).each do |step|
77
- print "\r\e[K#{step}"
78
- names = [step.to_i.to_s]
79
- if step =~ /\d+\-([\w-]+)$/
80
- names << $1
81
- end
75
+ last_step = Snaptoken::Step.new(0, nil, [])
76
+ steps.each do |step|
77
+ print "\r\e[K#{step.folder_name}"
82
78
 
83
79
  diff = Snaptoken::Diff.new(@config, last_step, step)
84
80
 
85
- names.each do |name|
86
- diffs[name] = diff.html.values.join("\n")
87
- end
81
+ diffs[step.name] = diff.html.values.join("\n")
88
82
 
89
83
  last_step = step
90
84
  end
@@ -20,10 +20,9 @@ class Snaptoken::Commands::Ref < Snaptoken::Commands::BaseCommand
20
20
  walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
21
21
  walker.push(repo.branches.find { |b| b.name == "master" }.target)
22
22
  walker.each.with_index do |commit, idx|
23
- step_num = (idx + 1).to_s
24
- step_name = commit.message.lines.first.strip
23
+ step = Snaptoken::Step.from_commit_msg(idx + 1, commit.message.lines.first.strip)
25
24
 
26
- if (is_num && ref == step_num) || (!is_num && ref == step_name)
25
+ if (is_num && ref.to_i == step.number) || (!is_num && ref == step.name)
27
26
  puts commit.oid
28
27
  exit
29
28
  end
@@ -30,14 +30,14 @@ class Snaptoken::Commands::Repo < Snaptoken::Commands::BaseCommand
30
30
 
31
31
  options = {}
32
32
  options[:tree] = index.write_tree(repo)
33
- options[:message] = step_name(step) || "-"
33
+ options[:message] = step.commit_msg
34
34
  options[:parents] = repo.empty? ? [] : [repo.head.target]
35
35
  options[:update_ref] = 'HEAD'
36
36
 
37
37
  commit_oid = Rugged::Commit.create(repo, options)
38
38
 
39
- if step_name(step)
40
- repo.references.create("refs/tags/#{step_name(step)}", commit_oid)
39
+ if step.name
40
+ repo.references.create("refs/tags/#{step.name}", commit_oid)
41
41
  end
42
42
  end
43
43
 
@@ -15,33 +15,32 @@ class Snaptoken::Commands::Undiff < Snaptoken::Commands::BaseCommand
15
15
  FileUtils.cd("steps") do
16
16
  File.open("../steps.diff", "r") do |f|
17
17
  step_num = 0
18
- step_dir = nil
19
- prev_dir = nil
18
+ step = Snaptoken::Step.new(0, nil, [])
19
+ prev_step = nil
20
20
  cur_diff = nil
21
21
  while line = f.gets
22
- if line =~ /^~~~ step(: \w+(-\w+)*)?$/
22
+ if line =~ /^~~~ step: ([\s\w-]+)$/
23
23
  if cur_diff
24
- apply_diff(step_dir, cur_diff)
24
+ apply_diff(step, cur_diff)
25
25
  cur_diff = nil
26
26
  end
27
27
 
28
- step_num += 1
29
- step_dir = step_num.to_s
30
- step_dir += "-#{$1[2..-1]}" if $1
31
- if step_num == 1
32
- FileUtils.mkdir(step_dir)
28
+ prev_step = step
29
+ step = Snaptoken::Step.from_commit_msg(prev_step.number + 1, $1)
30
+
31
+ if step.number == 1
32
+ FileUtils.mkdir(step.folder_name)
33
33
  else
34
- FileUtils.cp_r(prev_dir, step_dir)
34
+ FileUtils.cp_r(prev_step.folder_name, step.folder_name)
35
35
  end
36
- prev_dir = step_dir
37
36
  elsif line =~ /^diff --git/
38
- apply_diff(step_dir, cur_diff) if cur_diff
37
+ apply_diff(step, cur_diff) if cur_diff
39
38
  cur_diff = line
40
39
  elsif cur_diff
41
40
  cur_diff << line
42
41
  end
43
42
  end
44
- apply_diff(step_dir, cur_diff) if cur_diff
43
+ apply_diff(step, cur_diff) if cur_diff
45
44
  end
46
45
  end
47
46
  end
@@ -49,8 +48,8 @@ class Snaptoken::Commands::Undiff < Snaptoken::Commands::BaseCommand
49
48
 
50
49
  private
51
50
 
52
- def apply_diff(dir, diff)
53
- stdin = IO.popen("git --git-dir= apply --directory=#{dir} -", "w")
51
+ def apply_diff(step, diff)
52
+ stdin = IO.popen("git --git-dir= apply \"--directory=#{step.folder_name}\" -", "w")
54
53
  stdin.write diff
55
54
  stdin.close
56
55
  end
@@ -19,14 +19,7 @@ class Snaptoken::Commands::Unrepo < Snaptoken::Commands::BaseCommand
19
19
  walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
20
20
  walker.push(repo.branches.find { |b| b.name == "master" }.target)
21
21
  walker.each.with_index do |commit, idx|
22
- step_num = (idx + 1).to_s
23
- step_name = commit.message.lines.first.strip
24
-
25
- if step_name.empty?
26
- step = step_num
27
- else
28
- step = "#{step_num}-#{step_name}"
29
- end
22
+ step = Snaptoken::Step.from_commit_msg(idx + 1, commit.message.lines.first.strip)
30
23
 
31
24
  repo.checkout(commit.oid, strategy: :force,
32
25
  target_directory: step_path(step))
@@ -1,20 +1,17 @@
1
1
  class Snaptoken::Diff
2
+ # -r for recursive?
2
3
  GIT_DIFF_OPTIONS = "--histogram --unified=100000 --ignore-space-change --no-index"
3
4
 
4
5
  attr_reader :files, :html
5
6
 
6
7
  def initialize(config, step_a, step_b)
7
- git_diff = `git diff #{GIT_DIFF_OPTIONS} #{step_a} #{step_b}`
8
+ git_diff = `git diff #{GIT_DIFF_OPTIONS} #{step_a.folder_name} #{step_b.folder_name}`
8
9
  parse_git_diff(git_diff)
9
10
  @files.values.each(&:omit_adjacent_removals!)
10
11
 
11
- step = step_b.split('-')
12
- step.shift
13
- step = step.join('-')
14
-
15
12
  @html = {}
16
13
  @files.each do |filename, file|
17
- @html[filename] = file.to_html(config[:name], step)
14
+ @html[filename] = file.to_html(config[:name], step_b)
18
15
  end
19
16
  end
20
17
 
@@ -109,7 +106,7 @@ class Snaptoken::Diff
109
106
 
110
107
  html = ""
111
108
  html << "<div class=\"diff\">\n"
112
- html << "<div class=\"filename\"><a href=\"https://github.com/snaptoken/#{project}/blob/#{step}/#{@filename}\">#{@filename}</a></div>\n"
109
+ html << "<div class=\"filename\"><a href=\"https://github.com/snaptoken/#{project}/blob/#{step.name}/#{@filename}\">#{@filename}</a></div>\n"
113
110
  html << "<pre class=\"highlight\"><code>"
114
111
 
115
112
  to_render = @contents.dup
@@ -0,0 +1,35 @@
1
+ class Snaptoken::Step
2
+ attr_accessor :number, :name, :data
3
+
4
+ def initialize(number, name, data)
5
+ @number, @name, @data = number, name, data
6
+ end
7
+
8
+ def folder_name
9
+ name = "#{@number}"
10
+ name << "-#{@name}" if @name
11
+ name << "+#{@data.join('+')}" if @data.length > 0
12
+ name
13
+ end
14
+
15
+ def commit_msg
16
+ if @data.empty?
17
+ @name
18
+ else
19
+ "#{@name} #{@data.join(' ')}"
20
+ end
21
+ end
22
+
23
+ def self.from_folder_name(folder)
24
+ if folder =~ /\A(\d+)-([\w-]+)(\+([\+\w-]*))?\z/
25
+ Snaptoken::Step.new($1.to_i, $2, $4.to_s.split('+'))
26
+ end
27
+ end
28
+
29
+ def self.from_commit_msg(number, msg)
30
+ if msg =~ /\A([\w-]+)(\s([\s\w-]*))?\z/
31
+ Snaptoken::Step.new(number, $1, $2.to_s.split)
32
+ end
33
+ end
34
+ end
35
+
data/lib/snaptoken.rb CHANGED
@@ -11,4 +11,5 @@ end
11
11
  require 'snaptoken/cli'
12
12
  require 'snaptoken/commands'
13
13
  require 'snaptoken/diff'
14
+ require 'snaptoken/step'
14
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snaptoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ruten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -75,6 +75,7 @@ files:
75
75
  - lib/snaptoken/commands/undiff.rb
76
76
  - lib/snaptoken/commands/unrepo.rb
77
77
  - lib/snaptoken/diff.rb
78
+ - lib/snaptoken/step.rb
78
79
  homepage: https://github.com/yjerem/leg
79
80
  licenses:
80
81
  - MIT