redk-capn_panda 0.1.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: 3b7fa0856f5bf628a14f8f212948fdb79d76f150
4
+ data.tar.gz: 72e9c2ae409d83438c1e80b2868c8a9980e33b45
5
+ SHA512:
6
+ metadata.gz: 62ed1b55d25c6d14ad414dc49220def29d34c07ff588da49806cac0dd4d54655bc2d9ef6315deafe27098ece0fce769d45718c46de7c0b9b72d782f36c7bc90d
7
+ data.tar.gz: 7706ca98e34450c912fa46f12a573c95df3ed25a0c1daccbc3c9ad2e2cd4b10d7e33c69f28917fdba58a8f208639a871b12a7664e3d03b9ac5a9a1ec1e921ddb
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ gh-pages
11
+ docs.captain-panda
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redk-capn_panda.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 defektive
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # Redk::CapnPanda
2
+
3
+ Captain Panda wants you to be more efficient.
4
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/redk/capn_panda`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'redk-capn_panda'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install redk-capn_panda
23
+
24
+ ## Usage
25
+
26
+
27
+ ```bash
28
+ Redk::CapnPanda commands:
29
+ capn_panda add # Add an issue to jira
30
+ capn_panda config # view/modify configuration
31
+ capn_panda help [COMMAND] # Describe available commands or one specific command
32
+ capn_panda list # list open issues assigned to you
33
+ capn_panda prepare_commit_msg # git hook to prepapre commit messages :D
34
+ capn_panda prune # delete issue branches that no longer have open issues
35
+ capn_panda setup # used to install git hook
36
+ capn_panda start # Start/Switch to a jira issue
37
+ capn_panda version # print version info
38
+
39
+
40
+ ```
41
+
42
+ ## capn_panda add
43
+ ```bash
44
+ Usage:
45
+ capn_panda add
46
+
47
+ Options:
48
+ -a, [--auto-assign], [--no-auto-assign] # auto assign yourself
49
+ # Default: true
50
+
51
+ Add an issue to jira
52
+
53
+ ```
54
+
55
+ ## capn_panda config
56
+ ```bash
57
+ Usage:
58
+ capn_panda config
59
+
60
+ Options:
61
+ -w, [--write], [--no-write] # Write config
62
+ -n, [--nuke], [--no-nuke] # Nuke config
63
+
64
+ view/modify configuration
65
+
66
+ ```
67
+
68
+ ## capn_panda list
69
+ ```bash
70
+ Usage:
71
+ capn_panda list
72
+
73
+ Options:
74
+ -r, [--raw], [--no-raw] # Raw json
75
+
76
+ list open issues assigned to you
77
+
78
+ ```
79
+
80
+ ## capn_panda prepare
81
+ ```bash
82
+ Usage:
83
+ capn_panda prepare_commit_msg
84
+
85
+ git hook to prepapre commit messages :D
86
+
87
+ ```
88
+
89
+ ## capn_panda prune
90
+ ```bash
91
+ Usage:
92
+ capn_panda prune
93
+
94
+ delete issue branches that no longer have open issues
95
+
96
+ ```
97
+
98
+ ## capn_panda setup
99
+ ```bash
100
+ Usage:
101
+ capn_panda setup
102
+
103
+ used to install git hook
104
+
105
+ ```
106
+
107
+ ## capn_panda start
108
+ ```bash
109
+ Usage:
110
+ capn_panda start
111
+
112
+ Start/Switch to a jira issue
113
+
114
+ ```
115
+
116
+ ## capn_panda version
117
+ ```bash
118
+ Usage:
119
+ capn_panda version
120
+
121
+ print version info
122
+
123
+ ```
124
+
125
+
126
+ ## Development
127
+
128
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec redk-capn_panda` to use the code located in this directory, ignoring other installed copies of this gem.
129
+
130
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it ( https://github.com/redk/redk-capn_panda/fork )
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
137
+ 4. Push to the branch (`git push origin my-new-feature`)
138
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'erb'
3
+
4
+ task :readme do
5
+ puts 'building README.md from doc/README.md.erb'
6
+ File.open("README.md", "w+") do |f|
7
+ f.write(ERB.new(File.read('lib/doc/README.md.erb')).result())
8
+ end
9
+ end
10
+
11
+ task :build => :readme
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "redk/capn_panda"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/capn_panda ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "redk/capn_panda"
4
+
5
+ Redk::CapnPanda::CLI.start(ARGV)
@@ -0,0 +1,52 @@
1
+ # Redk::CapnPanda
2
+
3
+ Captain Panda wants you to be more efficient.
4
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/redk/capn_panda`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'redk-capn_panda'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install redk-capn_panda
23
+
24
+ ## Usage
25
+ <%
26
+ basic_usage = `bundle exec exe/capn_panda`
27
+ commands = basic_usage.scan(/capn_panda ([a-z]+)/).flatten.reject {|sd| sd == "help"}
28
+ %>
29
+
30
+ ```bash
31
+ <%= basic_usage %>
32
+ ```
33
+ <% commands.each do |command| %>
34
+ <%= "## capn_panda #{command}" %>
35
+ <%= "```bash" %>
36
+ <%= `bundle exec exe/capn_panda help #{command}` %>
37
+ <%= "```" %>
38
+ <% end %>
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec redk-capn_panda` to use the code located in this directory, ignoring other installed copies of this gem.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/redk/redk-capn_panda/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
@@ -0,0 +1,54 @@
1
+ require "redk/capn_panda/version"
2
+ require 'colorize'
3
+ require 'git'
4
+ require 'gerry'
5
+ require 'jira'
6
+ require 'keychain'
7
+ require 'thor'
8
+ require 'word_wrap'
9
+
10
+
11
+ require "redk/capn_panda/config"
12
+ require "redk/capn_panda/cli"
13
+ require "redk/capn_panda/gerrit"
14
+ require "redk/capn_panda/jira_client"
15
+
16
+ module Redk
17
+ module CapnPanda
18
+ class KeyChainError < StandardError
19
+ end
20
+
21
+ def self.config
22
+ @config ||= Config.load
23
+ end
24
+
25
+ def self.git
26
+ @git ||= Git.open(Dir.pwd)
27
+ end
28
+
29
+ def self.gerrit
30
+ @gerrit ||= Gerrit.from_keychain
31
+ end
32
+
33
+ def self.jira
34
+ @jira ||= JiraClient.from_keychain
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ Git::Branches.class_eval do
41
+ def local
42
+ @local ||= self.select { |b| !b.remote }
43
+ end
44
+ end
45
+
46
+
47
+ module Git::Base::Factory
48
+
49
+ # returns a Git::Branches object of all the Git::Branch
50
+ # objects for this repo
51
+ def branches
52
+ @branches ||= Git::Branches.new(self)
53
+ end
54
+ end
@@ -0,0 +1,263 @@
1
+ module Redk::CapnPanda
2
+
3
+ class CLI < Thor
4
+ package_name "Redk::CapnPanda"
5
+
6
+ map ["cfg", "c"] => "config"
7
+ desc "config", "view/modify configuration"
8
+ method_option :write, :aliases => "-w", :desc => "Write config", :type => :boolean, :default => false
9
+ method_option :nuke, :aliases => "-n", :desc => "Nuke config", :type => :boolean, :default => false
10
+ def config(key=nil, value=nil)
11
+ if options[:nuke]
12
+ Redk::CapnPanda::Config.nuke
13
+ end
14
+
15
+ config = Redk::CapnPanda::Config.load
16
+ if options[:write]
17
+ config.set(key, value)
18
+ config.write
19
+ end
20
+
21
+ puts config.to_hash
22
+ end
23
+
24
+ map ["a"] => "add"
25
+ method_option :auto_assign, :aliases => "-a", :desc => "auto assign yourself", :type => :boolean, :default => true
26
+ desc "add", "Add an issue to jira"
27
+ def add(*args)
28
+ issue = Redk::CapnPanda.jira.Issue.build
29
+
30
+ issue_fields = Redk::CapnPanda.config.jira_new_issue_fields.merge({
31
+ "summary"=> args.join(" "),
32
+ "project"=>{
33
+ "key" => Redk::CapnPanda.config.jira_default_project_key
34
+ },
35
+ "issuetype"=>{
36
+ "name" => Redk::CapnPanda.config.jira_default_issuetype_name
37
+ }
38
+ })
39
+ issue_fields["assignee"] = {"name" => Redk::CapnPanda.config.jira_username} if options[:auto_assign]
40
+ issue.save({
41
+ "fields" => issue_fields
42
+ })
43
+ issue.fetch
44
+
45
+ rescue Redk::CapnPanda::KeyChainError
46
+ puts "#{Redk::CapnPanda.config.jira_domain} doesnt exist in your keychain".colorize(:red)
47
+ rescue Interrupt
48
+ puts "\nInterrupt detected... terminating.".colorize(:yellow)
49
+ end
50
+
51
+ map ["switch", "s"] => "start"
52
+ desc "start", "Start/Switch to a jira issue"
53
+ def start(ticket_match=nil)
54
+ return Redk::CapnPanda.git.branch("master").checkout if ticket_match == "-"
55
+ issue = Redk::CapnPanda.jira.my_issues.find {|d| d.key.include?(ticket_match)} if ticket_match
56
+
57
+ unless issue
58
+ list
59
+ ticket_item = ask ("Select a ticket") { |q| q.echo = true }
60
+ ticket_index = ticket_item.to_i - 1
61
+ issue = Redk::CapnPanda.jira.my_issues[ticket_index]
62
+ end
63
+
64
+ issue.checkout
65
+
66
+ if issue.status.statusCategory['name'] != "In Progress"
67
+ if yes?("Would you like to move this issue to 'In Progress'? ")
68
+ issue.move_to_in_progress
69
+ end
70
+ end
71
+
72
+ rescue Redk::CapnPanda::KeyChainError
73
+ puts "#{Redk::CapnPanda.config.jira_domain} doesnt exist in your keychain".colorize(:red)
74
+ rescue Interrupt
75
+ puts "\nInterrupt detected... terminating.".colorize(:yellow)
76
+ end
77
+
78
+ map ['l', 'ls'] => 'list'
79
+ method_option :raw, :aliases => "-r", :desc => "Raw json", :type => :boolean, :default => false
80
+ desc "list", "list open issues assigned to you"
81
+ def list
82
+ issues_by_status = {}
83
+ return puts Redk::CapnPanda.jira.my_issues.each {|d| puts d.to_json} if options[:raw]
84
+ my_changes = Redk::CapnPanda.gerrit.my_changes
85
+
86
+ Redk::CapnPanda.jira.my_issues.each_with_index do |issue, index|
87
+ status = issue.status.statusCategory['name']
88
+ issues_by_status[status] ||= []
89
+ issues_by_status[status].push my_issues_index: index, issue: issue
90
+ end
91
+
92
+ status_colors = {
93
+ :unknown => [:white, :light_white],
94
+ "To Do" => [:yellow, :light_yellow],
95
+ "In Progress" => [:blue, :light_blue]
96
+ }
97
+
98
+ issues_by_status.each do |status, issues|
99
+ colors = status_colors[status] || status_colors[:unknown]
100
+ puts "\n #{status}".colorize(colors[0]).bold
101
+ issues.each_with_index do |issue, local_index|
102
+ my_issues_index = issue[:my_issues_index] + 1
103
+ issue = issue[:issue]
104
+ color = colors[local_index % 2]
105
+
106
+ change_field = issue.send(Redk::CapnPanda.config.jira_gerrit_field)
107
+ change_id = change_field && change_field.split("\n")[0].chomp
108
+ gerrit = my_changes.select {|ch| ch["change_id"] == change_id}.map do |change|
109
+
110
+ status = change['labels'].sort.map do |key, label|
111
+ m1 = label["rejected"] && !label["rejected"]["blocking"]
112
+ m2 = label["rejected"] && label["rejected"]["blocking"]
113
+ p1 = label["approved"]
114
+
115
+ res = if m2
116
+ "-2"
117
+ elsif p1
118
+ "+2"
119
+ elsif m1
120
+ "-1"
121
+ else
122
+ "--"
123
+ end
124
+
125
+ {
126
+ key => res
127
+ }
128
+ end.reduce({}, :merge)
129
+
130
+ res = [status.values.join("\t"),"<https://#{Redk::CapnPanda.config.gerrit_domain}/#/c/#{change['_number']}/>"]
131
+ res << "<https://#{Redk::CapnPanda.config.firework_domain}/runs/gerrit/#{change['_number']}/>" if Redk::CapnPanda.config.firework_domain
132
+ res.join("\t")
133
+ end.join("\n")
134
+
135
+ code_status = issue.has_branch? ? "⟁ " : ""
136
+
137
+ key = "#{issue.key}".colorize(color).underline
138
+ res = [%Q{ #{my_issues_index} #{code_status}#{key} #{issue.summary}}, %Q{ <https://#{Redk::CapnPanda.config.jira_domain}/browse/#{issue.key}>}]
139
+ res << "\tCR\tNA\tPR\tQA\tV \n\t" + gerrit if gerrit != ""
140
+ puts "#{res.join("\n")}\n".colorize(color)
141
+ end
142
+ end
143
+ rescue Redk::CapnPanda::KeyChainError
144
+ puts "#{Redk::CapnPanda.config.jira_domain} doesnt exist in your keychain".colorize(:red)
145
+ end
146
+
147
+ desc 'prune', 'delete issue branches that no longer have open issues'
148
+ def prune
149
+ issue_keys = Redk::CapnPanda.jira.my_issues.map do |issue|
150
+ issue.key
151
+ end
152
+
153
+ issue_branches = Redk::CapnPanda.git.branches.local.map do |branch|
154
+ branch_name = nil
155
+ parsed_branch = branch.name.match(/(?<type>[^\/]+)\/?(?<ticket>[A-Z]+-[0-9]+)/)
156
+ if parsed_branch
157
+ ticket_number = parsed_branch[:ticket]
158
+ branch_name = branch.name unless issue_keys.include? ticket_number
159
+ end
160
+ branch_name
161
+ end.compact
162
+
163
+ issue_branches.each do |branch|
164
+ puts branch
165
+ end
166
+
167
+ if issue_branches.empty?
168
+ puts "Nothing to prune".colorize(:yellow)
169
+ elsif yes?("Continue? The above branches will be removed")
170
+ Redk::CapnPanda.git.branch('master').checkout
171
+ issue_branches.each do |branch|
172
+ puts branch
173
+ Redk::CapnPanda.git.branch(branch).delete
174
+ end
175
+ end
176
+ rescue Redk::CapnPanda::KeyChainError
177
+ puts "#{Redk::CapnPanda.config.jira_domain} doesnt exist in your keychain".colorize(:red)
178
+ rescue Interrupt
179
+ puts "\nInterrupt detected... terminating.".colorize(:yellow)
180
+ end
181
+
182
+ desc "prepare_commit_msg", "git hook to prepapre commit messages :D"
183
+ def prepare_commit_msg(message_file)
184
+ # we dont want to modify messages that have already been generated
185
+ return if has_change_id message_file
186
+ return unless parsed_branch
187
+ write_commit_message message_file
188
+ end
189
+
190
+ desc "setup", "used to install git hook"
191
+ def setup()
192
+ hook_file = '.git/hooks/prepare-commit-msg'
193
+ if File.exist?(hook_file)
194
+ puts "It looks like you already have a 'prepare-commit-msg' git hook."
195
+ puts "You'll have to manually invoke capn_panda from your existing hook"
196
+ puts "\t'capn_panda prepare_commit_msg $1'"
197
+ else
198
+ File.open(hook_file, 'w') do |file|
199
+ file << '#!/bin/bash'
200
+ file << 'capn_panda prepare_commit_msg $1'
201
+ end
202
+ end
203
+ end
204
+
205
+ desc "version", "print version info"
206
+ def version()
207
+ puts Redk::CapnPanda::VERSION
208
+ end
209
+
210
+ no_commands do
211
+ def has_change_id(message_file)
212
+ File.read(message_file).match('Change-Id: I')
213
+ end
214
+
215
+ def write_commit_message(message_file)
216
+ original_file_contents = File.read(message_file)
217
+ temp_message_file = "#{(message_file)}.tmp"
218
+ File.open(temp_message_file, 'w') do |file|
219
+ file << message_template.join("\n")
220
+ file << "\n"
221
+ file << original_file_contents
222
+ end
223
+
224
+ File.rename(temp_message_file, message_file)
225
+ end
226
+
227
+ def git_branch
228
+ @git_branch ||= `git rev-parse --abbrev-ref HEAD`
229
+ end
230
+
231
+ def parsed_branch
232
+ @parsed_branch ||= git_branch.match(/(?<type>[^\/]+)\/?(?<ticket>[A-Z]+-[0-9]+)/)
233
+ end
234
+
235
+ def commit_type
236
+ @commit_type ||= parsed_branch[:type]
237
+ end
238
+
239
+ def ticket_number
240
+ @ticket_number ||= parsed_branch[:ticket]
241
+ end
242
+
243
+ def message_template
244
+ @message_template ||= (
245
+ issue = Redk::CapnPanda.jira.Issue.find(ticket_number)
246
+ message_template = []
247
+
248
+ message_template << issue.summary if commit_type == 'issue'
249
+ message_template << ''
250
+ message_template << WordWrap.ww(issue.description || '', 72)
251
+ message_template << ''
252
+ message_template << "Fixes #{ticket_number}"
253
+ message_template << "# <https://instructure.atlassian.net/browse/#{ticket_number}>"
254
+ message_template << ''
255
+ message_template << 'Test Plan:'
256
+ message_template << WordWrap.ww(issue.customfield_10500, 72) if issue.customfield_10500
257
+ message_template << 'You do have a test plan, right?'
258
+ message_template
259
+ )
260
+ end
261
+ end
262
+ end
263
+ end
@@ -0,0 +1,70 @@
1
+ require 'yaml'
2
+
3
+ module Redk::CapnPanda
4
+ class Config
5
+
6
+ def self.config_file
7
+ ENV['CAPN_PANDA_CONFIG'] || ENV['HOME'] + "/.config/capn_panda.yaml"
8
+ end
9
+
10
+ def self.load
11
+ unless File.exist?(Config.config_file)
12
+ self.save(Config.config_file, Config.default_config)
13
+ end
14
+
15
+ self.new(Config.config_file)
16
+ end
17
+
18
+ def self.nuke
19
+ File.delete(Config.config_file) if File.exist?(Config.config_file)
20
+ end
21
+
22
+ def self.save(config_file, config)
23
+ File.open(Config.config_file, 'w+') {|f| f.write(config.to_yaml) }
24
+ end
25
+
26
+ def self.default_config
27
+ {
28
+ jira_domain: "jira.atlassian.com",
29
+ jira_username: "jsmith",
30
+ jira_default_project_key: "PROJ",
31
+ jira_default_issuetype_name: "Task",
32
+ jira_gerrit_field: "customfield_10403",
33
+ jira_new_issue_fields: {
34
+ # customfield_12700: {
35
+ # value: "platform"
36
+ # }
37
+ },
38
+
39
+ gerrit_domain: "gerrit.changeme.com",
40
+ firework_domain: false
41
+ }
42
+ end
43
+
44
+ def initialize(config_file)
45
+ @default_config = Config.default_config
46
+ @config = @default_config.merge(::YAML::load(File.open(config_file)))
47
+ end
48
+
49
+ def write
50
+ Config.save(Config.config_file, @config)
51
+ end
52
+
53
+ def set(key, value)
54
+ @config[key.to_sym] = value
55
+ end
56
+
57
+ def to_ary
58
+ return @config.values
59
+ end
60
+
61
+ def to_hash
62
+ return @config
63
+ end
64
+
65
+ def method_missing(m, *args, &block)
66
+ return @config[m.to_sym] if @config.has_key?(m.to_sym)
67
+ raise "no such config property: #{m}"
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,27 @@
1
+ module Redk::CapnPanda
2
+
3
+ class Gerrit < Gerry::Client
4
+
5
+ def self.gerrit_domain
6
+ Redk::CapnPanda.config.gerrit_domain
7
+ end
8
+
9
+ def self.from_keychain
10
+ @keychain_client ||= (
11
+ keychain_item = Keychain.default.internet_passwords.where(server: self.gerrit_domain).first
12
+ raise Redk::CapnPanda::KeyChainError, "#{self.gerrit_domain} is in your keychain" unless keychain_item
13
+ self.from_keychain_item(keychain_item) if keychain_item
14
+ )
15
+ end
16
+
17
+ def self.from_keychain_item(keychain_item)
18
+ self.new("https://#{self.gerrit_domain}", keychain_item.account, keychain_item.password)
19
+ end
20
+
21
+
22
+ def my_changes
23
+ @my_changes ||= self.changes(['q=is:open+owner:self', 'o=LABELS'])
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,62 @@
1
+ module Redk::CapnPanda
2
+ class JiraClient < JIRA::Client
3
+
4
+ def self.jira_domain
5
+ Redk::CapnPanda.config.jira_domain
6
+ end
7
+
8
+ def inspect
9
+ "<Redk::CapnPanda::Jira::Client site: #{options[:site]}>"
10
+ end
11
+
12
+ def my_issues
13
+ @my_issues ||= (
14
+ my_issues_jql = "assignee = currentUser() AND resolution = Unresolved ORDER BY updatedDate DESC"
15
+ issues = JIRA::Resource::Issue.jql(self, my_issues_jql)
16
+ issues
17
+ )
18
+ end
19
+
20
+ def self.from_keychain
21
+ @keychain_client ||= (
22
+ keychain_item = Keychain.default.internet_passwords.where(server: self.jira_domain).first
23
+ raise Redk::CapnPanda::KeyChainError, "#{self.jira_domain} is in your keychain" unless keychain_item
24
+ self.from_keychain_item(keychain_item) if keychain_item
25
+ )
26
+ end
27
+
28
+ def self.from_keychain_item(keychain_item)
29
+ options = {
30
+ :username => keychain_item.account,
31
+ :password => keychain_item.password,
32
+ :site => "https://#{self.jira_domain}",
33
+ :context_path => '',
34
+ :auth_type => :basic
35
+ }
36
+ self.new(options)
37
+ end
38
+ end
39
+ end
40
+
41
+ JIRA::Resource::Issue.class_eval do
42
+
43
+ def has_branch?
44
+ @has_branch ||= branch != nil
45
+ end
46
+
47
+ def branch
48
+ @branch ||= Redk::CapnPanda.git.branches.local.select do |git_branch|
49
+ git_branch.name[/#{self.key}$/]
50
+ end.first
51
+ end
52
+
53
+ def checkout(type='issue')
54
+ Redk::CapnPanda.git.branch("#{type}/#{self.key}").checkout
55
+ end
56
+
57
+ def move_to_in_progress
58
+ transition = self.transitions.build
59
+ id = transitions.all.first {|e| puts e.name == "To In Progress" }.id
60
+ transition.save!("transition" => {"id" => id})
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ module Redk
2
+ module CapnPanda
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redk/capn_panda/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redk-capn_panda"
8
+ spec.version = Redk::CapnPanda::VERSION
9
+ spec.authors = ["defektive"]
10
+ spec.email = ["sirbradleyd@gmail.com"]
11
+
12
+ spec.summary = %q{Cap'n Panda - The powers of git, jira, gerrit, jenkins combined.}
13
+ spec.description = %q{Let the Cap'n hop skiip and jump, so you dont have to.}
14
+ spec.homepage = "http://xredk.github.io/capn-panda"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "git", "~> 1.2"
23
+ spec.add_runtime_dependency "gerry", "~> 0.0.3"
24
+ spec.add_runtime_dependency "jira-ruby", "~> 0.1"
25
+ spec.add_runtime_dependency "ruby-keychain", "~> 0.2"
26
+ spec.add_runtime_dependency "thor", "~> 0.19"
27
+ spec.add_runtime_dependency "word_wrap", "~> 1.0"
28
+ spec.add_runtime_dependency "colorize", "~> 0.7"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "pry", "~> 0.10"
33
+ spec.add_development_dependency "pry-remote", "~> 0.0"
34
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redk-capn_panda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - defektive
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gerry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: jira-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-keychain
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.19'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.19'
83
+ - !ruby/object:Gem::Dependency
84
+ name: word_wrap
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.10'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-remote
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.0'
167
+ description: Let the Cap'n hop skiip and jump, so you dont have to.
168
+ email:
169
+ - sirbradleyd@gmail.com
170
+ executables:
171
+ - capn_panda
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".travis.yml"
178
+ - Gemfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/setup
184
+ - exe/capn_panda
185
+ - lib/doc/README.md.erb
186
+ - lib/redk/capn_panda.rb
187
+ - lib/redk/capn_panda/cli.rb
188
+ - lib/redk/capn_panda/config.rb
189
+ - lib/redk/capn_panda/gerrit.rb
190
+ - lib/redk/capn_panda/jira_client.rb
191
+ - lib/redk/capn_panda/version.rb
192
+ - redk-capn_panda.gemspec
193
+ homepage: http://xredk.github.io/capn-panda
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.4.5
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: Cap'n Panda - The powers of git, jira, gerrit, jenkins combined.
217
+ test_files: []