bk-ci icon indicating copy to clipboard operation
bk-ci copied to clipboard

bug: git事件触发插件支持第三方服务changeFiles值总是为null

Open mingshewhe opened this issue 10 months ago • 0 comments

关联需求: #7743

问题

发送的body中changeFiles的值总是为空

原因

image 第2步赋的值,在第三步并没有生效。

模拟代码:

@Test
  fun filter() {
      var pushChangeFiles: Set<String>? = null
      val pathFilter = object: WebhookFilter {
          override fun doFilter() {
              pushChangeFiles = setOf("1", "2")
              println(pushChangeFiles)
          }
      }
      val thirdFilter = ThirdFilter(changeFiles = pushChangeFiles)
      listOf(pathFilter, thirdFilter).forEach { filter ->
          filter.doFilter()
      }
  }

输出:

[1, 2]
null

对代码进行反编译 image

解决方案

changeFile不在匿名类中计算

val isGetChangeFiles = !excludePaths.isNullOrBlank() || !includePaths.isNullOrBlank() || 
                    enableThirdFilter == true
  val pushChangeFiles = if (isGetChangeFiles) {
      getPushChangeFiles(event)
  } else {
      null
  }

mingshewhe avatar Apr 24 '24 04:04 mingshewhe