1
votes

I would like to know if is there an option to send a notification when log time worked is reaching estimating time.

example: Start.

Estimated: Original Estimate - 5 minutes 5m

Remaining: Remaining Estimate - 5 minutes 5m

Logged: Time Spent - Not Specified Not Specified

When i Log time.

Estimated: Original Estimate - 5 minutes 5m

Remaining: Time Spent - 4 minutes Remaining Estimate - 1 minute 1m

Logged: Time Spent - 4 minutes Remaining Estimate - 1 minute 4m

I like JIRA send the notification before 1 minute ending or what ever i set.

I'm sorry for the bad english.

Thank you

1

1 Answers

2
votes

I believe you wanted to create some kind of triggered event when logged work approaches original estimate, but I do not know how you could do that in JIRA. Nevertheless, I know something that still might help you to solve your problem.

Try using following groovy script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.config.properties.ApplicationProperties
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.issue.worklog.Worklog
import com.atlassian.jira.jql.parser.DefaultJqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.mail.Email
import com.atlassian.mail.MailException
import com.atlassian.mail.MailFactory
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.query.Query
import groovy.text.GStringTemplateEngine
import org.apache.log4j.Logger
import com.atlassian.core.util.DateUtils

def componentManager = ComponentManager.getInstance()
def worklogManager = componentManager.getWorklogManager()
def userUtil = componentManager.getUserUtil()
def user = userUtil.getUser('admin')
def searchProvider = componentManager.getSearchProvider()
def queryParser = new DefaultJqlQueryParser()
Logger log = Logger.getLogger('worklogNotification')

Query jql = queryParser.parseQuery('project = ABC and updated > startOfDay(-1d)')
SearchResults results = searchProvider.search(jql, user, PagerFilter.getUnlimitedFilter())
List issues = results.getIssues()
String emailFormat = 'HTML'
def mailServerManager = componentManager.getMailServerManager()
def mailServer = mailServerManager.getDefaultSMTPMailServer()
String defaultSubject = 'Logged work on JIRA issue %ISSUE% exceeds original estimate'
String body = ''
Map binding = [:]
String loggedWorkDiff = ''
String template = '''
Dear ${issue.assignee.displayName}, <br /><br />

Logged work on issue <a href="$baseUrl/browse/${issue.key}">${issue.key} (${issue.summary})</a> exceeds original estimate ($loggedWorkDiff more than expected).<br />

*** This is an automatically generated email, you do not need to reply ***<br />
'''
GStringTemplateEngine engine = new GStringTemplateEngine()

ApplicationProperties applicationProperties = componentManager.getApplicationProperties()
binding.put("baseUrl", applicationProperties.getString(APKeys.JIRA_BASEURL))

if (mailServer && ! MailFactory.isSendingDisabled()) {
    for (Issue issue in issues) {
        if(issue.originalEstimate) {
            loggedWork = 0
            worklogs = worklogManager.getByIssue(issue)
            worklogs.each{Worklog worklog -> loggedWork += worklog.getTimeSpent()}
            if(loggedWork - issue.originalEstimate) {
                loggedWorkDiff = DateUtils.getDurationString(Math.round(loggedWork - issue.originalEstimate))
                email = new Email(issue.getAssigneeUser().getEmailAddress())
                email.setFrom(mailServer.getDefaultFrom())
                email.setSubject(defaultSubject.replace('%ISSUE%', issue.getKey()))
                email.setMimeType(emailFormat == "HTML" ? "text/html" : "text/plain")
                binding.put("issue", issue)
                binding.put('loggedWorkDiff', loggedWorkDiff)

                body = engine.createTemplate(template).make(binding).toString()
                email.setBody(body)
                try {
                    log.debug ("Sending mail to ${email.getTo()}")
                    log.debug ("with body ${email.getBody()}")
                    log.debug ("from template ${template}")
                    SingleMailQueueItem item = new SingleMailQueueItem(email);
                    ComponentAccessor.getMailQueue().addItem(item);
                }
                catch (MailException e) {
                    log.warn ("Error sending email", e)
                }
            }
        }
    }
}

This script takes issues for project ABC, which have been updated during the previous day (JQL: "project = ABC and updated > startOfDay(-1d)"), calculates difference between logged work and estimated work and sends notification to the issue assignee if logged work exceeds original estimate.

You can add this script to the list of JIRA services (JIRA -> Administration -> System -> Advanced -> Services).

Name: [any name]

Class: com.onresolve.jira.groovy.GroovyService

Delay: 1440

Input file: [path to your script on server]

Delay: 1440

Note that you will put 1440 (min) as a service delay, which equals to one day. So, the script will be executed once per day sending notification to issue assignees about exceeded original estimates.

Also note that Groovy Scripting plugin should be installed in order to be able to run your script.