Behaviours plugin 0.5.10 compatibility with JIRA 6.1.7

Hello,

I have a duplicate search that is generated when users enter a string into the Subject and Description fields during issue creation. The script takes the string and displays 10 similar tickets under the field to prevent duplicate tickets being created.

I can add the code if required, but my question is has JIRA 6.1.7 changed something with the way fields are treated so that you cannot script responses from text fields?

There are no errors generated so it appears that our upgrade from JIRA 6.0.3 to 6.1.7 has broken this functionality.

Cheers,
Jordan 

2 answers

0 vote

This question is a bit too fuzzy to answer.  You ask about plugin compatibility in the title (answered at https://marketplace.atlassian.com/plugins/com.onresolve.jira.plugin.Behaviours/versions ), but then start talking about a script which tries to do something with fields.  It doesn't matter if JIRA has changed "something with the way fields are treated" (which, in the broadest sense, it has not, so that's a complete red-herring), because that, well, um, works.

What has broken is your script.  Not the upgrade.

What I'm heading to here is yes - show us the code, because the problem is somewhere in that.

Hi Nic, I've added extra info, but as another answer rather than a response to your asking for more info so you may not have received the notification that this has been updated. Does the extra info give you any clues as to what is preventing my script from running after the upgrade to 6.1.7? Any help would be appreciated. Cheers, Jordan

Is there any way to gain visibility for my question here?

Very fair call and cheers for the response. I was trying to keep it simple but can see it was a bit all over the place.

I'll add the code below and how it is set up to provide a more clear definition of my issue.

The script below searches 2 projects (kid and sid) for similar issues to that being created. It was working in JIRA 6.0.3 and generating errors when invalid characters were entered into the summary etc but now JIRA does not register any reference to my script at all in the logs nor display duplicates as it did in 6.0.3 (albeit with 0.5.6 of the plugin with that version of JIRA).

It is implemented via the behaviours plugin admin interface as below:

Field: Summary
Delete
Optional (Require) 
Writable (Readonly) 
Shown (Hide) 

Validator Class: /data/jira/scripts/AutoDupes.groovy
Validator Method: getPossibleDupes
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.jql.builder.JqlClauseBuilder
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.jql.builder.JqlOrderByBuilder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.query.Query
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
public class AutoDupes extends FieldBehaviours {
    // todo hrm... other languages
    def Set stopWords = new HashSet(["a", "an", "and", "are", "as", "at", "be", "but", "by",
        "for", "if", "in", "into", "is", "it",
        "no", "not", "of", "on", "or", "such",
        "that", "the", "their", "then", "there", "these",
        "they", "this", "to", "was", "will", "with"
    ])
        JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder()
        ComponentManager componentManager = ComponentManager.getInstance()
        SearchProvider searchProvider = componentManager.getSearchProvider()
        ApplicationUser appUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
        User user = appUser.getDirectoryUser()
    private int MAX_RESULTS = 15
    public void getPossibleDupes() {
        FormField frmSummary = getFieldById(getFieldChanged())
        Long pid = getFieldById("pid").getFormValue() as Long
                Long iid = getFieldById("id").getFormValue() as Long
                Long kid = 10061 as Long
                Long sid = 10001 as Long
                if (!pid) {
                        if (!iid) {
                                // Oh no!
                        } else {
                                IssueManager issueMgr = ComponentManager.getInstance().getIssueManager()
                                issue = issueMgr.getIssueObject(iid)
                                pid = issue.projectId
                        }
                }
        StringBuffer sb = new StringBuffer()
        def String summary = frmSummary.getFormValue() as String
        if (summary) {
            if (pid != sid) {
                query = builder
                .sub()
                        .summary(summary).or().description(summary).or().comment(summary)
                .endsub()
                .and().project(pid).buildQuery()
            } else {
                query = builder
                .sub()
                        .summary(summary).or().description(summary).or().comment(summary)
                .endsub()
                .and().project(kid).or().project(pid).buildQuery()
            }
            SearchResults searchResults = searchProvider.search(query, user, new PagerFilter(MAX_RESULTS))
            Collection issues = searchResults.getIssues()
            if (issues) {
                sb << "<div class=\"warningBox\">The following potential duplicates were found. Please look through them before submitting a new issue.<br><br>\n"
                issues.each {Issue issue ->
                    String highlightSummary = highlightMatches(summary, issue.getSummary())
                    sb << "<a href=\"../browse/${issue.getKey()}\" target=\"_blank\">${issue.getKey()}</a> - $highlightSummary<br>"
                }
                // todo: replace/append original help text
                sb << "</div>"
            }
        }
        // choose one of the two methods of returning feedback to the user
        // comment the following line if using overlays
        frmSummary.setHelpText(sb.toString())
        // or
        // uncomment the following 3 lines for overlays
        // if (sb.length()) {
        //     frmSummary.setOverlay(sb.toString())
        // }
    }
    public String highlightMatches(String searchTerm, String match) {
        searchTerm.split(/\s/).each {
            if (it && ! stopWords.contains(it)) {
                match = match.replaceAll(/$it/, "<em>$it</em>")
            }
        }
        match
    }
}

Thanks again,

Jordan

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

58 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you