commit_message 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +7 -0
- data/commit_message.gemspec +19 -0
- data/lib/commit_message.rb +53 -0
- data/spec/commit_message_spec.rb +51 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f8d784157830df75ac21facc4a7cdee165810d9e
|
4
|
+
data.tar.gz: d10774363005b51f9db174e69f00092837b69084
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1072620e2aa8047b3b699cc2814593be34475e510ce3f6d8281992fe19f4591a7969765a2a15aae6b0e521edd2478a317e736e44c17daa6c345e17208bdb6de8
|
7
|
+
data.tar.gz: 5d3ca5c74e73b0d6ea4c3f1360a9e83a1e43570666c84cde39d3f39eba340e04612678a1d677009d6f1a3d67ad2fff739fe270e7239d38409ee41e60df354b5c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ben Olive
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# CommitMessage
|
2
|
+
|
3
|
+
Convert a commit message into a reasonable description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'commit_message'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install commit_message
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
For the head of a repository in the working directory:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
puts CommitMessage.new
|
25
|
+
```
|
26
|
+
|
27
|
+
For a specific revision:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
puts CommitMessage.new(revision: "master")
|
31
|
+
```
|
32
|
+
|
33
|
+
For a different repo:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
puts CommitMessage.new(repo: "/path/to/repo")
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( http://github.com/sionide21/commit_message/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "commit_message"
|
4
|
+
spec.version = "0.0.1"
|
5
|
+
spec.authors = ["Ben Olive"]
|
6
|
+
spec.email = ["ben.olive@salesloft.com"]
|
7
|
+
spec.summary = "Convert a commit message into a reasonable description"
|
8
|
+
spec.homepage = "https://github.com/sionide21/commit_message"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files -z`.split("\x0")
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
17
|
+
spec.add_development_dependency "rake"
|
18
|
+
spec.add_development_dependency "rspec"
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class CommitMessage
|
2
|
+
attr_accessor :revision, :repo
|
3
|
+
|
4
|
+
def initialize(revision: "HEAD", repo: nil)
|
5
|
+
@revision = revision
|
6
|
+
@repo = repo || Dir.pwd
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
if pull_request
|
11
|
+
"Pull Request ##{pull_request}: #{branch}"
|
12
|
+
elsif branch
|
13
|
+
"#{name}: Merge '#{branch}' into '#{local_branch}'"
|
14
|
+
else
|
15
|
+
"#{name}: #{message}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def name
|
22
|
+
raw_message[/^Author: (.+) (?:<.+>)$/, 1]
|
23
|
+
end
|
24
|
+
|
25
|
+
def pull_request
|
26
|
+
message[/^Merge pull request #(\d+)/, 1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def branch
|
30
|
+
return unless is_merge?
|
31
|
+
message[/from .+\/(.+)$/, 1] or message[/^Merge branch '(.+?)'/, 1]
|
32
|
+
end
|
33
|
+
|
34
|
+
def local_branch
|
35
|
+
message[/into (.+)$/, 1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def message
|
39
|
+
raw_message.lines.last.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
def git_command
|
43
|
+
"git log --pretty=short -1 #{revision}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_merge?
|
47
|
+
raw_message.lines[1].start_with?("Merge: ")
|
48
|
+
end
|
49
|
+
|
50
|
+
def raw_message
|
51
|
+
Dir.chdir(repo) { `#{git_command}` }.strip
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'commit_message'
|
2
|
+
|
3
|
+
describe CommitMessage do
|
4
|
+
let (:commit_message) { CommitMessage.new }
|
5
|
+
|
6
|
+
describe '.new' do
|
7
|
+
it "defaults to HEAD in the CWD" do
|
8
|
+
expect(commit_message.revision).to eq("HEAD")
|
9
|
+
expect(commit_message.repo).to eq(Dir.pwd)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "accepts parameters" do
|
13
|
+
commit_message = CommitMessage.new(revision: "master", repo: "/path/to/repo")
|
14
|
+
expect(commit_message.revision).to eq("master")
|
15
|
+
expect(commit_message.repo).to eq("/path/to/repo")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_s' do
|
20
|
+
it "falls back to the author and message" do
|
21
|
+
commit_message.stub(:raw_message) { "commit 06082f66d541e581110406bbac3bc395bace3f86\nAuthor: Ben Olive <ben.olive@example.com>\n\n Fire ze missiles" }
|
22
|
+
expect(commit_message.to_s).to eq("Ben Olive: Fire ze missiles")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "leaves reverts alone" do
|
26
|
+
commit_message.stub(:raw_message) { "commit 4184d2d2b06eaa81a5a48678956dfd28feb6b118\nAuthor: Ben Olive <ben.olive@example.com>\n\n Revert \"Merge pull request #95 from SalesLoft/super-secret-project\"" }
|
27
|
+
expect(commit_message.to_s).to eq("Ben Olive: Revert \"Merge pull request #95 from SalesLoft/super-secret-project\"")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "renders the pull request" do
|
31
|
+
commit_message.stub(:raw_message) { "commit fc0b98da0b83329474922a920a6070d370091228\nMerge: f54dd28 4d344bb\nAuthor: Ben Olive <ben.olive@example.com>\n\n Merge pull request #314 from SalesLoft/super-secret-project" }
|
32
|
+
expect(commit_message.to_s).to eq("Pull Request #314: super-secret-project")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "renders pulls" do
|
36
|
+
commit_message.stub(:raw_message) { "commit 8ff2e3ac2bf32b3c05584e08ab977306d84bc02d\nMerge: d51e937 50464d8\nAuthor: Ben Olive <ben.olive@example.com>\n\n Merge branch 'pirates' of github.com:SalesLoft/repo into master" }
|
37
|
+
expect(commit_message.to_s).to eq("Ben Olive: Merge 'pirates' into 'master'")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "renders merges" do
|
41
|
+
commit_message.stub(:raw_message) { "commit a8ab66d0bdd40a4612425b0a0fee1417fbfbf940\nMerge: 617b40c 4184d2d\nAuthor: Ben Olive <ben.olive@example.com>\n\n Merge branch 'master' into test" }
|
42
|
+
expect(commit_message.to_s).to eq("Ben Olive: Merge 'master' into 'test'")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#git_command' do
|
47
|
+
it "returns the expected git command" do
|
48
|
+
expect(commit_message.send(:git_command)).to eq("git log --pretty=short -1 HEAD")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commit_message
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Olive
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ben.olive@salesloft.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- commit_message.gemspec
|
68
|
+
- lib/commit_message.rb
|
69
|
+
- spec/commit_message_spec.rb
|
70
|
+
homepage: https://github.com/sionide21/commit_message
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.14
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Convert a commit message into a reasonable description
|
94
|
+
test_files:
|
95
|
+
- spec/commit_message_spec.rb
|