jekyll-git-authors 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: ad4da7350ddf894bb087396bbcdd866cc128e03d7678c471f56e6ea08fafc4e2
4
- data.tar.gz: 3b92eef4c6399de9bc9384331ef53bebf38c2b300dd7b49d564232e68eade1d8
3
+ metadata.gz: 73738a3355402aebd9970f7e614524d0ce9a966f9f9589051f9cc95cbec334b9
4
+ data.tar.gz: 16431182d8bda9f840291c0b8545e7ea247b20b17f7252fbc3d45d497e1488d3
5
5
  SHA512:
6
- metadata.gz: 2fc25d3f46dba490466259ce48d19d16fecf30d8abc3edcf4584929d64f088f821418e2788c7d170fcdc8a6d273124fc98aed8d12c4e73d22b2397fab0db22f0
7
- data.tar.gz: 0e832ecd08ec6d381eebae13bc5c36bd080f1674a6aee10d2e8a21202fdfa3a9bca783c47f12aaf2b74a4918698f11481bd73d2eab402ab67785358cc3f33cd0
6
+ metadata.gz: f8a0275a90429c8f5136689dbfc3ecf112de4967ffddb2bc2783992487c9794b31e1c5c4070589f1bfd807f850740cf9496d281a43a79131886a919b7487fbe7
7
+ data.tar.gz: 18c332e37a3308d65a172705b5949dba8351b33da4dd6550fb628a772628b2f7e85a5ff37d05e85cf67ff803a3266e771e4035835da197358fb7cbc4d242a506
File without changes
@@ -0,0 +1,19 @@
1
+ Feature: Jekyll renders output of jekyll-git-authors
2
+
3
+ Background:
4
+ Given There is a fixture named "page.md" and it is in a subdirectory named "subdir"
5
+ And Git is intialized
6
+
7
+ Scenario: Authors are generated correctly
8
+ Given There are 6 commits on the "subdir/page.md"
9
+ And All commits on "subdir/page.md" have different authors
10
+ When Jekyll-git-authors generates authors
11
+ Then There should be 5 authors on the "subdir/page.md"
12
+
13
+ Scenario: Authors are not generated for non-section pages
14
+ Given There is a fixture "page.md"
15
+ And There is 1 commit on the "page.md"
16
+ And There is 1 commit on the "subdir/page.md"
17
+ When Jekyll-git-authors generates authors
18
+ Then There should be 0 authors on the "page.md"
19
+ But There should be 1 author on the "subdir/page.md"
@@ -0,0 +1,55 @@
1
+ Given("There is a fixture named {string} and it is in a subdirectory named {string}") do |file, subdir|
2
+ FileUtils.cp "#{@original_dir}/features/fixtures/#{file}", File.join(@dir, subdir)
3
+ expect(File).to exist(File.join(subdir, file))
4
+ end
5
+
6
+ Given("Git is intialized") do
7
+ GitHelper.init_repo
8
+ end
9
+
10
+ Given("There is a fixture {string}") do |file|
11
+ FileUtils.cp "#{@original_dir}/features/fixtures/page.md", @dir
12
+ expect(File).to exist(file)
13
+ end
14
+
15
+ Given("All commits on {string} have different authors") do |file|
16
+ log = Git.log(file).author_email
17
+
18
+ expect(log).to be_a_kind_of(Hash)
19
+ end
20
+
21
+ Given("There is/are {int} commit(s) on the {string}") do |int, file|
22
+ GitHelper.add_commit int, file
23
+
24
+ log = Git.execute("log --oneline #{file}").split("\n")
25
+ expect(log.size).to eq(int)
26
+ end
27
+
28
+ When("Jekyll-git-authors generates authors") do
29
+ # Jekyll::Site does not load directory properly if
30
+ # defaults are being loaded more than once.
31
+ # Workaround is copying it into variable and override directories.
32
+ site_config = Jekyll::Configuration::DEFAULTS.dup
33
+ site_config['source'] = @dir
34
+ site_config['destination'] = File.join(@dir, '_site')
35
+
36
+ @site = Jekyll::Site.new(site_config)
37
+ authors_generator = Jekyll::AuthorsGenerator.new(@site.config)
38
+ @site.generators = Array(authors_generator)
39
+
40
+ # Make jekyll generate every page found and add them into site.pages variable.
41
+ files = Dir.glob File.join('**', '*.md')
42
+ files.each do |file|
43
+ @page = Jekyll::Page.new(@site, File.expand_path(Dir.pwd), '', file)
44
+ @site.pages << @page
45
+ end
46
+ @site.generate
47
+ end
48
+
49
+ Then("There should be {int} author(s) on the {string}") do |int, file|
50
+ page = @site.pages.find { |p| p.path == file }
51
+ expression = /\[[^\]]+\]\(mailto:\{\{ '[^']*' \| encode_email \}\}\)/
52
+ matched_authors = (page.content.scan(expression)).size
53
+
54
+ expect(matched_authors).to eq(int)
55
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+ require 'jekyll'
5
+ require 'jekyll-git-authors'
6
+ # Using this file as a global hook to set up environment
7
+
8
+ if ENV['CODE_COV']
9
+ require 'simplecov'
10
+ SimpleCov.start
11
+ end
12
+
13
+ Before do
14
+ @original_dir = Dir.pwd
15
+ @dir = Dir.mktmpdir 'jekyll-git-authors'
16
+ @subdir = File.join(@dir, 'subdir')
17
+
18
+ Dir.mkdir @subdir
19
+
20
+ Dir.chdir @dir
21
+ end
22
+
23
+ After do
24
+ Dir.chdir @original_dir
25
+ FileUtils.rm_rf @dir
26
+ end
@@ -0,0 +1,27 @@
1
+ module GitHelper
2
+ # Initialize git environment in current directory.
3
+ def self.init_repo
4
+ Git.execute 'init'
5
+
6
+ change_author('')
7
+ end
8
+
9
+ # Change the author name and email by adding additional_info provided when the function gets called.
10
+ def self.change_author(additional_info)
11
+ Git.execute "config user.email 'you#{additional_info}@example.com'"
12
+ Git.execute "config user.name 'Your Name #{additional_info}'"
13
+ end
14
+
15
+ # Write "Commit #'number'" into the file and then commit the change
16
+ # The authors will have name "Your name 'number'" and email "you'number'@example.com"
17
+ def self.add_commit(number, file)
18
+ number.times do |num|
19
+ open(file, 'a') do |f|
20
+ f << "\nCommit #" + "#{num}"
21
+ end
22
+ change_author num
23
+ Git.execute "add #{file}"
24
+ Git.execute 'commit -m "Commit #' + "#{num}" + '."'
25
+ end
26
+ end
27
+ end
@@ -22,9 +22,8 @@ Gem::Specification.new do |spec|
22
22
  "public gem pushes."
23
23
  end
24
24
 
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
27
  spec.require_paths = ["lib"]
29
28
 
30
29
  spec.add_dependency "jekyll"
@@ -1,3 +1,3 @@
1
1
  module JekyllGitAuthors
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
File without changes
data/test/git_test.rb ADDED
@@ -0,0 +1,128 @@
1
+ require "fileutils"
2
+
3
+ require_relative './test_helper.rb'
4
+ require 'jekyll-git-authors.rb'
5
+
6
+ class TestGit < Minitest::Test
7
+ def setup
8
+ @original_dir = Dir.pwd
9
+ @dir = Dir.mktmpdir 'jekyll-git-authors'
10
+
11
+ @subdir = File.join(@dir, 'subdir')
12
+
13
+ Dir.mkdir @subdir
14
+
15
+ FileUtils.cp './test/fixtures/README.md', @subdir
16
+
17
+ Dir.chdir @dir
18
+
19
+
20
+ Git.execute 'init'
21
+
22
+ Git.execute 'config user.email "you@example.com"'
23
+ Git.execute 'config user.name "Your Name"'
24
+
25
+ Git.execute 'add .'
26
+ Git.execute 'commit -m "Initial commit"'
27
+ end
28
+
29
+ def teardown
30
+ Dir.chdir @original_dir
31
+ FileUtils.rm_rf @dir
32
+ end
33
+
34
+ def test_that_git_executes_basic_commands
35
+ assert_match /^git version /, Git.execute('--version')
36
+ end
37
+
38
+ def test_that_git_aborts_on_invalid_command
39
+ invalid_command = 'patses'
40
+ assert_output('', /^Git command failed: '#{invalid_command}' /) do
41
+ assert_raises(SystemExit) do
42
+ Git.execute invalid_command
43
+ end
44
+ end
45
+ end
46
+
47
+ def test_that_git_aborts_with_custom_message
48
+ invalid_command = 'burger order'
49
+ err_message = "We do not serve burgers"
50
+
51
+ assert_output('', /^Git command failed: '#{invalid_command}' #{err_message}/) do
52
+ assert_raises(SystemExit)do
53
+ Git.execute invalid_command, err_message
54
+ end
55
+ end
56
+ end
57
+
58
+ def test_git_log
59
+ method_output = Git.log File.join(@subdir, 'README.md')
60
+ assert_equal "Your Name;you@example.com", "#{method_output}"
61
+ end
62
+
63
+ def test_latest_author_email_is_used
64
+ output = "Your Name;you@example.com\nYour Name;me@example.com"
65
+ git_log = Git::Log.new output
66
+ assert_equal({"Your Name"=>"you@example.com"}, git_log.author_email)
67
+ end
68
+
69
+ def test_that_it_logs_single_author_once_if_author_has_multiple_commits
70
+ output = "Your Name;you@example.com\nYour Name;you@example.com"
71
+ git_log = Git::Log.new output
72
+ assert_equal({"Your Name"=>"you@example.com"}, git_log.author_email)
73
+ end
74
+
75
+ def test_that_it_logs_multiple_authors
76
+ output = "Your Name;you@example.com\nMy Name;me@example.org"
77
+ git_log = Git::Log.new output
78
+ assert_equal({"Your Name"=>"you@example.com", "My Name"=>"me@example.org"}, git_log.author_email)
79
+ end
80
+
81
+ def test_method_author_email_stops_at_5_authors
82
+ authors = ""
83
+ 6.times do |num|
84
+ authors << "Your Name#{num};you#{num}@example.com\n"
85
+ end
86
+ git_log = Git::Log.new authors
87
+
88
+ assert_equal 5, git_log.author_email.size
89
+ end
90
+
91
+ def test_method_author_email_iterates_through_authors
92
+ authors = ""
93
+ 3.times do
94
+ authors << "Your Name0;you0@example.com\n"
95
+ end
96
+ 3.times do
97
+ authors << "Your Name1;you1@example.com\n"
98
+ end
99
+ 2.upto(8) do |num|
100
+ authors << "Your Name#{num};you#{num}@example.com\n"
101
+ end
102
+
103
+ git_log = Git::Log.new authors
104
+
105
+ assert_includes git_log.author_email, 'Your Name4'
106
+ assert_equal 5, git_log.author_email.size
107
+ end
108
+
109
+ def test_that_git_log_aborts_with_custom_message_when_file_is_not_tracked_in_git
110
+ FileUtils.cp "#{@original_dir}/test/fixtures/README.md", @dir
111
+ file = './README.md'
112
+ err_message = "Git command failed: 'ls-files --error-unmatch ./README.md' File is not added in git: ./README.md"
113
+
114
+ assert_output('', /^#{err_message}/) do
115
+ assert_raises(SystemExit) do
116
+ Git.log(file)
117
+ end
118
+ end
119
+ end
120
+
121
+ def test_log_called_when_there_is_no_git_repository
122
+ FileUtils.rm_rf "#{@dir}/.git"
123
+
124
+ assert_raises(SystemExit) do
125
+ Git.log File.join(@subdir, 'README.md')
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './test_helper'
2
+ require 'jekyll-git-authors'
3
+
4
+ class TestJekyllGitAuthors < Minitest::Test
5
+ def setup
6
+ @original_dir = Dir.pwd
7
+ @dir = Dir.mktmpdir 'jekyll-git-authors'
8
+
9
+ @subdir = File.join(@dir, 'subdir')
10
+
11
+ Dir.mkdir @subdir
12
+
13
+ FileUtils.cp './test/fixtures/README.md', @subdir
14
+
15
+ Dir.chdir @dir
16
+
17
+
18
+ Git.execute 'init'
19
+
20
+ Git.execute 'config user.email "you@example.com"'
21
+ Git.execute 'config user.name "Your Name"'
22
+
23
+ Git.execute 'add .'
24
+ Git.execute 'commit -m "Initial commit"'
25
+ end
26
+
27
+ def teardown
28
+ Dir.chdir @original_dir
29
+ FileUtils.rm_rf @dir
30
+ end
31
+
32
+ def test_that_authors_method_formats_correctly
33
+ expected ="{:center: style=\"text-align: center\"}\nAuthors: [Your Name](mailto:{{ 'you@example.com' | encode_email }})\n{:center}"
34
+ authors_generator = Jekyll::AuthorsGenerator.new
35
+ actual = authors_generator.authors 'subdir/README.md'
36
+ assert_equal expected, actual
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ require_relative './test_helper'
2
+ require 'jekyll-git-authors/markdown'
3
+
4
+ class TestMarkdown < Minitest::Test
5
+ def test_markdown_mailto
6
+ author, email = "Your Name", "you@example.com"
7
+ assert_match "[#{author}](mailto:{{ '#{email}' | encode_email }})", Markdown.mailto(author, email)
8
+ end
9
+
10
+ def test_markdown_center
11
+ text = 'foo'
12
+ assert_match %Q|{:center: style="text-align: center"}\n#{text}\n{:center}|, Markdown.center(text)
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ if ENV['CODE_COV']
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+ end
7
+
8
+ require 'minitest/autorun'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-git-authors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaroslav Prokop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2018-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -136,11 +136,21 @@ files:
136
136
  - LICENSE.txt
137
137
  - README.md
138
138
  - Rakefile
139
+ - features/fixtures/page.md
140
+ - features/render_output.feature
141
+ - features/step_definitions/render_output.rb
142
+ - features/support/env.rb
143
+ - features/support/helper.rb
139
144
  - jekyll-git-authors.gemspec
140
145
  - lib/jekyll-git-authors.rb
141
146
  - lib/jekyll-git-authors/git.rb
142
147
  - lib/jekyll-git-authors/markdown.rb
143
148
  - lib/jekyll-git-authors/version.rb
149
+ - test/fixtures/README.md
150
+ - test/git_test.rb
151
+ - test/jekyll-git-authors_test.rb
152
+ - test/markdown_test.rb
153
+ - test/test_helper.rb
144
154
  homepage: https://gitlab.com/jackorp/jekyll-git-authors
145
155
  licenses:
146
156
  - MIT
@@ -166,4 +176,14 @@ rubygems_version: 2.7.6
166
176
  signing_key:
167
177
  specification_version: 4
168
178
  summary: Jekyll plugin that adds git authors into your page.
169
- test_files: []
179
+ test_files:
180
+ - features/fixtures/page.md
181
+ - features/render_output.feature
182
+ - features/step_definitions/render_output.rb
183
+ - features/support/env.rb
184
+ - features/support/helper.rb
185
+ - test/fixtures/README.md
186
+ - test/git_test.rb
187
+ - test/jekyll-git-authors_test.rb
188
+ - test/markdown_test.rb
189
+ - test/test_helper.rb