anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
178 stars 72 forks source link

In redmine , how to find out repository url of the current project #300

Closed oldunclez closed 1 year ago

oldunclez commented 1 year ago

In redmine , I have setup a repository for a project via https://github.com/linniksa/redmine_git_mirror The follow code works , it will find out the repository url of the project(id 1)

@project = Project.find(1)
@repository = @project.repository
system("echo #{@repository.url} >> /tmp/test ")

But I want to find out repository url of the current project , I have tried the following codes, none works

pid = @issue.project_id
@project = Project.find(pid)
@repository = @project.repository
system("echo #{@repository.url} >> /tmp/test ")

Workflow script executable before saving observable object contains error: Couldn't find Project without an ID

@project=@issue.project 
@repository = @project.repository
system("echo #{@repository.url} >> /tmp/test ")

Workflow script executable before saving observable object contains error: undefined methodrepository' for nil:NilClass`

pid = @issue.project_id
@project = Project.find(pid.to_i)
@repository = @project.repository
system("echo #{@repository.url} >> /tmp/test ")

Workflow script executable before saving observable object contains error: Couldn't find Project with 'id'=0

Any help is appreciated, Thx!

Environment:
  Redmine version                4.2.9.stable
  Ruby version                   2.7.7-p221 (2022-11-24) [x86_64-linux]
  Rails version                  5.2.8.1
  Environment                    production
  Database adapter               Mysql2
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
SCM:
  Subversion                     1.14.1
  Mercurial                      5.6.1
  Bazaar                         3.1.0
  Git                            2.30.2
  Filesystem                     
  GitMirror                      2.30.2
  GitRemote                      2.30.2
Redmine plugins:
  redmine_custom_workflows       2.0.8
  redmine_git_mirror             0.8.0
  redmine_git_remote             0.0.2
picman commented 1 year ago

I see several problems in your code:

  1. If you define a script in the administration, no issue exists. You must take it into account
  2. Assigning values to internal variables: @project = @issue.project is a nonsense
  3. sytem 'echo...'. Ruby has got different tools how to write into files.

Try this:

project = self.project 
if project
  repository = project.repository
  Rails.logger.info repository.url
end
oldunclez commented 1 year ago

Thank you ! Your code works.