Skip to content

Commit 40c53ac

Browse files
committed
Paths for Push and PullRequest events
1 parent 99c15d6 commit 40c53ac

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

src/main/scala/sbtghactions/GenerativePlugin.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,13 @@ ${indent(workflow.jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}"""
645645
List(
646646
WebhookEvent.Push(
647647
githubWorkflowTargetBranches.value.toList,
648-
githubWorkflowTargetTags.value.toList
648+
githubWorkflowTargetTags.value.toList,
649+
Nil
649650
),
650651
WebhookEvent.PullRequest(
651652
githubWorkflowTargetBranches.value.toList,
652653
Nil,
654+
Nil,
653655
githubWorkflowPREventTypes.value.toList
654656
)
655657
),

src/main/scala/sbtghactions/TriggerEvent.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,19 @@ object WebhookEvent {
115115

116116
case object Public extends PlainNameEvent
117117

118-
final case class PullRequest(branches: Seq[String], tags: Seq[String], types: Seq[PREventType])
118+
final case class PullRequest(
119+
branches: Seq[String],
120+
tags: Seq[String],
121+
paths: Seq[String],
122+
types: Seq[PREventType])
119123
extends WebhookEvent {
120124

121125
override def render: String =
122126
s"$name:" +
123-
indentOnce { renderBranches(branches) + renderTags + renderTypes }
127+
indentOnce { renderBranches(branches) + renderTags + renderPaths + renderTypes }
124128

125-
private def renderTags =
126-
renderParamWithList("tags", tags)
129+
private def renderTags = renderParamWithList("tags", tags)
130+
private def renderPaths: String = if (tags.isEmpty) "" else renderParamWithList("paths", paths)
127131

128132
private def renderTypes =
129133
if (types == PREventType.Defaults) ""
@@ -137,13 +141,15 @@ object WebhookEvent {
137141

138142
final case class PullRequestTarget(types: Seq[PRTargetEventType]) extends TypedEvent
139143

140-
final case class Push(branches: Seq[String], tags: Seq[String]) extends WebhookEvent {
144+
final case class Push(branches: Seq[String], tags: Seq[String], paths: Seq[String])
145+
extends WebhookEvent {
141146

142147
override def render: String =
143148
s"$name:" +
144-
indentOnce { renderBranches(branches) + renderTags }
149+
indentOnce { renderBranches(branches) + renderTags + renderPaths }
145150

146-
def renderTags: String = if (tags.isEmpty) "" else renderParamWithList("tags", tags)
151+
def renderTags: String = if (tags.isEmpty) "" else renderParamWithList("tags", tags)
152+
def renderPaths: String = if (tags.isEmpty) "" else renderParamWithList("paths", paths)
147153

148154
}
149155

src/test/scala/sbtghactions/GenerativePluginSpec.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class GenerativePluginSpec extends Specification {
4949
Workflow(
5050
"test",
5151
List(
52-
WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults),
53-
WebhookEvent.Push(List("main"), Nil)
52+
WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults),
53+
WebhookEvent.Push(List("main"), Nil, Nil)
5454
),
5555
Nil,
5656
Map(),
@@ -76,8 +76,8 @@ class GenerativePluginSpec extends Specification {
7676
Workflow(
7777
"test",
7878
List(
79-
WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults),
80-
WebhookEvent.Push(List("main"), List("howdy"))
79+
WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults),
80+
WebhookEvent.Push(List("main"), List("howdy"), Nil)
8181
),
8282
Nil,
8383
Map(),
@@ -106,8 +106,9 @@ class GenerativePluginSpec extends Specification {
106106
WebhookEvent.PullRequest(
107107
List("main"),
108108
Nil,
109+
Nil,
109110
List(PREventType.ReadyForReview, PREventType.ReviewRequested, PREventType.Opened)),
110-
WebhookEvent.Push(List("main"), Nil)),
111+
WebhookEvent.Push(List("main"), Nil, Nil)),
111112
Nil,
112113
Map(),
113114
),
@@ -143,8 +144,8 @@ class GenerativePluginSpec extends Specification {
143144
Workflow(
144145
"test2",
145146
List(
146-
WebhookEvent.PullRequest(List("main", "backport/v*"), Nil, PREventType.Defaults),
147-
WebhookEvent.Push(List("main", "backport/v*"), Nil)
147+
WebhookEvent.PullRequest(List("main", "backport/v*"), Nil, Nil, PREventType.Defaults),
148+
WebhookEvent.Push(List("main", "backport/v*"), Nil, Nil)
148149
),
149150
List(
150151
WorkflowJob(
@@ -195,8 +196,8 @@ class GenerativePluginSpec extends Specification {
195196
Workflow(
196197
"test3",
197198
List(
198-
WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults),
199-
WebhookEvent.Push(List("main"), Nil)
199+
WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults),
200+
WebhookEvent.Push(List("main"), Nil, Nil)
200201
),
201202
List(
202203
WorkflowJob(
@@ -240,8 +241,8 @@ class GenerativePluginSpec extends Specification {
240241
Workflow(
241242
"test4",
242243
List(
243-
WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults),
244-
WebhookEvent.Push(List("main"), Nil)
244+
WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults),
245+
WebhookEvent.Push(List("main"), Nil, Nil)
245246
),
246247
List(
247248
WorkflowJob(
@@ -292,8 +293,8 @@ class GenerativePluginSpec extends Specification {
292293
Workflow(
293294
"test4",
294295
List(
295-
WebhookEvent.PullRequest(List("main"), Nil, PREventType.Defaults),
296-
WebhookEvent.Push(List("main"), Nil)
296+
WebhookEvent.PullRequest(List("main"), Nil, Nil, PREventType.Defaults),
297+
WebhookEvent.Push(List("main"), Nil, Nil)
297298
),
298299
List(
299300
WorkflowJob(

src/test/scala/sbtghactions/TriggerEventSpec.scala

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,31 +127,39 @@ class TriggerEventSpec extends Specification with AllExpectations {
127127
}
128128

129129
"push" should {
130-
"render without branches, tags or types" in {
130+
"render without branches, tags or paths" in {
131131
val expected = "push:"
132-
WebhookEvent.Push(Nil, Nil).render mustEqual expected
132+
WebhookEvent.Push(Nil, Nil, Nil).render mustEqual expected
133133
}
134134

135-
"render without branches, but with tags and types" in {
135+
"render without branches, but with tags and paths" in {
136136
val expected =
137137
"""|push:
138-
| tags: [v1*, v2*]""".stripMargin
139-
WebhookEvent.Push(Nil, List("v1*", "v2*")).render mustEqual expected
138+
| tags: [v1*, v2*]
139+
| paths: ['scr/main/**']""".stripMargin
140+
WebhookEvent.Push(Nil, List("v1*", "v2*"), List("src/main/**")).render mustEqual expected
141+
}
142+
143+
"render only with paths" in {
144+
val expected =
145+
"""|push:
146+
| paths: ['scr/main/**']""".stripMargin
147+
WebhookEvent.Push(Nil, Nil, List("src/main/**")).render mustEqual expected
140148
}
141149

142150
"render with branches and tags" in {
143151
val expected =
144152
"""|push:
145153
| branches: [master]
146154
| tags: [v1*, v2*]""".stripMargin
147-
WebhookEvent.Push(List("master"), List("v1*", "v2*")).render mustEqual expected
155+
WebhookEvent.Push(List("master"), List("v1*", "v2*"), Nil).render mustEqual expected
148156
}
149157

150158
"render without tags, but with branches" in {
151159
val expected =
152160
"""|push:
153161
| branches: [master]""".stripMargin
154-
WebhookEvent.Push(List("master"), Nil).render mustEqual expected
162+
WebhookEvent.Push(List("master"), Nil, Nil).render mustEqual expected
155163
}
156164
}
157165

0 commit comments

Comments
 (0)