-
Notifications
You must be signed in to change notification settings - Fork 10
/
remainingestimate-fix.groovy
57 lines (42 loc) · 1.69 KB
/
remainingestimate-fix.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//fixes problem with tempo timer
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.dvhb.remainingestimate-fix")
log.setLevel(Level.DEBUG)
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Query query = JqlQueryBuilder.newBuilder()
.where()
.currentEstimate().gt().number(0L)
.and()
.originalEstimate().gt().number(0L)
.and()
.timeSpent().gtEq().number(0L)
.buildQuery()
IssueManager issueManager = ComponentAccessor.getIssueManager()
SearchResults searchResult = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
Collection<Issue> issues = searchResult.issues
def allIssues = issues.collect { issueManager.getIssueObject(it.id) }
allIssues
.findAll { issue ->
def original = issue.getOriginalEstimate()
def remaining = issue.getEstimate()
def spent = issue.getTimeSpent()
def needsUpdate = (remaining != 0) && (remaining + spent != original)
return needsUpdate
}
.each { issue ->
Long remaining = issue.getOriginalEstimate() - issue.getTimeSpent()
issue.setEstimate(remaining)
issue.store()
}
log.debug(allIssues)