import com.atlassian.jira.bc.issue.search.SearchService; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.search.SearchException; import com.atlassian.jira.issue.search.SearchResults; import com.atlassian.jira.jql.builder.JqlClauseBuilder; import com.atlassian.jira.jql.builder.JqlQueryBuilder; import com.atlassian.jira.service.AbstractService; import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.web.bean.PagerFilter; import com.atlassian.query.Query; import com.opensymphony.module.propertyset.PropertySet; import com.atlassian.jira.issue.customfields.option.Option; import java.util.Date; import java.util.List; import java.util.Map; ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("hktx"); //查询epic的字段为空的情况 String jqlEpic = "issuetype = Epic AND PI计划 in (2024_PI_Q2)"; CustomField cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10512L); CustomField cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10513L); CustomField cf3 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10514L); CustomField cf4 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10515L); log.debug(jqlEpic) try { SearchService searchService = (SearchService) ComponentAccessor.getComponentOfType(SearchService.class); SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlEpic); Query query = parseResult.getQuery(); SearchResults searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter()); List<Issue> epicList = searchResults.getResults(); String jqlStory = "issueFunction in issuesInEpics(\"key = %s \")"; for (int i = 0; i < epicList.size(); i++) { String jqlEpicNew = String.format(jqlStory, epicList.get(i).getKey()); log.debug(jqlEpicNew) parseResult = searchService.parseQuery(user, jqlEpicNew); query = parseResult.getQuery(); searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter()); List<Issue> storyList = searchResults.getResults(); log.debug(storyList.size()) for (int j = 0; j < storyList.size(); j++) { MutableIssue storyIssue = ComponentAccessor.getIssueManager().getIssueObject(storyList.get(j).getKey()); storyIssue.setCustomFieldValue(cf1, epicList.get(i).getCustomFieldValue(cf1)); storyIssue.setCustomFieldValue(cf2, epicList.get(i).getCustomFieldValue(cf2)); storyIssue.setCustomFieldValue(cf3, epicList.get(i).getCustomFieldValue(cf3)); storyIssue.setCustomFieldValue(cf4, epicList.get(i).getCustomFieldValue(cf4)); log.debug(storyIssue.getKey()) ComponentAccessor.getIssueManager().updateIssue(user, storyIssue, EventDispatchOption.ISSUE_UPDATED, false); // ComponentAccessor.getCommentManager().create(storyIssue,user,"补充数据",false); } } } catch (SearchException e) { }
Overview
Content Tools
Activity