zit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.md +118 -0
- data/Rakefile +1 -0
- data/bin/zit +88 -0
- data/lib/zit.rb +152 -0
- data/lib/zit/jira_client.rb +27 -0
- data/lib/zit/management.rb +139 -0
- data/lib/zit/settings.rb +39 -0
- data/lib/zit/version.rb +3 -0
- data/zit.gemspec +28 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9049acb21091c3eb05fdebcb7d70e1e5a590bb44
|
4
|
+
data.tar.gz: bace68b6375180b0d1d2e63012c4d0816a3d0669
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66c54e57b1ff3fe35c5a7d83d9fc4c904b154da061bf04853dd34465a2220e689ada4aaf50bd0cdb7d71f9937299e3e239c08cc04b9b5eab6c75df2815dd2adf
|
7
|
+
data.tar.gz: c3de4392c9efc475a3af07a7c0ca0a1b89a8832474980dfbc653af8b219b48049b55e2fedd4083c84f3f93bba82b6e3948fa455cd3a5ed5fe948f735a9273651
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Adam Panzer
|
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,118 @@
|
|
1
|
+
# Zit
|
2
|
+
|
3
|
+
|
4
|
+
Goals:
|
5
|
+
|
6
|
+
* Provide a consistent looking pull request
|
7
|
+
* Make branch naming consistent
|
8
|
+
* Easily provide feedback to advocates about ticket status
|
9
|
+
|
10
|
+
# Install
|
11
|
+
|
12
|
+
$ gem install zit
|
13
|
+
|
14
|
+
# Configuration
|
15
|
+
|
16
|
+
Almost all configuration settings are stored in ~/.zit in YAML format. The default config, shown below, is in ruby hash for easier reading.
|
17
|
+
|
18
|
+
The default config is:
|
19
|
+
|
20
|
+
````ruby
|
21
|
+
{
|
22
|
+
:gitname => "doody", # your git username
|
23
|
+
:base_repo => nil, # base github repo
|
24
|
+
:last_branch => nil, # the last branch you were on when you ran init
|
25
|
+
:last_system => nil, # the last system you specified when you ran init
|
26
|
+
:repsteps_tag => "macro_1234", # replication steps tag (see below)
|
27
|
+
:include_repsteps_by_default => true, # include replication steps by default
|
28
|
+
:zendesk_url => nil, # The url of your Zendesk instance
|
29
|
+
:jira_url => nil, # The url of your jira instance
|
30
|
+
:settings_version => 1.0 # ignore this right now.
|
31
|
+
}
|
32
|
+
````
|
33
|
+
|
34
|
+
The only settings that MUST be set in this file are: zendesk\_url and jira\_url
|
35
|
+
|
36
|
+
In management.rb there is a method called "get\_repsteps". In there, you'll find this line:
|
37
|
+
|
38
|
+
````ruby
|
39
|
+
next unless audit.events.map(&:value).join(" ").include?(macro_tag)
|
40
|
+
````
|
41
|
+
|
42
|
+
The "macro_tag" refers to the setting in ~/.zit called repsteps\_tag (which refers to a tag that is added with a comment on a series of replication steps). This is only workable for Zendesk tickets as Jira issues do not have tags. If the repsteps\_tag is not found on any comment, you'll be given a list of all comments to pick amongst. In addition, the setting include\_repsteps\_by\_default can be swtiched to false in order to skip this process all together.
|
43
|
+
|
44
|
+
Finally, you'll need to have 5 environment variables set: zendesk\_user, zendesk\_token, jira\_user, jira\_pass, and optionally your gh_api_key which can be generated here: https://github.com/settings/applications (under "Personal Access Tokens")
|
45
|
+
|
46
|
+
The GH api token is only needed if you want to use the zit update function.
|
47
|
+
|
48
|
+
# Todo
|
49
|
+
|
50
|
+
1. Dry things up.
|
51
|
+
|
52
|
+
2. Fix up docs (the stuff below here is stale)
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
### Zendesk
|
57
|
+
|
58
|
+
**Description:** When used with Zendesk the syntax is as follows:
|
59
|
+
|
60
|
+
$ zit init -c zendesk -t [TICKET_ID]
|
61
|
+
|
62
|
+
Use this to start your workflow. The init command will initialize the repository. The -c/--connector flag will tell Zit which system you are talking to, zendesk or jira. The -t flag passes in the Zendesk ticket id number.
|
63
|
+
|
64
|
+
**Results:** Zit will create a new branch with a name composed of the format:
|
65
|
+
|
66
|
+
name/zd[ticket\_id]
|
67
|
+
|
68
|
+
For example:
|
69
|
+
|
70
|
+
Github Username: apanzerj
|
71
|
+
Ticket ID: 12345
|
72
|
+
|
73
|
+
$ zit init -c zendesk -t 12345
|
74
|
+
|
75
|
+
New branch name: apanzerj/zd12345
|
76
|
+
|
77
|
+
In addition, Zit will "pingback" the Zendesk ticket with a private comment:
|
78
|
+
|
79
|
+
"A branch for this ticket has been created. It should be named apanzerj/zd12345."
|
80
|
+
|
81
|
+
Once you have completed your work on the branch, you can use:
|
82
|
+
|
83
|
+
$ zit ready -c zendesk
|
84
|
+
|
85
|
+
Zit will detect the currently checked out branch. Zit will then call:
|
86
|
+
|
87
|
+
$ open https://github.com/....
|
88
|
+
|
89
|
+
such that your default browser opens to the correct repository with a valid PR waiting.
|
90
|
+
|
91
|
+
|
92
|
+
### Jira
|
93
|
+
|
94
|
+
Much of the details above are the same for Jira as they are for Zendesk with a few important distinctions:
|
95
|
+
|
96
|
+
When starting the workflow you'll want to do this (keeping with our example from above):
|
97
|
+
|
98
|
+
$ zit init -c jira -p HD -i 123
|
99
|
+
|
100
|
+
This will create a new branch for issue HD-123 where HD is the project and 123 is the issue.
|
101
|
+
|
102
|
+
Pingback does not make a "private comment"
|
103
|
+
|
104
|
+
When finished with your branch you can still type:
|
105
|
+
|
106
|
+
$ zit ready -c jira
|
107
|
+
|
108
|
+
But Zit will give you a list of comments to choose from so you can decide which one you want to be included as your pull request description.
|
109
|
+
|
110
|
+
Lastly, once you have submitted your pull request you can type:
|
111
|
+
|
112
|
+
$ zit update
|
113
|
+
|
114
|
+
To have Zit update the ticket/issue with the comment:
|
115
|
+
|
116
|
+
PR: {PR URL}
|
117
|
+
|
118
|
+
For the relevant pull request.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/zit
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'zit'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
subcommand = ARGV.shift unless ARGV[0] == "--help" || ARGV == "-h"# The subcommand is the first argument.
|
8
|
+
|
9
|
+
optparse = OptionParser.new do |opts|
|
10
|
+
opts.banner = <<-EOS
|
11
|
+
Usage:
|
12
|
+
|
13
|
+
The starting worflow is to begin your work. Use the subcommand "init" as in:
|
14
|
+
|
15
|
+
zit init -c CONNECTOR [params]
|
16
|
+
|
17
|
+
The finishing workflow, for when you are ready to create a pull request uses the "finish" subcommand, as in:
|
18
|
+
|
19
|
+
zit finish -c CONNECTOR
|
20
|
+
|
21
|
+
You can, additionally, run zit update -c CONNECTOR to post the now saved PR to the ticket.
|
22
|
+
|
23
|
+
The params for init are as follows:
|
24
|
+
|
25
|
+
EOS
|
26
|
+
|
27
|
+
# optparse doesn't like subcommands. So neither of the following are output when you call help.
|
28
|
+
["init", "finish", "update"].each do |flow|
|
29
|
+
options[flow.to_sym] = (subcommand == flow ? true : false)
|
30
|
+
end
|
31
|
+
|
32
|
+
# These options are output.
|
33
|
+
|
34
|
+
opts.on('-c', '--connector NAME', [:jira, :zendesk], "The connector. Either \"zendesk\" or \"jira\".") do |connector|
|
35
|
+
options[:system] = connector
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.separator("")
|
39
|
+
opts.separator("If working with Jira, the following are required params:")
|
40
|
+
|
41
|
+
|
42
|
+
opts.on("-p", "--project PROJECT", "The Jira project code.") do |project|
|
43
|
+
options[:project] = project
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("-i", "--issue ISSUE", "The Jira issue number.") do |issue|
|
47
|
+
options[:foreign_key] = issue
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.separator("")
|
51
|
+
opts.separator("If working with Zendesk, the following are required params:")
|
52
|
+
|
53
|
+
opts.on("-t", "--ticket TICKETID", "The ticket id of the Zendesk ticket.") do |tid|
|
54
|
+
options[:foreign_key] = tid
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.separator("")
|
58
|
+
|
59
|
+
options[:quiet] = false
|
60
|
+
opts.on("-q", "--quiet", "No pingbacks. No chatter to systems (jira/zendesk).") do
|
61
|
+
options[:quiet] = true
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on('-h', '--help', 'This help dialog') do
|
65
|
+
puts opts
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
optparse.parse!
|
72
|
+
if subcommand == "init"
|
73
|
+
if (options[:system].nil? || (options[:system] != :jira && options[:system] != :zendesk))
|
74
|
+
puts "No connector, or incorrect connector specified."
|
75
|
+
puts "#{options.inspect}, |#{options[:system]}|"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
end
|
79
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument
|
80
|
+
puts $!.to_s
|
81
|
+
puts optparse
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
zit_zap = Zit::Zap.new
|
86
|
+
zit_zap.init(options[:foreign_key], options[:system], options[:project], options[:quiet]) if options[:init]
|
87
|
+
zit_zap.finish(options[:quiet]) if options[:finish]
|
88
|
+
zit_zap.update if options[:update]
|
data/lib/zit.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
require "zit/version"
|
2
|
+
require "zit/jira_client"
|
3
|
+
require "zit/management"
|
4
|
+
require "zit/settings"
|
5
|
+
require "git"
|
6
|
+
require "zendesk_api"
|
7
|
+
require "CGI"
|
8
|
+
require "httparty"
|
9
|
+
|
10
|
+
module Zit
|
11
|
+
|
12
|
+
TOKEN = ENV['zendesk_token']
|
13
|
+
USER = ENV['zendesk_user']
|
14
|
+
|
15
|
+
JIRA_USER = ENV['jira_user']
|
16
|
+
JIRA_PASS = ENV['jira_pass']
|
17
|
+
|
18
|
+
class Error
|
19
|
+
def initialize(msg)
|
20
|
+
puts "Error: #{msg}"
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Zap
|
26
|
+
|
27
|
+
def init(fk, connector, project=nil, quiet)
|
28
|
+
# get settings from .zit
|
29
|
+
@settings = Zit::Settings.new
|
30
|
+
|
31
|
+
# initialize issue/ticket system
|
32
|
+
system = Zit::Management.new({:system => connector, :foreign_key => fk, :project=>project}, @settings)
|
33
|
+
|
34
|
+
#gather git data
|
35
|
+
Zit::Error.new("Not a git repository") unless File.directory?(".git")
|
36
|
+
@g = Git.open(Dir.pwd)
|
37
|
+
|
38
|
+
# make sure we haven't changed repos
|
39
|
+
validate_repo
|
40
|
+
|
41
|
+
# branch off of master!
|
42
|
+
checkout_master unless @g.current_branch.to_s == "master"
|
43
|
+
|
44
|
+
# derive the proper github username
|
45
|
+
begin
|
46
|
+
name = @g.config('github.user')
|
47
|
+
@settings.update_setting("gitname", name.to_s) if (@settings.get("gitname") == "doody" || @settings.get("gitname") != name)
|
48
|
+
rescue Git::GitExecuteError
|
49
|
+
puts "Github user not set! Using defualt 'doody'..."
|
50
|
+
name = "doody"
|
51
|
+
end
|
52
|
+
|
53
|
+
# name the new branch and checkout
|
54
|
+
new_branch = system.branch_name(name)
|
55
|
+
@g.branch(new_branch).checkout
|
56
|
+
|
57
|
+
# set last system and last branch
|
58
|
+
@settings.update_settings({:last_system => connector, :last_branch => new_branch})
|
59
|
+
|
60
|
+
# Provide a ping_back message
|
61
|
+
msg = "A branch for this #{connector == :jira ? "issue" : "ticket" } has been created. It should be named #{new_branch}."
|
62
|
+
system.ping_back(msg) unless quiet
|
63
|
+
end
|
64
|
+
|
65
|
+
def finish(quiet)
|
66
|
+
# Description: Finish workflow by calling ready. This method is the start of the "closing up" workflow.
|
67
|
+
settings = Zit::Settings.new
|
68
|
+
|
69
|
+
@g = Git.open(Dir.pwd)
|
70
|
+
@options = {}
|
71
|
+
@options[:current_branch] = @g.current_branch.to_s
|
72
|
+
|
73
|
+
# Create message for ping_back
|
74
|
+
msg = "A pull request is being made for this branch."
|
75
|
+
|
76
|
+
# Create the needed options hash
|
77
|
+
@options[:current_branch].match(/.*?\/zd(\d{1,8})/).nil? ? jira_ready : zendesk_ready
|
78
|
+
|
79
|
+
# Initialize system object
|
80
|
+
system = Zit::Management.new(@options, settings)
|
81
|
+
|
82
|
+
# Ping_back and pick comment.
|
83
|
+
# If the ENV['gh_api_key'] is nill, we want to ping back since we won't be updating the ticket
|
84
|
+
# with a PR link.
|
85
|
+
|
86
|
+
system.ping_back("A pull request for your branch is being created") unless (quiet || ENV['gh_api_key'].nil?)
|
87
|
+
system.ready
|
88
|
+
end
|
89
|
+
|
90
|
+
def update
|
91
|
+
# read settings
|
92
|
+
settings = Zit::Settings.new
|
93
|
+
|
94
|
+
# get GitHub key
|
95
|
+
gh_key = ENV['gh_api_key']
|
96
|
+
Zit::Error.new("GitHub key is missing! Can't update.") if gh_key.nil?
|
97
|
+
|
98
|
+
# Get the owner / repo and get relevant PR url
|
99
|
+
(owner, repo) = settings.get("base_repo").match(/com\/(.*?)\/(.*?)$/)[1..2]
|
100
|
+
response = HTTParty.get("https://api.github.com/repos/#{owner}/#{repo}/pulls", :query=>{:state => "open"}, :basic_auth => {:username => gh_key, :password=> "x-oauth-basic"}, :headers => {"User-Agent" => "zit_gem_0.0.1"})
|
101
|
+
selected_pr = response.select do |pr|
|
102
|
+
next if pr["head"]["ref"] != settings.get("last_branch")
|
103
|
+
pr
|
104
|
+
end
|
105
|
+
url = selected_pr.first["html_url"]
|
106
|
+
|
107
|
+
# Get necessary options for system ping_back
|
108
|
+
@options = {:current_branch => settings.get("last_branch")}
|
109
|
+
settings.get("last_system") == :zendesk ? zendesk_ready : jira_ready
|
110
|
+
|
111
|
+
# ping_back
|
112
|
+
system = Zit::Management.new(@options, settings)
|
113
|
+
system.ping_back("PR: #{url}")
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def checkout_master
|
119
|
+
# This is REALLY slow for large repos... Take out? Took me 24 seconds to get to master
|
120
|
+
puts "Attempting to switch to master..."
|
121
|
+
master = @g.branches[:master]
|
122
|
+
Zit::Error.new("Couldn't find branch master! #{master.inspect}") unless master
|
123
|
+
master.checkout
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# The following methods are for creating the options hash. If you want to change how your branches are named
|
128
|
+
# then these methods need to be updated.
|
129
|
+
|
130
|
+
def jira_ready
|
131
|
+
@options[:system] = :jira
|
132
|
+
mchdata = @options[:current_branch].match(/.*?\/([A-Za-z].*?)_(\d.*)/)
|
133
|
+
@options[:project] = mchdata[1]
|
134
|
+
@options[:foreign_key] = mchdata[2]
|
135
|
+
end
|
136
|
+
|
137
|
+
def zendesk_ready
|
138
|
+
@options[:system] = :zendesk
|
139
|
+
@options[:foreign_key] = @options[:current_branch].match(/.*?\/zd(\d{1,8})/)[1]
|
140
|
+
end
|
141
|
+
|
142
|
+
def validate_repo
|
143
|
+
# we need to make sure we haven't moved to a different local repo then last time.
|
144
|
+
|
145
|
+
(owner, repo) = @g.remote.url.to_s.match(/com:(.*)\/(.*)\.git$/)[1..2]
|
146
|
+
base_repo = "https://github.com/#{owner}/#{repo}"
|
147
|
+
unless base_repo == @settings.get("base_repo")
|
148
|
+
@settings.update_setting(:base_repo, "https://github.com/#{owner}/#{repo}")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "zit/settings"
|
3
|
+
|
4
|
+
module Zit
|
5
|
+
class JiraClient
|
6
|
+
include HTTParty
|
7
|
+
SETTINGS = Zit::Settings.new
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
response = self.class.get("#{SETTINGS.get("jira_url")}/dashboard", :basic_auth => self.auth )
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def auth
|
15
|
+
return { :username => JIRA_USER, :password => JIRA_PASS }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_issue(issue)
|
19
|
+
self.class.get("#{SETTINGS.get("jira_url")}/issue/#{issue}", :basic_auth => self.auth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_comment_to_issue(message, issue)
|
23
|
+
response = self.class.post("#{SETTINGS.get("jira_url")}/issue/#{issue}/comment", :body=>{:body => message.to_s}.to_json, :headers => {'content-type'=>'application/json'}, :basic_auth => self.auth)
|
24
|
+
response.code
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module Zit
|
2
|
+
class Management
|
3
|
+
def initialize(options = {}, settings)
|
4
|
+
@options = options
|
5
|
+
@settings = settings
|
6
|
+
|
7
|
+
# Options = {
|
8
|
+
# :system => [jira|zendesk]
|
9
|
+
# :project =>
|
10
|
+
# :foreign_key =>
|
11
|
+
# }
|
12
|
+
|
13
|
+
#Validate ENV and Options
|
14
|
+
Zit::Error.new("There was an error configuring the client.") unless set_client
|
15
|
+
options_validation(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_client
|
19
|
+
case @options[:system]
|
20
|
+
when :zendesk
|
21
|
+
env_set = (TOKEN.is_a?(String) && TOKEN.size > 0) && (USER.is_a?(String) && USER.size > 0)
|
22
|
+
Zit::Error.new("Unable to locate the zendesk_token and zendesk_user environment variables. Please set them and try again.") unless env_set
|
23
|
+
puts "Connecting to Zendesk..."
|
24
|
+
@client = ZendeskAPI::Client.new do |config|
|
25
|
+
config.url = @settings.get("zendesk_url")
|
26
|
+
config.username = USER
|
27
|
+
config.token = TOKEN
|
28
|
+
end
|
29
|
+
puts "Connected as #{@client.current_user[:name]}"
|
30
|
+
@options[:client] = @client
|
31
|
+
true
|
32
|
+
when :jira
|
33
|
+
@options[:client] = JiraClient.new()
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def options_validation(options)
|
39
|
+
begin
|
40
|
+
Zit::Error.new("Invalid system...") if options[:system] != :zendesk && options[:system] != :jira
|
41
|
+
case options[:system]
|
42
|
+
when :zendesk
|
43
|
+
pick_ticket_recent if options[:foreign_key].nil?
|
44
|
+
when :jira
|
45
|
+
Zit::Error.new("No jira project!") if options[:project].nil?
|
46
|
+
Zit::Error.new("No issue id!") if options[:foreign_key].nil?
|
47
|
+
end
|
48
|
+
true
|
49
|
+
rescue NoMethodError
|
50
|
+
Zit::Error.new("Nil Erorr")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def branch_name(username)
|
55
|
+
@options[:branch_name] ||= "#{username}/zd#{@options[:foreign_key]}" if @options[:system] == :zendesk
|
56
|
+
@options[:branch_name] ||= "#{username}/#{@options[:project]}_#{@options[:foreign_key]}" if @options[:system] == :jira
|
57
|
+
@options[:branch_name]
|
58
|
+
end
|
59
|
+
|
60
|
+
def ping_back(msg)
|
61
|
+
@options[:system] == :zendesk ? zendesk_pingback(msg) : jira_pingback(msg)
|
62
|
+
end
|
63
|
+
|
64
|
+
def ready
|
65
|
+
if @options[:system] == :zendesk
|
66
|
+
ticket = @options[:client].tickets.find(:id => @options[:foreign_key])
|
67
|
+
audits = ticket.audits.fetch
|
68
|
+
comments = audits.map{|m| m["events"].select{|c| c if c["type"] == "Comment"} }
|
69
|
+
rep_steps = (get_repsteps(audits) || pick_comment(comments.flatten!)) if @settings.get("include_repsteps_by_default")
|
70
|
+
elsif @options[:system] == :jira
|
71
|
+
issue = @options[:client].get_issue("#{@options[:project]}-#{@options[:foreign_key]}")
|
72
|
+
comments = issue["fields"]["comment"]["comments"]
|
73
|
+
rep_steps = (pick_comment(comments) || "Place a brief description here.") if @settings.get("include_repsteps_by_default")
|
74
|
+
end
|
75
|
+
rep_steps ||= "Description goes here..."
|
76
|
+
link = "#{pr_link}#{@options[:current_branch]}"
|
77
|
+
title_prefix = @options[:system] == :zendesk ? "ZD" : "#{@options[:project]}-"
|
78
|
+
cmd = "open '#{link}?pull_request[title]=#{title_prefix}#{@options[:foreign_key]}&pull_request[body]=#{CGI.escape(rep_steps)}'"
|
79
|
+
system(cmd)
|
80
|
+
end
|
81
|
+
|
82
|
+
def pick_comment(comments)
|
83
|
+
step = -1
|
84
|
+
until (0..comments.size-1).include?(step)
|
85
|
+
puts "Would you like to choose a comment from the issue as a description for your PR?"
|
86
|
+
comments.each_index do |n|
|
87
|
+
puts "#{n}. #{comments[n]["body"].inspect}"
|
88
|
+
end
|
89
|
+
print "(N)o, #:"
|
90
|
+
step = gets.chomp
|
91
|
+
step = Integer(step) unless step.to_s.downcase == "no"
|
92
|
+
return nil if step.to_s.downcase == "no"
|
93
|
+
end
|
94
|
+
comments[step]["body"]
|
95
|
+
end
|
96
|
+
|
97
|
+
def pr_link
|
98
|
+
link = "#{@settings.get("base_repo")}/compare/master..."
|
99
|
+
end
|
100
|
+
|
101
|
+
# Zendesk methods
|
102
|
+
|
103
|
+
def zendesk_pingback(msg)
|
104
|
+
ticket = @options[:client].tickets.find(:id => @options[:foreign_key].to_i)
|
105
|
+
ticket.comment = {:body => msg}
|
106
|
+
ticket.comment.public = false
|
107
|
+
puts "Creating ticket comment"
|
108
|
+
ticket.save
|
109
|
+
end
|
110
|
+
|
111
|
+
def get_repsteps(audits)
|
112
|
+
macro_tag = @settings.get("repsteps_tag")
|
113
|
+
aud = audits.detect do |audit|
|
114
|
+
next unless audit.events.map(&:type).include?("Change")
|
115
|
+
next unless audit.events.map(&:field_name).include?("tags")
|
116
|
+
next unless audit.events.map(&:value).join(" ").include?(" #{macro_tag} ")
|
117
|
+
audit
|
118
|
+
end
|
119
|
+
return aud.events.detect{|c| c.type == "Comment"}.body unless aud.nil?
|
120
|
+
return nil
|
121
|
+
end
|
122
|
+
|
123
|
+
def pick_ticket_recent
|
124
|
+
recent_list = @options[:client].tickets.recent.fetch
|
125
|
+
puts "No ticket specified. You can specify a ticket by using \"-t [ticket_id]\" as a parameter."
|
126
|
+
puts "Ticket ID\tSubject "
|
127
|
+
recent_list.each{|ticket| puts "#{ticket["id"]}\t#{ticket["subject"]}"}
|
128
|
+
exit
|
129
|
+
end
|
130
|
+
|
131
|
+
# Jira methods
|
132
|
+
|
133
|
+
def jira_pingback(msg)
|
134
|
+
issue = "#{@options[:project]}-#{@options[:foreign_key]}"
|
135
|
+
response = @options[:client].add_comment_to_issue(msg, issue)
|
136
|
+
puts "Jira issue updated!" if response == 201
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/zit/settings.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Zit
|
2
|
+
class Settings
|
3
|
+
DEFAULTS = {
|
4
|
+
:gitname => "doody",
|
5
|
+
:base_repo => nil,
|
6
|
+
:last_branch => nil,
|
7
|
+
:last_system => nil,
|
8
|
+
:repsteps_tag => "macro_1234",
|
9
|
+
:include_repsteps_by_default => true,
|
10
|
+
:zendesk_url => nil,
|
11
|
+
:jira_url => nil,
|
12
|
+
:settings_version => 1.0
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(system=nil)
|
16
|
+
write_settings_file!(true) unless File.exists?("#{ENV['HOME']}/.zit")
|
17
|
+
@settings = Psych.load(File.open("#{ENV['HOME']}/.zit"))
|
18
|
+
@settings
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(setting)
|
22
|
+
return @settings[setting.to_sym]
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_setting(setting_name, value)
|
26
|
+
@settings[setting_name] = value
|
27
|
+
write_settings_file!(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_settings(settings_hash)
|
31
|
+
@settings.merge!(settings_hash)
|
32
|
+
write_settings_file!(false)
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_settings_file!(defaults = true)
|
36
|
+
File.open("#{ENV['HOME']}/.zit", "w"){|settings| settings.puts(Psych.dump(defaults ? DEFAULTS : @settings)) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/zit/version.rb
ADDED
data/zit.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zit"
|
8
|
+
spec.version = Zit::VERSION
|
9
|
+
spec.authors = ["Adam Panzer"]
|
10
|
+
spec.email = ["apanzerj@gmail.com"]
|
11
|
+
spec.description = %q{A tool to unify zendesk and git as well as jira and git.}
|
12
|
+
spec.summary = %q{Unify zendesk and git, jira and git.}
|
13
|
+
spec.homepage = "https://github.com/apanzerj/zit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = ['zit']
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "git"
|
24
|
+
spec.add_runtime_dependency "httparty"
|
25
|
+
spec.add_runtime_dependency "zendesk_api"
|
26
|
+
spec.add_runtime_dependency "psych"
|
27
|
+
spec.post_install_message = "Remember to set ENV variables: jira_user, jira_pass, zendesk_user, zendesk_token."
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Panzer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-24 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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: git
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: zendesk_api
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: psych
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A tool to unify zendesk and git as well as jira and git.
|
98
|
+
email:
|
99
|
+
- apanzerj@gmail.com
|
100
|
+
executables:
|
101
|
+
- zit
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- MIT-LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/zit
|
111
|
+
- lib/zit.rb
|
112
|
+
- lib/zit/jira_client.rb
|
113
|
+
- lib/zit/management.rb
|
114
|
+
- lib/zit/settings.rb
|
115
|
+
- lib/zit/version.rb
|
116
|
+
- zit.gemspec
|
117
|
+
homepage: https://github.com/apanzerj/zit
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message: 'Remember to set ENV variables: jira_user, jira_pass, zendesk_user,
|
122
|
+
zendesk_token.'
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.0.3
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Unify zendesk and git, jira and git.
|
142
|
+
test_files: []
|