I am currently writing a plugin the creates a new issue via a http post request. I am currently Having issues with creating and saving a new issue. Every time I cal issue.save, it returns false. I was hoping that someone would point me in the right direction. Thank you in advance
Here is the code I currently have:
issue = Issue.new
issue.tracker = Tracker.find_by_name("Bug")
issue.subject = params[:subject]
issue.description = params[:description]
issue.project = Project.find_by_name(params[:project])
issue.start_date = Time.now.localtime.strftime("%Y-%m-%d")
issue.priority = IssuePriority.find_by_name("Normal")
issue.author = User.find_by_mail("XXX@gmail.com")
issue.status = IssueStatus.find_by_name("New")
issue.save
Thank you for all your quick responses, They have helped me significantly.
After calling issue.errors.full_messages
, I discovered that I could not save the issue because required custom fields were not set.
I added the following code before calling issue.save
issue.custom_values = [
create_custom_value(CustomField.find_by_name("StackTrace").id, params[:stackTrace]),
... more custom values ...
]
also here is my create_custom_value method
# returns a new custom value
def create_custom_value(field_id, value)
custom_value = CustomValue.new
custom_value.custom_field_id = field_id
custom_value.value = value
custom_value.customized_type = "Issue"
return custom_value
end