...
Code Block |
---|
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.security.groups.GroupManager; import com.atlassian.jira.issue.IssueInputParameters; import com.atlassian.jira.bc.issue.IssueService; import com.atlassian.jira.bc.issue.DefaultIssueService; import com.atlassian.jira.bc.issue.worklog.WorklogInputParametersImpl.Builder; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.IssueInputParameters; import com.atlassian.jira.security.*; import org.slf4j.*; Logger log = LoggerFactory.getLogger(com.deniz.jira.worklog.scripting.ScriptingService.class); log.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); def issueManager = ComponentAccessor.getIssueManager(); def issueService = ComponentAccessor.getIssueService(); def authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); def customFieldManager = ComponentAccessor.getCustomFieldManager(); def currentUser = authenticationContext.getLoggedInUser(); def issue=worklogResult.getWorklog().getIssue(); def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link"); def epicIssue = issue.getCustomFieldValue(epicLinkCf); def parentObject=issue.getParentObject(); if(parentObject){ def epicIssueOfObject=parentObject.getCustomFieldValue(epicLinkCf); if(epicIssueOfObject){ //In this case,epic has a child issue and child issue has a subtask.Worklog is done for this subtask. epicIssue = epicIssueOfObject; } if(parentObject.issueType.name == 'Epic'){ //In this case,epic has a subtask.Worklog is done for this subtask. epicIssue=parentObject; log.debug("EPIC ISSUE IS PARENT OBJECT:{}", epicIssue); } } if (epicIssue!=null){ log.debug("EPIC ISSUE:{}", epicIssue); def issueSpentTime=worklog.getTimeSpent(); if (epicIssue){log.debug("TIME SPENT:{}", issueSpentTime); def epicEstimate=epicIssue.getEstimate(); log.debug("EPIC ESTIMATE:{}", epicEstimate); if(epicEstimate!=null){ //Since this script runs before worklog deletion process,issueSpentTime is added twice to remaining estimate,so the number issueSpentTime is divided by 2 in calculating 'epicEstimateUpdated' Long epicEstimateUpdated=epicEstimate+(issueSpentTime/2); log.debug("EPIC ESTIMATE UPDATED:{}", epicEstimateUpdated); IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); issueInputParameters.setRemainingEstimate((epicEstimateUpdated/60) + "m"); IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(currentUser, epicIssue.getId(), issueInputParameters); if(updateValidationResult.isValid()){ issueService.update(currentUser, updateValidationResult); }else{ log.error("!!!Error in Worklog Update Script:{}", getErrorCollection.getErrorCollection()) } } } return null; |