jekyll-git-authors 0.1.1 → 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
  SHA256:
3
- metadata.gz: 56f16a9833a6d2c0ea29b3af6e0ede1455154b8d0e8216018c68f058e37d10a4
4
- data.tar.gz: 5e069b91a4fc9179d3b6b7b0f3aee15ab72a23365e2c2a07b340ff6b57fcc2d3
3
+ metadata.gz: ad4da7350ddf894bb087396bbcdd866cc128e03d7678c471f56e6ea08fafc4e2
4
+ data.tar.gz: 3b92eef4c6399de9bc9384331ef53bebf38c2b300dd7b49d564232e68eade1d8
5
5
  SHA512:
6
- metadata.gz: 6db8590b31df33735fb64dcb05679c555f153e9f33017b6a7ae76dc843e923a0f1ab4f46d8dff2d8526ac894da9506abe5aa71f8aee074a1e1e39ed72cd8ff16
7
- data.tar.gz: 8c179ba6c81ab872ab7660a8f7e1c0b063e8c211f115e947a96136af406d6bbd12c73412ea29665eb2c6def510fb1f3f3e0dbddb86c88f84189add4488f1877d
6
+ metadata.gz: 2fc25d3f46dba490466259ce48d19d16fecf30d8abc3edcf4584929d64f088f821418e2788c7d170fcdc8a6d273124fc98aed8d12c4e73d22b2397fab0db22f0
7
+ data.tar.gz: 0e832ecd08ec6d381eebae13bc5c36bd080f1674a6aee10d2e8a21202fdfa3a9bca783c47f12aaf2b74a4918698f11481bd73d2eab402ab67785358cc3f33cd0
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  *.swp
10
10
  *.gem
11
11
  *.bak
12
+ Gemfile.lock
data/.gitlab-ci.yml CHANGED
@@ -1,13 +1,28 @@
1
1
  before_script:
2
- - bundle update listen
3
2
  - bundle install
4
3
 
5
4
  test:2.4:
6
5
  image: ruby:2.4
7
6
  script:
8
- - bundle exec rake
7
+ - rake
9
8
 
10
9
  test:2.5:
11
10
  image: ruby:2.5
12
11
  script:
13
- - bundle exec rake
12
+ - CODE_COV=TRUE rake
13
+ artifacts:
14
+ paths:
15
+ - coverage/
16
+
17
+ pages:
18
+ stage: deploy
19
+ dependencies:
20
+ - test:2.5
21
+ script:
22
+ - mv coverage/ public/
23
+ artifacts:
24
+ paths:
25
+ - public
26
+ expire_in: 30 days
27
+ only:
28
+ - master
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:gitlab) {|repo_name| "https://gitlab.com/#{repo_name}" }
3
+ git_source(:gitlab) { |repo_name| "https://gitlab.com/#{repo_name}" }
4
4
 
