usmu-github-pages 1.0.1 → 1.0.2

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: 9eac8a8597e25ceb9e1edcf6e78245f95f89785a
4
- data.tar.gz: de6e31fe794731809f85c423fee35ca480802286
3
+ metadata.gz: e8de3a318b1cc72d1f2861d3b4fbee68f9f8b7da
4
+ data.tar.gz: 10e7765259b32a2e7b3ce9397bee9a4cd43ad58c
5
5
  SHA512:
6
- metadata.gz: 37fd1c37f5f4c788ac6a07c3d5cbc5372409805e389c8541a98594bb0a4c313e66638a5be965f4e43c845f90e550d56618a712b2ba168dc71e300b33d1627ff1
7
- data.tar.gz: 685c5588abe097d531f9984dc2132f97c814c4e2762ca267b746a454adcec18472cea1a160d3faf7293fb00df6e4298d9a8fc042a88d25e083de2e00a09cc47b
6
+ metadata.gz: 7517767aaed9757dbeeb2b1e4822e62d34d89be78afcbc90fa10cc437231f585e3efad95f07aad56317ca4a0b72e2dbaea33a5fc9810ceb30e7bc3c73f124508
7
+ data.tar.gz: ca383f949175e377aea5b425223daa94755143081e6ce0b52524518e987930dee07ae26d677cc57387d1e60f7ab132c42aa0bafad9240d880bf2d4e36d4e05ba
data/Guardfile CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  guard :rspec, cmd: 'rspec', spec_paths: ['spec'] do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/usmu/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/usmu/github/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch(%r{^spec/support}) { 'spec' }
8
8
  watch('spec/spec_helper.rb') { 'spec' }
9
9
 
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ desc 'Run all test scripts'
16
16
  task :test => [:clean, :spec, :mutant]
17
17
 
18
18
  desc 'Run mutation tests'
19
- task :mutant, [:target] => [:clean] do |t,args|
19
+ task :mutant, [:target] => [:clean] do |_, args|
20
20
  old = ENV.delete('CODECLIMATE_REPO_TOKEN')
21
21
  if `which mutant 2>&1 > /dev/null; echo \$?`.to_i != 0
22
22
  puts 'Mutant isn\'t supported on your platform. Please run these tests on MRI <= 2.1.5.'
@@ -67,7 +67,7 @@ end
67
67
 
68
68
  # (mostly) borrowed from: https://gist.github.com/mcansky/802396
69
69
  desc 'generate changelog with nice clean output'
70
- task :changelog, :since_c, :until_c do |t,args|
70
+ task :changelog, :since_c, :until_c do |_, args|
71
71
  since_c = args[:since_c] || `git tag | egrep '^[0-9]+\\.[0-9]+\\.[0-9]+\$' | sort -Vr | head -n 1`.chomp
72
72
  until_c = args[:until_c]
73
73
  cmd=`git log --pretty="format:%ci::::%an <%ae>::::%s::::%H" #{since_c}..#{until_c}`
@@ -76,16 +76,15 @@ task :changelog, :since_c, :until_c do |t,args|
76
76
  changelog_content = "\#\# #{Usmu::Github::Pages::VERSION}\n\n"
77
77
 
78
78
  cmd.lines.each do |entry|
79
- date, author, subject, hash = entry.chomp.split('::::')
79
+ _date, author, subject, hash = entry.chomp.split('::::')
80
80
  entries[author] = Array.new unless entries[author]
81
- day = date.split(' ').first
82
81
  entries[author] << "#{subject} (#{hash})" unless subject =~ /Merge/
83
82
  end
84
83
 
85
84
  # generate clean output
86
85
  entries.keys.each do |author|
87
86
  changelog_content += author + "\n\n"
88
- entries[author].reverse.each { |entry| changelog_content += "* #{entry}\n" }
87
+ entries[author].reverse_each { |entry| changelog_content += "* #{entry}\n" }
89
88
  end
90
89
 
91
90
  puts changelog_content
@@ -3,141 +3,42 @@
3
3
  uri
4
4
  usmu/github/pages/version
5
5
  usmu/github/pages/configuration
6
+ usmu/github/pages/commands
6
7
  }.each {|f| require f }
7
8
 
