You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Groovy/ScriptRunner将Story评论复制到其父级Epic?

使用ScriptRunner实现Story评论自动同步到父级Epic

核心实现思路

  • 借助ScriptRunner的事件监听器监听Story的评论创建事件
  • 校验当前Issue是否为Story类型且关联了父级Epic
  • 以原评论创建者作为执行者,将评论内容同步到对应Epic中

可直接使用的Groovy脚本

将以下脚本配置到ScriptRunner的事件监听器(监听Comment Created事件)即可:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.comment.CommentCreatedEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser

def commentService = ComponentAccessor.getCommentService()
def event = event as CommentCreatedEvent

// 获取当前评论关联的Issue、评论内容及原作者
Issue currentIssue = event.comment.issue
def comment = event.comment
ApplicationUser commentAuthor = comment.authorApplicationUser

// 判断当前Issue是否为Story,且存在父级Epic
if (currentIssue.issueType.name == "Story" && currentIssue.parentObject != null) {
    Issue parentEpic = currentIssue.parentObject
    
    // 验证父级Issue是否为Epic类型(需匹配你的Jira配置中的类型名称)
    if (parentEpic.issueType.name == "Epic") {
        // 构建带溯源信息的同步评论内容
        String syncCommentBody = """来自关联Story [${currentIssue.key}] 的评论:
---
${comment.body}
---
原评论作者:${commentAuthor.displayName}"""
        
        // 以原作者身份添加评论到Epic
        def commentParams = commentService.newCommentParameters()
            .issue(parentEpic)
            .body(syncCommentBody)
            .author(commentAuthor)
        
        commentService.addComment(commentAuthor, commentParams)
    }
}

配置步骤

  1. 进入Jira管理后台,打开ScriptRunner > Event Listeners
  2. 点击Create Listener,选择Custom Listener
  3. 监听事件选择Comment Created
  4. 粘贴上述脚本并保存配置

注意事项

  • 脚本中的"Story"和"Epic"需匹配你Jira实例中的Issue类型名称(部分团队可能使用英文或自定义名称)
  • 脚本自动使用原评论创建者作为执行账号,无需固定配置执行者
  • 同步的评论会保留原Story的Key、作者信息,便于后续溯源

内容的提问来源于stack exchange,提问作者Brian Gulizia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 04:44:53