Willems Davy
Willems Davy

Reputation: 105

How to get the comments of a JIRA issue in a custom release note template

We upgraded our jira to version 5.0.5 today, before we were running version 4.2.4. In that version we had made a custom release notes template that would also show all comments made on an issue. To do that we had to be able to get a CommentManager object. We did this like this:

#foreach ($issue in $issueType.issues)
#if($issueType.issues.size() > 0)
    #set ($comments = $action.ComponentManager.CommentManager.getComments($issue))
    #if ($comments) 
       #foreach ($comment in $comments)
...

That worked fine in JIRA 4.2.4 however it isn't working anymore in jira 5.0.5, does anyone know how i can get a CommentManager object again when creating a custom release notes template in JIRA 5.0.5 or how to get a CommentManager object some other way, without using $action for example?

Upvotes: 0

Views: 2309

Answers (3)

Mousi
Mousi

Reputation: 276

In your vm template, write this:

#set ($componentAccessorClass        = $constantsManager.getClass().getClassLoader().findClass('com.atlassian.jira.component.ComponentAccessor'))
#set ($componentAccessorConstructor  = $componentAccessorClass.getConstructor())
#set ($componentAccessor             = $componentAccessorConstructor.newInstance())

Now you have access to the Component Accessor which can get you pretty much anything you want, including the Comment Manager.

Now, all you have to do is call getCommentManager() on your Component Accessor variable.

#set($commentManager = $componentAccessor.getCommentManager() ) 

Hope that helps ! :)

Upvotes: 1

Willems Davy
Willems Davy

Reputation: 105

this is the way i used in jira to get a componentmanager object, once you have the componentmanager object it's rather easy to do the rest:

#set ($componentManagerClass = $constantsManager.getClass().getClassLoader().findClass('com.atlassian.jira.ComponentManager'))
#set ($method = $componentManagerClass.getDeclaredMethod('getInstance', null))
#set ($componentManager = $method.invoke(null, null))

i'm using this solution now, and it can be rather helpfull to others to almost get any kind of class using the constantsmanager.

Upvotes: 0

mdoar
mdoar

Reputation: 6891

JiraWebActionSupport has the following deprecated method that provided the component manager object.

@Deprecated public ComponentManager getComponentManager() { return ComponentManager.getInstance(); }

and https://developer.atlassian.com/display/JIRADEV/Creating+a+Custom+Release+Notes+Template+Containing+Release+Comments has some Velocity code but looking at the 5.0.1 source it looks like Velocity is no longer being used?

I would file an Improvement at https://jira.atlassian.com/browse/JRA to add a getCommentManager method to JiraWebActionSupport.java

Upvotes: 0

Related Questions