8
- module Usmu
9
- module Github
10
- class Pages
11
- def initialize
12
- @log = Logging.logger[self]
13
- @log.debug("Initializing usmu-github-pages v#{VERSION}")
14
- end
15
-
16
- # @see Usmu::Plugin::CoreHooks#commands
17
- def commands(ui, c)
18
- @log.debug('Adding commands from usmu-github-pages.')
19
- @ui = ui
20
-
21
- c.command(:'gh-pages init') do |command|
22
- command.syntax = 'usmu gh-pages init'
23
- command.description = 'Ensures that your repository is compatible and setup correctly for Github Pages.'
24
- command.action &method(:command_init)
25
- end
26
-
27
- c.command(:'gh-pages deploy') do |command|
28
- command.syntax = 'usmu gh-pages deploy'
29
- command.description = 'Generates a site and commits it to Github.'
30
- command.action &method(:command_deploy)
31
- end
32
- end
33
-
34
- def command_init(args, options)
35
- config = Configuration.new(@ui.configuration['plugin', 'github-pages', default: {}])
36
-
37
- # Ensure git (>= 2.5).
38
- git_version = `git version 2>&1`.split(' ').last
39
- if Gem::Version.new(git_version) < Gem::Version.new('2.5.0')
40
- @log.fatal('The Github Pages plugin requires at least git version 2.5.0')
41
- exit 1
42
- end
43
-
44
- # Work out what the correct gh-pages branch is.
45
- remote = config['remote', default: 'origin']
46
- branch = config['branch', default: config.default_branch(remote)]
47
- @log.info("Configuring to deploy to #{remote}/#{branch}.")
48
-
49
- # Ensure destination is gitignored.
50
- destination = @ui.configuration['destination', default: 'site']
51
- gitignore_path = File.expand_path './.gitignore', @ui.configuration.config_dir
52
- gitignore = File.read(gitignore_path).lines.map(&:chomp)
53
- if gitignore.grep(%r{^/?#{File.basename destination}$}).empty?
54
- @log.info("Adding #{destination} to gitignore at #{gitignore_path}")
55
- gitignore.push("#{File.basename destination}")
56
- File.write gitignore_path, gitignore.join("\n") + "\n"
57
- end
58
-
59
- # Ensure the destination directory is configured correctly.
60
- destination = @ui.configuration.destination_path
61
- if File.exist? destination
62
- unless File.file? File.expand_path('./.git', destination)
63
- if File.exist? File.expand_path('./.git', destination)
64
- @log.fatal('Destination directory looks like a git clone not a worktree: ' + destination)
65
- else
66
- @log.fatal('Destination directory exists but doesn\'t look like it is controlled by git: ' + destination)
67
- end
68
- exit 1
69
- end
70
- else
71
- @log.info("Configuring git worktree at: #{destination}")
72
- `git worktree prune 2>&1`
73
- `git worktree add #{Shellwords.escape destination} HEAD 2>&1`
74
- end
75
-
76
- # Check if branch exists locally and remotely.
77
- branches = `git branch -a`.lines.map{|l| l[2..-1]}.map(&:chomp)
78
- local = !branches.select{|b| b == branch }.empty?
79
- remote = !branches.select{|b| b == "remotes/#{remote}/#{branch}" }.empty?
80
- if !local && !remote
81
- Dir.chdir destination do
82
- `git checkout -f --orphan #{Shellwords.escape branch} 2>&1`
83
- `git rm -r . 2>&1`
84
- end
85
- else
86
- Dir.chdir destination do
87
- `git checkout -f #{Shellwords.escape branch} 2>&1`
88
- end
89
- end
90
- end
91
-
92
- def command_deploy(args, options)
93
- @configuration = @ui.configuration
94
- config = Configuration.new(@ui.configuration['plugin', 'github-pages', default: {}])
95
- remote = config['remote', default: 'origin']
96
- branch = config['branch', default: config.default_branch(remote)]
97
- destination = @ui.configuration.destination_path
9
+ class Usmu::Github::Pages
10
+ def initialize
11
+ @log = Logging.logger[self]
12
+ @log.debug("Initializing usmu-github-pages v#{VERSION}")
13
+ end
98
14
 
99
- # Ensure we're deploying a complete commit.
100
- sha = `git rev-parse HEAD`.chomp[0, 7]
101
- unless `git diff HEAD --name-only`.lines.count == 0
102
- @log.fatal("Found unsaved changes in your git repository. Please commit these changes and try again.")
103
- exit 1
104
- end
15
+ # @see Usmu::Plugin::CoreHooks#commands
16
+ def commands(ui, c)
17
+ @log.debug('Adding commands from usmu-github-pages.')
18
+ @ui = ui
105
19
 
106
- # Ensure clean worktree.
107
- @log.info("Cleaning output directory.")
108
- Dir.chdir destination do
109
- `git fetch #{Shellwords.escape remote} 2>&1`
110
- `git reset --hard #{Shellwords.escape remote}/#{Shellwords.escape branch} 2>&1`
111
- end
20
+ c.command(:'gh-pages init') do |command|
21
+ command.syntax = 'usmu gh-pages init'
22
+ command.description = 'Ensures that your repository is compatible and setup correctly for Github Pages.'
23
+ command.action(&method(:command_init))
24
+ end
112
25
 
113
- # Regenerate site.
114
- Usmu.plugins[Usmu::Plugin::Core].command_generate({}, options)
26
+ c.command(:'gh-pages deploy') do |command|
27
+ command.syntax = 'usmu gh-pages deploy'
28
+ command.description = 'Generates a site and commits it to Github.'
29
+ command.action(&method(:command_deploy))
30
+ end
31
+ end
115
32
 
116
- Dir.chdir destination do
117
- # Commit results.
118
- `git add . 2>&1`
119
- if `git diff HEAD --name-only`.lines.count == 0
120
- @log.info "Detected no changes - deploy aborted."
121
- exit 0
122
- end
123
- `git commit -a -m "Update created by usmu-github-pages from revision #{sha}." 2>&1`
124
- if $?.exitstatus != 0
125
- @log.fatal "Unable to create a new commit. Please check the destination folder for more information."
126
- exit 1
127
- end
33
+ def config
34
+ @config ||= Configuration.new(@ui.configuration['plugin', 'github-pages', default: {}])
35
+ end
128
36
 
129
- # Push branch to remote.
130
- @log.info("Deploying to Github...")
131
- `git push #{Shellwords.escape remote} #{Shellwords.escape branch} 2>&1`
132
- end
37
+ def command_init(args, options)
38
+ Usmu::Github::Pages::Commands::Init.new(args, options).run(config)
39
+ end
133
40
 
134
- cname_file = File.expand_path('./CNAME', destination)
135
- if File.exist? cname_file
136
- @log.success("Your site should be available shortly at http://#{File.read(cname_file).chomp}/")
137
- else
138
- @log.success("Deploy completed successfully.")
139
- end
140
- end
141
- end
41
+ def command_deploy(args, options)
42
+ Usmu::Github::Pages::Commands::Deploy.new(args, options).run(config)
142
43
  end
143
44
  end
@@ -0,0 +1,7 @@
1
+ module Usmu::Github::Pages::Commands
2
+ end
3
+
4
+ %w{
5
+ usmu/github/pages/commands/deploy
6
+ usmu/github/pages/commands/init
7
+ }.each {|f| require f }
@@ -0,0 +1,68 @@
1
+
2
+ class Usmu::Github::Pages::Commands::Deploy
3
+ def initialize(*)
4
+ @log = Logging.logger[self]
5
+ end
6
+
7
+ def run(ui, config)
8
+ remote = config['remote', default: 'origin']
9
+ branch = config['branch', default: config.default_branch(remote)]
10
+ destination = ui.configuration.destination_path
11
+
12
+ # Ensure we're deploying a complete commit.
13
+ sha = `git rev-parse HEAD`.chomp[0, 7]
14
+ unless working_dir_clean?
15
+ @log.fatal("Found unsaved changes in your git repository. Please commit these changes and try again.")
16
+ exit 1
17
+ end
18
+
19
+ # Ensure clean worktree.
20
+ @log.info("Cleaning output directory.")
21
+ clean_destination(destination, remote, branch)
22
+
23
+ # Regenerate site.
24
+ Usmu.plugins[Usmu::Plugin::Core].command_generate({}, options)
25
+
26
+ # Commit results.
27
+ create_commit!(destination, "Update created by usmu-github-pages from revision #{sha}.")
28
+
29
+ # Push branch to remote.
30
+ @log.info("Deploying to Github...")
31
+ `git push #{Shellwords.escape remote} #{Shellwords.escape branch} 2>&1`
32
+
33
+ cname_file = File.expand_path('./CNAME', destination)
34
+ if File.exist? cname_file
35
+ @log.success("Your site should be available shortly at http://#{File.read(cname_file).chomp}/")
36
+ else
37
+ @log.success("Deploy completed successfully.")
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def working_dir_clean?
44
+ `git diff HEAD --name-only`.lines.count == 0
45
+ end
46
+
47
+ def clean_destination(destination, remote, branch)
48
+ Dir.chdir destination do
49
+ remote = Shellwords.escape remote
50
+ branch = Shellwords.escape branch
51
+ `(git fetch #{remote} && git reset --hard #{remote}/#{branch}) 2>&1`
52
+ end
53
+ end
54
+
55
+ def create_commit!(destination, message)
56
+ Dir.chdir destination do
57
+ if working_dir_clean?
58
+ @log.info "Detected no changes - deploy aborted."
59
+ exit 0
60
+ end
61
+ `(git add . && git commit -a -m #{Shellwords.escape message}) 2>&1`
62
+ if $?.exitstatus != 0
63
+ @log.fatal "Unable to create a new commit. Please check the destination folder for more information."
64
+ exit 1
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,81 @@
1
+
2
+ class Usmu::Github::Pages::Commands::Init
3
+ def initialize(*)
4
+ @log = Logging.logger[self]
5
+ end
6
+
7
+ def run(ui, config)
8
+ # Ensure git (>= 2.5).
9
+ ensure_git!
10
+
11
+ # Work out what the correct gh-pages branch is.
12
+ remote = config['remote', default: 'origin']
13
+ branch = config['branch', default: config.default_branch(remote)]
14
+ @log.info("Configuring to deploy to #{remote}/#{branch}")
15
+
16
+ # Ensure destination is gitignored.
17
+ destination = ui.configuration['destination', default: 'site']
18
+ gitignore_path = File.expand_path './.gitignore', ui.configuration.config_dir
19
+ gitignore = File.read(gitignore_path).lines.map(&:chomp)
20
+ if gitignore.grep(%r{^/?#{File.basename destination}$}).empty?
21
+ @log.info("Adding #{destination} to gitignore at #{gitignore_path}")
22
+ gitignore.push("#{File.basename destination}")
23
+ File.write gitignore_path, gitignore.join("\n") + "\n"
24
+ end
25
+
26
+ # Ensure the destination directory is configured correctly.
27
+ destination = ui.configuration.destination_path
28
+ ensure_destination! destination
29
+
30
+ # Check if branch exists locally and remotely.
31
+ branches = `git branch -a`.lines.map{|l| l[2..-1]}.map(&:chomp)
32
+ local = !branches.select{|b| b == branch }.empty?
33
+ remote = !branches.select{|b| b == "remotes/#{remote}/#{branch}" }.empty?
34
+ if !local && !remote
35
+ create_destination_branch destination, branch
36
+ else
37
+ checkout_destination_branch destination, branch
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def ensure_git!
44
+ git_version = `git version 2>&1`.split(' ').last
45
+ if Gem::Version.new(git_version) < Gem::Version.new('2.5.0')
46
+ @log.fatal('The Github Pages plugin requires at least git version 2.5.0')
47
+ exit 1
48
+ end
49
+ end
50
+
51
+ def ensure_destination!(destination)
52
+ if File.exist? destination
53
+ unless File.file? File.expand_path('./.git', destination)
54
+ if File.exist? File.expand_path('./.git', destination)
55
+ @log.fatal('Destination directory looks like a git clone not a worktree: ' + destination)
56
+ else
57
+ @log.fatal('Destination directory exists but doesn\'t look like it is controlled by git: ' + destination)
58
+ end
59
+ exit 1
60
+ end
61
+ else
62
+ @log.info("Configuring git worktree at: #{destination}")
63
+ `git worktree prune 2>&1`
64
+ `git worktree add #{Shellwords.escape destination} HEAD 2>&1`
65
+ end
66
+ end
67
+
68
+ def create_destination_branch(destination, branch)
69
+ Dir.chdir destination do
70
+ `git checkout -f --orphan #{Shellwords.escape branch} 2>&1`
71
+ `git rm -r . 2>&1`
72
+ `git clean -fd 2>&1`
73
+ end
74
+ end
75
+
76
+ def checkout_destination_branch(destination, branch)
77
+ Dir.chdir destination do
78
+ `git checkout -f #{Shellwords.escape branch} 2>&1`
79
+ end
80
+ end
81
+ end
@@ -3,7 +3,7 @@ module Usmu
3
3
  module Github
4
4
  class Pages
5
5
  # The current version string for the gem
6
- VERSION = '1.0.1'
6
+ VERSION = '1.0.2'
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,12 @@
1
+ require 'usmu/github/pages/configuration'
2
+ require 'ostruct'
3
+
4
+ RSpec.describe Usmu::Github::Pages::Configuration do
5
+ context '#initialize' do
6
+ it 'indexes the configuration parameter' do
7
+ values = {foo: 'bar'}
8
+ conf = described_class.new(values)
9
+ expect(conf[:foo]).to eq('bar')
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usmu-github-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Scharley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: usmu
@@ -175,8 +175,12 @@ files:
175
175
  - Rakefile
176
176
  - circle.yml
177
177
  - lib/usmu/github/pages.rb
178
+ - lib/usmu/github/pages/commands.rb
179
+ - lib/usmu/github/pages/commands/deploy.rb
180
+ - lib/usmu/github/pages/commands/init.rb
178
181
  - lib/usmu/github/pages/configuration.rb
179
182
  - lib/usmu/github/pages/version.rb
183
+ - spec/pages/configuration_spec.rb
180
184
  - spec/spec_helper.rb
181
185
  - usmu-github-pages.gemspec
182
186
  homepage: https://github.com/usmu/usmu-github-pages
@@ -204,5 +208,6 @@ signing_key:
204
208
  specification_version: 4
205
209
  summary: Github Pages publishing plugin for Usmu.
206
210
  test_files:
211
+ - spec/pages/configuration_spec.rb
207
212
  - spec/spec_helper.rb
208
213
  has_rdoc: