git-blog 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0da108037aabdf36d1106d540a662add7ce9c5b8
4
+ data.tar.gz: bfea49390b39b50ac3606bd9666c481afce92fb9
5
+ SHA512:
6
+ metadata.gz: 760a757078402be5a5fab798853246843280b6e7e1de19d8270c44f1edc6b67c48d02f7d9be384471725f15b43869278115efcbf62c55d2453fa681aebaf9a26
7
+ data.tar.gz: 8877dc258cefe82769e77beab5dd06ddba88010926d4320853d8f8950f92222fd0278e126e05a8d26ff23207c5d649eb96271acb519ab6f7e7e901106b429955
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Void Main
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # git-blog
2
+ Turn git commit message into blog article.
3
+
4
+ ## They say programmers love DRY
5
+ There are tons of books yelling about how you shouldn't repeat yourself, how you should keep it DRY(Don't Repeat Yourself). Well, we tried hard to keep the code clean, but when it comes to blog we wrote, we seems quite ignorante to the DRY principle.
6
+
7
+ During the whole developement process, there will always be some interesting points you want to record, so git gurus told us to write proper git commit messages for further reference or so. And yes, I followed, and I spent quite a time writing about the problem I encountered, how I found the solution, and what should might be useful in the future. That's nice, right?
8
+
9
+ But I've also got a blog to write! Wait, I don't want to REPEAT MYSELF. And that leads to a barely touch [blog site](http://blog.voidmain.me). And I want to change this.
10
+
11
+ ## How this works
12
+ `git-blog` is a simple to use command line tool, which leverage the familiar `git commit` command. Basically, during the commit process, `git-blog` inserts two git hooks, namely `prepare-commit-msg` and `commit-msg`. The `prepare-commit-msg` provides you a self-defined blog template you can use, and the `commit-msg` does the heavy-lifting by turn the commit message into a real blog article. Quite simple and straightforward.
13
+
14
+ ## Spec
15
+ - Basic git hooks for message preparation and commit message interception ★
16
+ - Support local file system (for jekyll) ★
17
+ - Support Github issue reference ★
18
+ - User authentication for Github ★
19
+ - Support wordpress and other blog services (if they provide API) ★★
20
+ - User authentication for the above blog services (if they provide API) ★★
21
+ - Support other code hosting services like Bitbucket or Gitcafe ★★
22
+ - Maybe a website for template sharing or blog service integration ★★★
data/bin/git-blog ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/git-blog/storage'
4
+ require_relative '../lib/git-blog/configuration'
5
+ require_relative '../lib/git-blog/workflow'
6
+
7
+ workflow = GitBlog::Workflow.new
8
+ if ARGV.length == 1 && ARGV[0] == "setup"
9
+ workflow.setup
10
+ else
11
+ workflow.start_blogging ARGV
12
+ end
13
+
14
+ # workflow = GitBlog::Workflow.new
15
+ # workflow.setup
data/git-blog.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require './lib/git-blog/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'git-blog'
5
+ s.version = GitBlog::VERSION
6
+ s.author = 'Peng Sun'
7
+ s.email = 'voidmain1313113@gmail.com'
8
+
9
+ s.summary = 'Turn git commit message into blog article.'
10
+ s.description = "There are tons of books yelling about how you shouldn't repeat yourself, how you should keep it DRY(Don't Repeat Yourself).
11
+ Well, we tried hard to keep the code clean, but when it comes to blog we wrote, we seems quite ignorante to the DRY principle.
12
+ During the whole developement process, there will always be some interesting points you want to record, so git gurus told us to write proper git commit messages for further reference or so.
13
+ And yes, I followed, and I spent quite a time writing about the problem I encountered, how I found the solution, and what should might be useful in the future. That's nice, right?
14
+ But I've also got a blog to write! Wait, I don't want to REPEAT MYSELF. And that leads to a barely touched blog site. And git-blog is here to help."
15
+ s.homepage = 'https://github.com/void-main/git-blog'
16
+ s.license = 'The MIT License (MIT)'
17
+
18
+ s.platform = Gem::Platform::RUBY
19
+ s.require_paths = %w[lib]
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = Dir['spec/**/*.rb']
22
+ s.executables = ['git-blog']
23
+
24
+ s.add_development_dependency 'rake', '~> 0.9.0'
25
+ s.add_development_dependency 'rspec', '~> 2.6.0'
26
+
27
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
28
+ s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'git-blog', '--main', 'README.md']
29
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "./storage"
3
+
4
+ module GitBlog
5
+ class Configuration
6
+ attr_accessor :blog_path
7
+ attr_accessor :template_content
8
+
9
+ def read
10
+ dict = Storage::config_dict
11
+ @blog_path = dict["blog-path"]
12
+ end
13
+
14
+ def write
15
+ dict = { "blog-path" => @blog_path }
16
+ Storage::save_config_dict dict
17
+ end
18
+ end
19
+ end
20
+
21
+ # blog = GitBlog::Configuration.new
22
+ # blog.read
23
+ # puts blog.blog_path
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'date'
3
+ require 'git-blog/configuration'
4
+
5
+ $msg_path = ARGV[0]
6
+ content = File.read($msg_path)
7
+
8
+ conf = GitBlog::Configuration.new
9
+ conf.read
10
+
11
+ # Create a new blog file
12
+ time = DateTime.now.strftime("%F")
13
+ title = [time, "blogging-with-git-blog.markdown"].join("-")
14
+ path = File.join conf.blog_path, title
15
+
16
+ File.open(path, "w") do |file|
17
+ file.write content
18
+ end
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: post
3
+ title: [Your Title Here]
4
+ date: [Current Date and Time]
5
+ categories: [Your category here]
6
+ ---
7
+
8
+ # Fill the content here!
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ require 'json'
3
+ require 'FileUtils'
4
+
5
+ module GitBlog
6
+ class Storage
7
+ BASE_PATH = "~/.git-blog"
8
+
9
+ def self.storage_base_path
10
+ File.expand_path BASE_PATH
11
+ end
12
+
13
+ def self.config_path
14
+ File.join storage_base_path, "config.json"
15
+ end
16
+
17
+ def self.prepare_commit_msg_template_path
18
+ File.join storage_base_path, "prepare-commit-msg"
19
+ end
20
+
21
+ def self.commit_msg_script_path
22
+ File.join storage_base_path, "commit-msg"
23
+ end
24
+
25
+ def self.config_dict
26
+ dict = nil
27
+
28
+ path = Storage::config_path
29
+ if File.exists? path
30
+ dict = JSON.parse(File.read(path))
31
+ end
32
+
33
+ dict
34
+ end
35
+
36
+ def self.save_config_dict dict
37
+ FileUtils.mkdir_p Storage::storage_base_path
38
+ path = Storage::config_path
39
+ File.open(path, "w") { |file| file.write dict.to_json }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module GitBlog
2
+ VERSION = '0.1'
3
+ end
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative './storage'
3
+ require_relative './configuration'
4
+ require 'FileUtils'
5
+
6
+ # Test if a (String) path is a repo
7
+ class String
8
+ def repo?
9
+ ret = false
10
+
11
+ # Use git rev-parse command to test if a directory is a repo
12
+ full_path = File.expand_path self
13
+ if File.directory? full_path
14
+ Dir.chdir full_path do
15
+ system "git rev-parse --show-toplevel > /dev/null 2>&1"
16
+ ret = $?.exitstatus == 0
17
+ end
18
+ end
19
+
20
+ ret
21
+ end
22
+ end
23
+
24
+ module GitBlog
25
+ class Workflow
26
+
27
+ # Setup basic configuration
28
+ def setup
29
+ conf = GitBlog::Configuration.new
30
+ print "Path to blog: "
31
+ $stdin.flush
32
+ conf.blog_path = File.expand_path $stdin.gets.chomp
33
+ conf.write
34
+
35
+ # Also, create the hook files
36
+ current_path = File.expand_path(File.dirname(__FILE__))
37
+ hook_path = File.join current_path, "hooks"
38
+ source_template_path = File.join hook_path, "prepare-commit-msg"
39
+ target_template_path = GitBlog::Storage.prepare_commit_msg_template_path
40
+ if !File.file? target_template_path
41
+ FileUtils.cp source_template_path, target_template_path
42
+ FileUtils.chmod 0755, target_template_path
43
+ end
44
+
45
+ source_commit_script_path = File.join hook_path, "commit-msg"
46
+ target_commit_script_path = GitBlog::Storage.commit_msg_script_path
47
+ if !File.file? target_commit_script_path
48
+ FileUtils.cp source_commit_script_path, target_commit_script_path
49
+ FileUtils.chmod 0755, target_commit_script_path
50
+ end
51
+ end
52
+
53
+ # Test if config is setup
54
+ def need_setup?
55
+ !File.file?(GitBlog::Storage.config_path) ||
56
+ !File.file?(GitBlog::Storage.prepare_commit_msg_template_path) ||
57
+ !File.file?(GitBlog::Storage.commit_msg_script_path)
58
+ end
59
+
60
+ # Do the job
61
+ def start_blogging cli_params
62
+ current_path = Dir.pwd
63
+
64
+ if !current_path.repo?
65
+ puts "Error: please run git-blog inside a git repo."
66
+ return
67
+ end
68
+
69
+ if need_setup?
70
+ puts "Haven't setup git-repo, setting up now"
71
+ setup
72
+ end
73
+
74
+ git_root_path = %x(git rev-parse --show-toplevel).strip
75
+ hooks_path = File.join git_root_path, ".git", "hooks"
76
+ source_template_path = GitBlog::Storage.prepare_commit_msg_template_path
77
+
78
+ script = <<EOF
79
+ #!/usr/bin/env ruby
80
+
81
+ $commit_file_path = ARGV[0]
82
+
83
+ content = <<EOC
84
+ #{File.read(source_template_path)}
85
+ EOC
86
+
87
+ File.write($commit_file_path, content)
88
+ EOF
89
+
90
+ target_template_path = File.join hooks_path, "prepare-commit-msg"
91
+ File.open(target_template_path, "w") { |file| file.write script }
92
+ FileUtils.chmod 0755, target_template_path
93
+
94
+ source_commit_script_path = GitBlog::Storage.commit_msg_script_path
95
+ target_commit_script_path = File.join hooks_path, "commit-msg"
96
+ FileUtils.cp source_commit_script_path, target_commit_script_path
97
+ FileUtils.chmod 0755, target_commit_script_path
98
+
99
+ # Pass to git commit
100
+ system("git commit #{cli_params.join(" ")}")
101
+
102
+ # Clean up
103
+ FileUtils.rm target_template_path
104
+ FileUtils.rm target_commit_script_path
105
+ end
106
+ end
107
+ end
108
+
109
+
110
+ # Test it!
111
+ # puts ".".repo?
112
+ # puts "~".repo?
113
+ # puts "/DoesNotExists".repo?
114
+ # puts "~/Workspace/Projects/OctoEvent".repo?
115
+ #
116
+ # workflow = GitBlog::Workflow.new
117
+ # workflow.setup
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-blog
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Peng Sun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.6.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.6.0
41
+ description: "There are tons of books yelling about how you shouldn't repeat yourself,
42
+ how you should keep it DRY(Don't Repeat Yourself). \nWell, we tried hard to keep
43
+ the code clean, but when it comes to blog we wrote, we seems quite ignorante to
44
+ the DRY principle. \nDuring the whole developement process, there will always be
45
+ some interesting points you want to record, so git gurus told us to write proper
46
+ git commit messages for further reference or so. \nAnd yes, I followed, and I spent
47
+ quite a time writing about the problem I encountered, how I found the solution,
48
+ and what should might be useful in the future. That's nice, right?\nBut I've also
49
+ got a blog to write! Wait, I don't want to REPEAT MYSELF. And that leads to a barely
50
+ touched blog site. And git-blog is here to help."
51
+ email: voidmain1313113@gmail.com
52
+ executables:
53
+ - git-blog
54
+ extensions: []
55
+ extra_rdoc_files:
56
+ - README.md
57
+ - LICENSE
58
+ files:
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.md
62
+ - bin/git-blog
63
+ - git-blog.gemspec
64
+ - lib/git-blog/configuration.rb
65
+ - lib/git-blog/hooks/commit-msg
66
+ - lib/git-blog/hooks/prepare-commit-msg
67
+ - lib/git-blog/storage.rb
68
+ - lib/git-blog/version.rb
69
+ - lib/git-blog/workflow.rb
70
+ homepage: https://github.com/void-main/git-blog
71
+ licenses:
72
+ - The MIT License (MIT)
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --line-numbers
77
+ - --inline-source
78
+ - --title
79
+ - git-blog
80
+ - --main
81
+ - README.md
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Turn git commit message into blog article.
100
+ test_files: []