git-redmine-commit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.0.0)
16
+ jeweler (~> 1.5.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Robin Lu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,47 @@
1
+ = git-redmine-commit
2
+
3
+ git commit with redmine issue id.
4
+
5
+ With this tool, you can do a git commit with a redmine issue id. The message of the commit is filled with the title of the issue automatically.
6
+
7
+ == Install
8
+
9
+ gem install git-redmine-commit
10
+
11
+ == Usage
12
+
13
+ git-redmine-commit issue_id [options] -- [git-commit options]
14
+
15
+ Specify the api key and url. You only need to do it once for each repo.
16
+ --redmine-api-key [key] The api access key to access redmine.
17
+ --redmine-url [url] URL of your redmine.
18
+
19
+ -h, --help Displays this help info
20
+
21
+ Example:
22
+ git-redmine-commit 3125 -- -a
23
+
24
+ == Copyright
25
+
26
+ (The MIT License)
27
+
28
+ Copyright (c) 2011 Robin Lu
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ 'Software'), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "git-redmine-commit"
16
+ gem.homepage = "http://github.com/robin/git-redmine-commit"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{git commit with redmine issue id}
19
+ gem.description = %Q{With this tool, you can do a git commit with a redmine issue id. The message of the commit is filled with the title of the issue automatically.}
20
+ gem.email = "iamawalrus@gmail.com"
21
+ gem.authors = ["Robin Lu"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_dependency 'xml-simple', ">= 1.0.12"
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ task :default => :test
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "git-redmine-commit #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'git-redmine-commit'
3
+ GitRedmineCommit.new(ARGV).run
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{git-redmine-commit}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Robin Lu"]
12
+ s.date = %q{2011-03-28}
13
+ s.default_executable = %q{git-redmine-commit}
14
+ s.description = %q{With this tool, you can do a git commit with a redmine issue id. The message of the commit is filled with the title of the issue automatically.}
15
+ s.email = %q{iamawalrus@gmail.com}
16
+ s.executables = ["git-redmine-commit"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/git-redmine-commit",
30
+ "git-redmine-commit.gemspec",
31
+ "lib/git-redmine-commit.rb",
32
+ "test/helper.rb",
33
+ "test/test_git-redmine-commit.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/robin/git-redmine-commit}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{git commit with redmine issue id}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_git-redmine-commit.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
52
+ s.add_runtime_dependency(%q<xml-simple>, [">= 1.0.12"])
53
+ else
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
56
+ s.add_dependency(%q<xml-simple>, [">= 1.0.12"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<xml-simple>, [">= 1.0.12"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,121 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+ require 'yaml'
7
+ require 'open-uri'
8
+ require 'optparse'
9
+ require 'ostruct'
10
+
11
+ require 'rubygems'
12
+ require 'xmlsimple'
13
+
14
+ class GitRedmineCommit
15
+ defaults = {}
16
+ REDMINECOMMIT_RC = File.join("#{ENV['HOME']}",".redmine_commit_rc")
17
+ GRC_CONFIG = if File.exist?(REDMINECOMMIT_RC)
18
+ defaults.merge(YAML.load_file(REDMINECOMMIT_RC))
19
+ else
20
+ defaults
21
+ end
22
+
23
+ def initialize(args)
24
+ @options = {}
25
+
26
+ opts = OptionParser.new do |opts|
27
+ opts.banner = "Usage: #{File.basename($0)} issue_id [options] -- [git-commit options]"
28
+ opts.separator ""
29
+ opts.separator "Specify the api key and url. You only need to do it once for each repo."
30
+
31
+ opts.on( "--redmine-api-key [key]", String,
32
+ "The api access key to access redmine." ) do |opt|
33
+ @options[:key] = opt
34
+ end
35
+ opts.on( "--redmine-url [url]", String,
36
+ "URL of your redmine." ) do |opt|
37
+ @options[:url] = opt
38
+ end
39
+ opts.separator ""
40
+ opts.on("-h", "--help", "Displays this help info") do
41
+ puts opts
42
+ exit 0
43
+ end
44
+
45
+ opts.separator ""
46
+ opts.separator "Example:"
47
+ opts.separator "\t#{File.basename($0)} 3125 -- -a"
48
+ end
49
+
50
+ opts.parse!(args)
51
+
52
+ if args.empty?
53
+ puts "Please specify the redmine issue id"
54
+ puts opts
55
+ exit 1
56
+ end
57
+
58
+ @options[:issue_id] = args.shift.to_i
59
+ @options[:git_options] = args.join(' ')
60
+ @options[:repo] = `git config --get remote.origin.url`.chomp
61
+ @options[:repo] = Dir.pwd if @options[:repo].empty?
62
+ end
63
+
64
+ def set_redmine_config(redmine_url, api_key, repo)
65
+ GRC_CONFIG[redmine_url] ||= {}
66
+ GRC_CONFIG[redmine_url][:key] = api_key
67
+ GRC_CONFIG[redmine_url][:repos] ||= []
68
+ GRC_CONFIG[redmine_url][:repos] << repo
69
+
70
+ File.open( REDMINECOMMIT_RC, 'w' ) do |out|
71
+ YAML.dump( GRC_CONFIG, out )
72
+ end
73
+ end
74
+
75
+ def run
76
+ git_repo = @options[:repo]
77
+ unless @options[:key] && @options[:url]
78
+ config = get_config(git_repo) || get_config(Dir.pwd) || set_config(git_repo)
79
+ @options[:key] ||= config[:key]
80
+ @options[:url] ||= config[:url]
81
+ end
82
+ set_redmine_config(@options[:url], @options[:key], @options[:repo])
83
+
84
+ url = File.join(@options[:url], "issues", "#{@options[:issue_id]}.xml?key=#{@options[:key]}")
85
+ issue = open(url) { |f| XmlSimple.xml_in(f)}
86
+ title = "fix issue ##{issue['id']} : #{issue['subject']}"
87
+ temp = Tempfile.new('redmine_commit')
88
+ temp << title
89
+ temp.close
90
+ puts `git commit #{@options[:git_options]} -F #{temp.path}`
91
+ end
92
+
93
+ def get_config(git_repo)
94
+ redmine_url = GRC_CONFIG.keys.select {|k|
95
+ rslt = false
96
+ GRC_CONFIG[k][:repos].each {|repo|
97
+ rslt = true and break if git_repo == repo
98
+ }
99
+ rslt
100
+ }[0]
101
+
102
+ {:url => redmine_url, :key => GRC_CONFIG[redmine_url][:key]} if redmine_url
103
+ end
104
+
105
+ def set_config(git_repo)
106
+ redmine_url = @options[:url]
107
+ until redmine_url && !redmine_url.empty?
108
+ print "Redmine url: "
109
+ redmine_url = gets.chomp
110
+ end
111
+
112
+ GRC_CONFIG[redmine_url] ||= {}
113
+
114
+ api_key = @options[:key] || GRC_CONFIG[redmine_url][:key]
115
+ until api_key && !api_key.empty?
116
+ print "Redmine api key: "
117
+ api_key = gets.chomp
118
+ end
119
+ {:url => redmine_url, :key => api_key}
120
+ end
121
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'git-redmine-commit'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGitRedmineCommit < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-redmine-commit
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Robin Lu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-28 00:00:00 +08:00
19
+ default_executable: git-redmine-commit
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 23
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :development
34
+ name: bundler
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 7
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 2
48
+ version: 1.5.2
49
+ type: :development
50
+ name: jeweler
51
+ prerelease: false
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 15
60
+ segments:
61
+ - 1
62
+ - 0
63
+ - 12
64
+ version: 1.0.12
65
+ type: :runtime
66
+ name: xml-simple
67
+ prerelease: false
68
+ version_requirements: *id003
69
+ description: With this tool, you can do a git commit with a redmine issue id. The message of the commit is filled with the title of the issue automatically.
70
+ email: iamawalrus@gmail.com
71
+ executables:
72
+ - git-redmine-commit
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.rdoc
84
+ - Rakefile
85
+ - VERSION
86
+ - bin/git-redmine-commit
87
+ - git-redmine-commit.gemspec
88
+ - lib/git-redmine-commit.rb
89
+ - test/helper.rb
90
+ - test/test_git-redmine-commit.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/robin/git-redmine-commit
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: git commit with redmine issue id
125
+ test_files:
126
+ - test/helper.rb
127
+ - test/test_git-redmine-commit.rb