5
5
  gemspec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![coverage report](https://gitlab.com/jackorp/jekyll-git-authors/badges/master/coverage.svg)](https://gitlab.com/jackorp/jekyll-git-authors/commits/master) [![pipeline status](https://gitlab.com/jackorp/jekyll-git-authors/badges/master/pipeline.svg)](https://gitlab.com/jackorp/jekyll-git-authors/commits/master)
2
+
1
3
  # Git Authors Generator for Jekyll
2
4
 
3
5
  This generator adds last 5 authors and their obfuscated email adress from git commit history into markdown formatted page.
@@ -24,7 +26,7 @@ $ gem install jekyll-git-authors
24
26
  After the plugin has been installed successfully, add the following lines to your `_config.yml` in order to tell Jekyll to use the plugin:
25
27
 
26
28
  ```
27
- gems:
29
+ plugins:
28
30
  - jekyll-git-authors
29
31
  ```
30
32
  ## Contributing
data/Rakefile CHANGED
@@ -1,8 +1,13 @@
1
1
  require 'rake/testtask'
2
+ require 'cucumber/rake/task'
2
3
 
3
- task :default => :test
4
- Rake::TestTask.new do |t|
4
+ desc "Run tests by default"
5
+ task :default => [:test]
6
+
7
+ Rake::TestTask.new(:test) do |t|
5
8
  t.libs = ["lib"]
6
9
  t.verbose = true
7
10
  t.test_files = FileList['test/*_test.rb']
8
11
  end
12
+
13
+ Cucumber::Rake::Task.new(:test)
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "jekyll-git-authors/version"
@@ -6,7 +5,7 @@ require "jekyll-git-authors/version"
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "jekyll-git-authors"
8
7
  spec.version = JekyllGitAuthors::VERSION
9
- spec.authors = ["jackorp"]
8
+ spec.authors = ["Jaroslav Prokop"]
10
9
  spec.email = ["jar.prokop@volny.cz"]
11
10
 
12
11
  spec.summary = %q{Jekyll plugin that adds git authors into your page.}
@@ -31,7 +30,10 @@ Gem::Specification.new do |spec|
31
30
  spec.add_dependency "jekyll"
32
31
  spec.add_dependency "jekyll-email-protect"
33
32
 
33
+ spec.add_development_dependency "simplecov"
34
34
  spec.add_development_dependency "bundler", "~> 1.16"
35
35
  spec.add_development_dependency "rake", "~> 10.0"
36
36
  spec.add_development_dependency "minitest"
37
+ spec.add_development_dependency "cucumber"
38
+ spec.add_development_dependency "rspec"
37
39
  end
@@ -1,98 +1,11 @@
1
- require_relative './jekyll-git-authors/version.rb'
1
+ require 'jekyll-git-authors/version'
2
+ require 'jekyll-git-authors/markdown'
3
+ require 'jekyll-git-authors/git'
4
+
2
5
  require 'jekyll'
3
6
 
4
7
  # This script gets last 5 authors of a file and writes them at the end of the file.
5
8
 
6
- module Git
7
- # Git::Log parses output passed from Git#log and creates a hash with author as a key and email as value
8
- class Log
9
- # We are expecting output from "git log" command
10
- def initialize(log)
11
- @log = log
12
- end
13
-
14
- # Iterate through each line in the log
15
- # filter out whitespace characters, split the line by semicolon
16
- # assign the returned pair (i.e. author and email) to author and email variables
17
- # then create hash with author as key and email as value and return it.
18
- def author_email
19
- author_email = Hash.new
20
- @log.each_line do |line|
21
- author, mail = line.strip.split(';')
22
-
23
- author_email[author] = mail unless author_email.key?(author)
24
- end
25
- author_email
26
- end
27
-
28
- # To ensure log will be text when we want
29
- def to_s
30
- @log
31
- end
32
- end
33
-
34
- # Git::Submodules parses output from Git#submodules and creates an array of submodules
35
- class Submodules
36
- # Expected input is "git submodule foreach 'echo $path'".
37
- # That command gives us paths relative to current directory.
38
- def initialize(paths)
39
- @paths = paths
40
- end
41
-
42
- # Clean the @path from redundant text that git generates.
43
- # First we take the @paths. We iterate through each line,
44
- # ignore ballast git puts there 'Entering ...'
45
- # and make it a path relative to the current directory
46
- # that git puts there, we then add the absolute path into an array.
47
- def extract_path
48
- submodules = Array.new
49
- @paths.each_line do |line|
50
- unless line =~ /Entering/
51
- line.strip!
52
- line.sub!(/^#{Dir.pwd}\//, '')
53
-
54
- submodules << line
55
- end
56
- end
57
- submodules
58
- end
59
- end
60
-
61
- # Take a git command and execute
62
- # Abort if command didn't execute successfully
63
- # then return output of the command.
64
- def self.execute(command)
65
- output = `git #{command}`
66
-
67
- abort "Unknown git command: '#{command}'" unless $?.success?
68
-
69
- return output
70
- end
71
-
72
- # Create instance of Git::Submodules and execute expected command.
73
- # We receive array of absolute paths of all submodules
74
- def self.submodules
75
- Submodules.new(execute('submodule foreach pwd'))
76
- end
77
-
78
- # Create instance of Git::Log and pass it output from git log command
79
- # return 5 last authors of a particular file
80
- # %an returns author, semicolon for effortless parsing, %ae return email of author
81
- def self.log(file)
82
- Log.new(execute("log -5 --pretty=format:'%an;%ae' #{file}"))
83
- end
84
- end
85
-
86
- module Markdown
87
- def self.mailto(a, e)
88
- "[#{a}](mailto:{{ '#{e}' | encode_email }})"
89
- end
90
-
91
- def self.center(text)
92
- '{:center: style="text-align: center"}' + "\n#{text}\n{:center}"
93
- end
94
- end
95
-
96
9
  module Jekyll
97
10
  class AuthorsGenerator < Generator
98
11
  safe true
@@ -104,46 +17,34 @@ module Jekyll
104
17
  def generate(site)
105
18
  puts "\nGenerating authors"
106
19
 
107
- repositories = Git.submodules.extract_path
108
-
109
- # For each submodule we go into directory of that submodule
110
- # delete the submodule dir from page path
111
- # before executing Git#log, then go back where we were.
20
+ # Find every .md file that is in subdirectory,
21
+ # then go into directory where page is located.
22
+ # Git finds authors for us if we call Git#log in directory
23
+ # where the file is located.
112
24
  site.pages.each do |page|
113
25
  file = page.path
114
- if file =~ /\.md/
115
- repositories.each do |repository|
116
- if file =~ /^#{repository}/
117
- original_dir = Dir.pwd
118
- Dir.chdir repository
119
-
120
- file.sub!(repository, '.')
121
-
122
- author_md = Git.log(file).author_email
123
- author_md = author_md.sort
124
- author_md = author_md.map { |a, e| Markdown.mailto(a, e) }
125
-
126
- output = author_md.join ', '
127
- output = "Authors: #{output}"
128
- output = Markdown.center output
129
-
130
- page.content += output
131
-
132
- Dir.chdir original_dir
133
- else
134
- author_md = Git.log(file).author_email
135
- author_md = author_md.sort
136
- author_md = author_md.map { |a, e| Markdown.mailto(a, e) }
137
-
138
- output = author_md.join ', '
139
- output = "Authors: #{output}"
140
- output = Markdown.center output
141
-
142
- page.content += output
143
- end
26
+ # If file ends with md and if it is subdir.
27
+ # Jekyll does not add "./" into pages paths,
28
+ # so we can use this approach.
29
+ if file =~ /\.md/ and file =~ /\//
30
+ Dir.chdir File.dirname(file) do |path|
31
+ output = authors File.basename(file)
32
+
33
+ page.content += output
144
34
  end
145
35
  end
146
36
  end
147
37
  end
38
+
39
+ # Gets the authors and then adds required formatting.
40
+ def authors(file)
41
+ author_md = Git.log(file).author_email
42
+ author_md = author_md.sort
43
+ author_md = author_md.map { |a, e| Markdown.mailto(a, e) }
44
+
45
+ output = author_md.join ', '
46
+ output = "Authors: #{output}"
47
+ Markdown.center output
48
+ end
148
49
  end
149
50
  end
@@ -0,0 +1,55 @@
1
+ module Git
2
+ # Git::Log parses output passed from Git#log and creates a hash with author as a key and email as value
3
+ class Log
4
+ # We are expecting output from "git log" command
5
+ def initialize(log)
6
+ @log = log
7
+ end
8
+
9
+ # Iterate through each line in the log
10
+ # filter out whitespace characters, split the line by semicolon
11
+ # assign the returned pair (i.e. author and email) to author and email variables
12
+ # then create hash with author as key and email as value and return it.
13
+ # Return from function if we have 5 authors
14
+ def author_email
15
+ author_email = Hash.new
16
+ @log.each_line do |line|
17
+ author, mail = line.strip.split(';')
18
+
19
+ author_email[author] = mail unless author_email.key?(author)
20
+
21
+ return author_email if author_email.size == 5
22
+ end
23
+ author_email
24
+ end
25
+
26
+ # To ensure log will be text when we want
27
+ def to_s
28
+ @log
29
+ end
30
+ end
31
+
32
+ # Take a git command and execute
33
+ # Abort if command didn't execute successfully
34
+ # then return output of the command.
35
+ # Print custom message if required.
36
+ def self.execute(command, msg = '')
37
+ output = `git #{command}`
38
+
39
+ abort "Git command failed: '#{command}'" + " #{msg}" unless $?.success?
40
+
41
+ return output
42
+ end
43
+
44
+ # Check if file is tracked with git.
45
+ # If it is not, exit status 1 will be returned by git.
46
+ # so it will be aborted by execute method.
47
+ #
48
+ # Create instance of Git::Log and pass it output from git log command
49
+ # return 5 last authors of a particular file
50
+ # %an returns author, semicolon for effortless parsing, %ae return email of author
51
+ def self.log(file)
52
+ Git.execute("ls-files --error-unmatch #{file}", "File is not added in git: #{file}")
53
+ Log.new(execute("log --pretty=format:'%an;%ae' #{file}"))
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ module Markdown
2
+ def self.mailto(a, e)
3
+ "[#{a}](mailto:{{ '#{e}' | encode_email }})"
4
+ end
5
+
6
+ def self.center(text)
7
+ '{:center: style="text-align: center"}' + "\n#{text}\n{:center}"
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module JekyllGitAuthors
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - jackorp
7
+ - Jaroslav Prokop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-10 00:00:00.000000000 Z
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
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'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,34 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cucumber
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description: Jekyll plugin that adds git authors and their obfuscated email address
84
126
  into page using markdown and liquid.
85
127
  email:
@@ -91,12 +133,13 @@ files:
91
133
  - ".gitignore"
92
134
  - ".gitlab-ci.yml"
93
135
  - Gemfile
94
- - Gemfile.lock
95
136
  - LICENSE.txt
96
137
  - README.md
97
138
  - Rakefile
98
139
  - jekyll-git-authors.gemspec
99
140
  - lib/jekyll-git-authors.rb
141
+ - lib/jekyll-git-authors/git.rb
142
+ - lib/jekyll-git-authors/markdown.rb
100
143
  - lib/jekyll-git-authors/version.rb
101
144
  homepage: https://gitlab.com/jackorp/jekyll-git-authors
102
145
  licenses:
data/Gemfile.lock DELETED
@@ -1,73 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll-git-authors (0.1.0)
5
- jekyll
6
- jekyll-email-protect
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.5.2)
12
- public_suffix (>= 2.0.2, < 4.0)
13
- colorator (1.1.0)
14
- concurrent-ruby (1.0.5)
15
- em-websocket (0.5.1)
16
- eventmachine (>= 0.12.9)
17
- http_parser.rb (~> 0.6.0)
18
- eventmachine (1.2.7)
19
- ffi (1.9.25)
20
- forwardable-extended (2.6.0)
21
- http_parser.rb (0.6.0)
22
- i18n (0.9.5)
23
- concurrent-ruby (~> 1.0)
24
- jekyll (3.8.3)
25
- addressable (~> 2.4)
26
- colorator (~> 1.0)
27
- em-websocket (~> 0.5)
28
- i18n (~> 0.7)
29
- jekyll-sass-converter (~> 1.0)
30
- jekyll-watch (~> 2.0)
31
- kramdown (~> 1.14)
32
- liquid (~> 4.0)
33
- mercenary (~> 0.3.3)
34
- pathutil (~> 0.9)
35
- rouge (>= 1.7, < 4)
36
- safe_yaml (~> 1.0)
37
- jekyll-email-protect (1.1.0)
38
- jekyll-sass-converter (1.5.2)
39
- sass (~> 3.4)
40
- jekyll-watch (2.0.0)
41
- listen (~> 3.0)
42
- kramdown (1.17.0)
43
- liquid (4.0.0)
44
- listen (3.1.5)
45
- rb-inotify (~> 0.9, >= 0.9.7)
46
- mercenary (0.3.6)
47
- minitest (5.11.3)
48
- pathutil (0.16.1)
49
- forwardable-extended (~> 2.6)
50
- public_suffix (3.0.2)
51
- rake (10.5.0)
52
- rb-fsevent (0.10.3)
53
- rb-inotify (0.9.10)
54
- ffi (>= 0.5.0, < 2)
55
- rouge (3.1.1)
56
- safe_yaml (1.0.4)
57
- sass (3.5.6)
58
- sass-listen (~> 4.0.0)
59
- sass-listen (4.0.0)
60
- rb-fsevent (~> 0.9, >= 0.9.4)
61
- rb-inotify (~> 0.9, >= 0.9.7)
62
-
63
- PLATFORMS
64
- ruby
65
-
66
- DEPENDENCIES
67
- bundler (~> 1.16)
68
- jekyll-git-authors!
69
- minitest
70
- rake (~> 10.0)
71
-
72
- BUNDLED WITH
73
- 1.16.1