lib/ruboty/jira/actions/base.rb in ruboty-jira-0.1.0 vs lib/ruboty/jira/actions/base.rb in ruboty-jira-0.2.0
- old
+ new
@@ -2,65 +2,86 @@
module Jira
module Actions
class Base < Ruboty::Actions::Base
def client
JIRA::Client.new(
- username: username,
- password: password,
- site: site,
- context_path: context,
- auth_type: :basic,
- use_ssl: use_ssl
+ username: jira_username,
+ password: jira_password,
+ site: jira_site,
+ context_path: jira_context,
+ auth_type: :basic,
+ use_ssl: use_ssl
)
end
- def fetch_project(key)
- client.Project.find(key)
- rescue
- log.error('JIRA HTTPError')
- nil
+ def jira_username
+ ENV['JIRA_USERNAME']
end
- def username
- ENV["JIRA_USERNAME"]
+ def jira_password
+ ENV['JIRA_PASSWORD']
end
- def password
- ENV["JIRA_PASSWORD"]
+ def jira_site
+ ENV['JIRA_URL']
end
- def site
- ENV["JIRA_URL"]
+ def jira_context
+ ENV['JIRA_CONTEXT_PATH'] || ''
end
- def context
- ENV["JIRA_CONTEXT_PATH"] || ''
- end
-
def use_ssl
- ENV["JIRA_USE_SSL"] || true
+ value = ENV['JIRA_USE_SSL']
+ return value unless value.nil?
+ true
end
def memory
message.robot.brain.data[Ruboty::Jira::NAME_SPACE] ||= {}
end
+ def users
+ memory['USERS'] ||= {}
+ end
+
+ def projects
+ memory['PROJECTS'] ||= {}
+ end
+
+ def associate_user
+ user = users[message.from_name]
+ return if user.nil?
+ user
+ end
+
+ def associate_project
+ project = projects[message.to]
+ return if project.nil?
+ project
+ end
+
def find_project(key)
client.Project.find(key)
rescue => e
Ruboty.logger.error e
- Ruboty.logger.info('JIRA HTTPError')
nil
end
- def find_issue(key, expected = true)
+ def find_issue(key)
client.Issue.find(key)
- rescue
- log.error('JIRA HTTPError') if expected
+ rescue => e
+ Ruboty.logger.error e
nil
end
- def quey_issues(jql)
+ def find_user(key)
+ client.User.find(key)
+ rescue => e
+ Ruboty.logger.error e
+ nil
+ end
+
+ def query_issue(jql)
client.Issue.jql(jql)
end
end
end
end