Class: Zit::Zap
- Inherits:
-
Object
- Object
- Zit::Zap
- Defined in:
- lib/zit.rb
Instance Method Summary collapse
Instance Method Details
#finish(quiet) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/zit.rb', line 65 def finish(quiet) # Description: Finish workflow by calling ready. This method is the start of the "closing up" workflow. settings = Zit::Settings.new @g = Git.open(Dir.pwd) @options = {} @options[:current_branch] = @g.current_branch.to_s # Create message for ping_back msg = "A pull request is being made for this branch." # Create the needed options hash @options[:current_branch].match(/.*?\/zd(\d{1,8})/).nil? ? jira_ready : zendesk_ready # Initialize system object system = Zit::Management.new(@options, settings) # Ping_back and pick comment. # If the ENV['gh_api_key'] is nill, we want to ping back since we won't be updating the ticket # with a PR link. system.ping_back("A pull request for your branch is being created") unless (quiet || ENV['gh_api_key'].nil?) system.ready end |
#init(fk, connector, project = nil, quiet) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zit.rb', line 27 def init(fk, connector, project=nil, quiet) # get settings from .zit @settings = Zit::Settings.new # initialize issue/ticket system system = Zit::Management.new({:system => connector, :foreign_key => fk, :project=>project}, @settings) #gather git data Zit::Error.new("Not a git repository") unless File.directory?(".git") @g = Git.open(Dir.pwd) # make sure we haven't changed repos validate_repo # branch off of master! checkout_master unless @g.current_branch.to_s == "master" # derive the proper github username begin name = @g.config()["github.user"] @settings.update_setting("gitname", name.to_s) if (@settings.get("gitname") == "doody" || @settings.get("gitname") != name) rescue Git::GitExecuteError puts "Github user not set! Using defualt 'doody'..." name = "doody" end # name the new branch and checkout new_branch = system.branch_name(name) @g.branch(new_branch).checkout # set last system and last branch @settings.update_settings({:last_system => connector, :last_branch => new_branch}) # Provide a ping_back message msg = "A branch for this #{connector == :jira ? "issue" : "ticket" } has been created. It should be named #{new_branch}." system.ping_back(msg) unless quiet end |
#update ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/zit.rb', line 90 def update # read settings settings = Zit::Settings.new # get GitHub key gh_key = ENV['gh_api_key'] Zit::Error.new("GitHub key is missing! Can't update.") if gh_key.nil? # Get the owner / repo and get relevant PR url (owner, repo) = settings.get("base_repo").match(/com\/(.*?)\/(.*?)$/)[1..2] 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"}) selected_pr = response.select do |pr| next if pr["head"]["ref"] != settings.get("last_branch") pr end url = selected_pr.first["html_url"] # Get necessary options for system ping_back @options = {:current_branch => settings.get("last_branch")} settings.get("last_system") == :zendesk ? zendesk_ready : jira_ready # ping_back system = Zit::Management.new(@options, settings) system.ping_back("PR: #{url}") end |