diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 92249cd..269a14a 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -645,11 +645,13 @@ ${indent(workflow.jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}""" List( WebhookEvent.Push( githubWorkflowTargetBranches.value.toList, - githubWorkflowTargetTags.value.toList + githubWorkflowTargetTags.value.toList, + Nil ), WebhookEvent.PullRequest( githubWorkflowTargetBranches.value.toList, Nil, + Nil, githubWorkflowPREventTypes.value.toList ) ), diff --git a/src/main/scala/sbtghactions/TriggerEvent.scala b/src/main/scala/sbtghactions/TriggerEvent.scala index f967e06..4dfdc11 100644 --- a/src/main/scala/sbtghactions/TriggerEvent.scala +++ b/src/main/scala/sbtghactions/TriggerEvent.scala @@ -115,15 +115,19 @@ object WebhookEvent { case object Public extends PlainNameEvent - final case class PullRequest(branches: Seq[String], tags: Seq[String], types: Seq[PREventType]) + final case class PullRequest( + branches: Seq[String], + tags: Seq[String], + paths: Seq[String], + types: Seq[PREventType]) extends WebhookEvent { override def render: String = s"$name:" + - indentOnce { renderBranches(branches) + renderTags + renderTypes } + indentOnce { renderBranches(branches) + renderTags + renderPaths + renderTypes } - private def renderTags = - renderParamWithList("tags", tags) + private def renderTags = renderParamWithList("tags", tags) + private def renderPaths: String = if (tags.isEmpty) "" else renderParamWithList("paths", paths) private def renderTypes = if (types == PREventType.Defaults) "" @@ -137,13 +141,15 @@ object WebhookEvent { final case class PullRequestTarget(types: Seq[PRTargetEventType]) extends TypedEvent - final case class Push(branches: Seq[String], tags: Seq[String]) extends WebhookEvent { + final case class Push(branches: Seq[String], tags: Seq[String], paths: Seq[String]) + extends WebhookEvent { override def render: String = s"$name:" + - indentOnce { renderBranches(branches) + renderTags } + indentOnce { renderBranches(branches) + renderTags + renderPaths } - def renderTags: String = if (tags.isEmpty) "" else renderParamWithList("tags", tags) + def renderTags: String = if (tags.isEmpty) "" else renderParamWithList("tags", tags) + def renderPaths: String = if (tags.isEmpty) "" else renderParamWithList("paths", paths) } diff --git a/src/test/scala/sbtghactions/GenerativePluginSpec.scala b/src/test/scala/sbtghactions/GenerativePluginSpec.scala index d68d2c4..69454b9 100644 --- a/src/test/scala/sbtghactions/GenerativePluginSpec.scala +++ b/src/test/scala/sbtghactions/GenerativePluginSpec.scala @@ -49,8 +49,8 @@ class GenerativePluginSpec extends Specification { Workflow( "test", List( - WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults), - WebhookEvent.Push(List("main"), Nil) + WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults), + WebhookEvent.Push(List("main"), Nil, Nil) ), Nil, Map(), @@ -76,8 +76,8 @@ class GenerativePluginSpec extends Specification { Workflow( "test", List( - WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults), - WebhookEvent.Push(List("main"), List("howdy")) + WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults), + WebhookEvent.Push(List("main"), List("howdy"), Nil) ), Nil, Map(), @@ -106,8 +106,9 @@ class GenerativePluginSpec extends Specification { WebhookEvent.PullRequest( List("main"), Nil, + Nil, List(PREventType.ReadyForReview, PREventType.ReviewRequested, PREventType.Opened)), - WebhookEvent.Push(List("main"), Nil)), + WebhookEvent.Push(List("main"), Nil, Nil)), Nil, Map(), ), @@ -143,8 +144,8 @@ class GenerativePluginSpec extends Specification { Workflow( "test2", List( - WebhookEvent.PullRequest(List("main", "backport/v*"), Nil, PREventType.Defaults), - WebhookEvent.Push(List("main", "backport/v*"), Nil) + WebhookEvent.PullRequest(List("main", "backport/v*"), Nil, Nil, PREventType.Defaults), + WebhookEvent.Push(List("main", "backport/v*"), Nil, Nil) ), List( WorkflowJob( @@ -195,8 +196,8 @@ class GenerativePluginSpec extends Specification { Workflow( "test3", List( - WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults), - WebhookEvent.Push(List("main"), Nil) + WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults), + WebhookEvent.Push(List("main"), Nil, Nil) ), List( WorkflowJob( @@ -240,8 +241,8 @@ class GenerativePluginSpec extends Specification { Workflow( "test4", List( - WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults), - WebhookEvent.Push(List("main"), Nil) + WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults), + WebhookEvent.Push(List("main"), Nil, Nil) ), List( WorkflowJob( @@ -292,8 +293,8 @@ class GenerativePluginSpec extends Specification { Workflow( "test4", List( - WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults), - WebhookEvent.Push(List("main"), Nil) + WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults), + WebhookEvent.Push(List("main"), Nil, Nil) ), List( WorkflowJob( diff --git a/src/test/scala/sbtghactions/TriggerEventSpec.scala b/src/test/scala/sbtghactions/TriggerEventSpec.scala index 89e8025..59f7949 100644 --- a/src/test/scala/sbtghactions/TriggerEventSpec.scala +++ b/src/test/scala/sbtghactions/TriggerEventSpec.scala @@ -127,16 +127,24 @@ class TriggerEventSpec extends Specification with AllExpectations { } "push" should { - "render without branches, tags or types" in { + "render without branches, tags or paths" in { val expected = "push:" - WebhookEvent.Push(Nil, Nil).render mustEqual expected + WebhookEvent.Push(Nil, Nil, Nil).render mustEqual expected } - "render without branches, but with tags and types" in { + "render without branches, but with tags and paths" in { val expected = """|push: - | tags: [v1*, v2*]""".stripMargin - WebhookEvent.Push(Nil, List("v1*", "v2*")).render mustEqual expected + | tags: [v1*, v2*] + | paths: ['scr/main/**']""".stripMargin + WebhookEvent.Push(Nil, List("v1*", "v2*"), List("src/main/**")).render mustEqual expected + } + + "render only with paths" in { + val expected = + """|push: + | paths: ['scr/main/**']""".stripMargin + WebhookEvent.Push(Nil, Nil, List("src/main/**")).render mustEqual expected } "render with branches and tags" in { @@ -144,14 +152,14 @@ class TriggerEventSpec extends Specification with AllExpectations { """|push: | branches: [master] | tags: [v1*, v2*]""".stripMargin - WebhookEvent.Push(List("master"), List("v1*", "v2*")).render mustEqual expected + WebhookEvent.Push(List("master"), List("v1*", "v2*"), Nil).render mustEqual expected } "render without tags, but with branches" in { val expected = """|push: | branches: [master]""".stripMargin - WebhookEvent.Push(List("master"), Nil).render mustEqual expected + WebhookEvent.Push(List("master"), Nil, Nil).render mustEqual expected } }