开发者

JIRA + Savon + Ruby issues

开发者 https://www.devze.com 2023-03-31 02:52 出处:网络
I am trying to get my new application integrated with JIRA for management of our customer\'s support tickets.What I had envisioned the system doing was in a before_filter gathering a user\'s account f

I am trying to get my new application integrated with JIRA for management of our customer's support tickets. What I had envisioned the system doing was in a before_filter gathering a user's account from within JIRA - from that I can pull up a list of accounts and what not, and if they don't have one then we create one based on their details in the Rails application. Thing is I'm having major issues doing things like removing the user from the jira-users group and adding them to a separate group I have for customers called customer-support. This is the code I have currently:

def current_jira_user
    # Fetch the current user in JIRA, if we don't exist, create it!
    user_try = @jira.request :get_user do |soap|
      soap.body = { :token => @token, :username => "#{current_user.username}" }
    end
    if user_try.to_hash[:get_user_response][:get_user_return][:href].nil?
      # We need to create the user
      @jira.request :create_user do |soap|
        soap.body = {
            :token => @token,
            :username => "#{current_user.username}",
            :password => UUID.new.to_s,
            :fullName => current_user.full_name,
            :email => "noreply@XXXXX.XXX" #this is such a hack to get around JIRA's "you've got an account" email
        }
      end
      new_user = RemoteUser.find(current_user.username)
      @jira.request :remove_user_from_group do |soap|
        soap.body = { :token => @token, :group => RemoteGroup.find('jira-users'), :ruser => new_user }
      end
      @jira.request :add_user_to_group do |soap|
        soap.body = { :token => @token, :group => RemoteGroup.find('customer-support'), :ruser => new_user }
      end
      new_user[:email] = current_user.email
      @jira.request :update_user do |soap| # change their email to the valid one
   开发者_如何转开发     soap.body = { :token => @token, :ruser => new_user }
      end
      new_user
    else
      user_try.to_hash[:get_user_response][:get_user_return]
    end
  end

  def verify_jira_connection
    # Verify that we can reach the JIRA instance
    @jira = Savon::Client.new do
      wsdl.document = JIRA_SOAP_URI
    end
    @jira.http.read_timeout = 300
    @jira.http.auth.ssl.verify_mode = :none

    @auth = @jira.request :login do |soap|
      soap.body = { :username => JIRA_LOGIN, :password => JIRA_PASSWORD }
    end
    @token = @auth.to_hash[:login_response][:login_return]
  end

## REMOTE CLASSES
  class RemoteUser
    include Savon::Model

    client do
      http.headers["Pragma"] = "no-cache"
      http.auth.ssl.verify_mode = :none
    end

    namespace "http://beans.soap.rpc.jira.atlassian.com"
    endpoint JIRA_SOAP_URI

    basic_auth JIRA_LOGIN, JIRA_PASSWORD

    actions :get_user

    def self.find(username)
      get_user(:username => username).to_hash
    end
  end

  class RemoteGroup
    include Savon::Model

    client do
      http.headers["Pragma"] = "no-cache"
      http.auth.ssl.verify_mode = :none
    end

    namespace "http://beans.soap.rpc.jira.atlassian.com"
    endpoint JIRA_SOAP_URI

    basic_auth JIRA_LOGIN, JIRA_PASSWORD

    actions :get_group

    def self.find(group)
      get_group(:groupName => group).to_hash
    end
  end

Users are created just fine, but when I get to the removeUserFromGroup call, I get (soapenv:Server.userException) com.atlassian.jira.rpc.exception.RemoteValidationException: group name cannot be null, needs a value. Using the Jira4R gem is out thanks to our using Ruby 1.9.2. Any help is appreciated. Thanks!


Maybe you need to explicitly send the name?

:group => RemoteGroup.find('jira-users').name

instead of this

:group => RemoteGroup.find('jira-users')

If you were willing to do some rewriting, you could try using a Ruby 1.9-compatible fork of jira4r

0

精彩评论

暂无评论...
验证码 换一张
取 消