无法从类型为 ISSUE_COMMENT_DELETED_ID 的 JIRA 问题事件中获取已删除的评论 ID

Cannot get deleted comment id from JIRA's IssueEvent with type ISSUE_COMMENT_DELETED_ID

这个问题是关于atlassian JIRA插件开发的。当我使用事件监听器来处理 JIRA 的评论删除事件的 IssueEvent 时,我可以捕获事件类型为 "com.atlassian.jira.event.type.EventType.ISSUE_COMMENT_DELETED_ID" 的评论删除事件。但是我不知道如何获得在这个事件中被删除的评论id。我已经针对这种情况尝试了 IssueEvent.getComment,但它 returns 为空。

IssueEvent class 中有一个名为 COMMENTS_PARAM_NAME 的常量,这表明删除的评论可能位于名为 'params' 的映射中,该映射是 IssueEvent 对象的一部分(link 转到 JavaDoc 获取常量)。虽然这说的是"issue delete events",但可能能帮到你。

要查看您的情况是否存在这种情况,您可以尝试(假设您连接了一个记录器并且设置了正确的日志记录级别):

Map<String, Object> paramsMap = issueEvent.getParams();
for (String key : paramsMap.keySet()) {
    if (key.equals(IssueEvent.COMMENTS_PARAM_NAME)) {
        log.debug("Comments Param List Exists");
    }
}

看看它是否打印到 atlassian 日志。

如果它确实存在,那么您可以像这样尝试使用它:

Map<String, Object> paramsMap = issueEvent.getParams();
List<Comment> deletedCommentsList = paramsMap.get(IssueEvent.COMMENTS_PARAM_NAME);

// Do whatever you need to do with the Comments

N.B。 getParams()方法继承自JiraEventclass.

根据更改日志,您可以提取

 GenericValue genericValue = issueEvent.getChangeLog();
if (genericValue == null) {
    return;
}
List<GenericValue> changeItems = null;
try {
    changeItems = genericValue.getRelated("ChildChangeItem");
    String fieldName, fieldType;
    for (GenericValue changeItem : changeItems) {
        fieldType = (String) changeItem.get("fieldtype");
        fieldName = (String) changeItem.get("field");
        if ("JIRA".equalsIgnoreCase(fieldType) && IssueFieldConstants.COMMENT.equalsIgnoreCase(fieldName)) {        
            **Object commentId = changeItem.get("id");**        
            if (commentId != null && commentId.toString().length()>0) {

            } 
        }
    }       
} catch (GenericEntityException e) {}