Redmine问题创建代码

发布于 2025-01-06 13:16:32 字数 687 浏览 0 评论 0原文

我目前正在编写一个插件,通过 http post 请求创建一个新问题。我目前在创建和保存新问题时遇到问题。每次我调用 Issue.save 时,它​​都会返回 false。我希望有人能指出我正确的方向。预先感谢您

这是我目前拥有的代码:

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("[email protected]")
issue.status = IssueStatus.find_by_name("New")
issue.save

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("[email protected]")
issue.status = IssueStatus.find_by_name("New")
issue.save

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

踏月而来 2025-01-13 13:16:32

出现一些错误!检查 issues.errors 以检查以下内容:

Rails.logger.info issue.errors.inspect

Some error occurs! Examine issue.errors to check which:

Rails.logger.info issue.errors.inspect
楠木可依 2025-01-13 13:16:32

您可以使用 REST API 在 Redmine 中创建问题(以及执行许多其他操作)。

You can create Issues (and do many other things) in Redmine using REST API.

心安伴我暖 2025-01-13 13:16:32

感谢您的快速回复,他们对我帮助很大。

调用 issue.errors.full_messages 后,我发现无法保存问题,因为未设置所需的自定义字段。

我在调用 issues.save 之前添加了以下代码,

  issue.custom_values = [
    create_custom_value(CustomField.find_by_name("StackTrace").id, params[:stackTrace]),
    ... more custom values ...
  ]

这里也是我的 create_custom_value 方法

# 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文