Skip to content

Commit

Permalink
2.0.1: changeKind should match patch set created events only
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sims committed Sep 28, 2017
1 parent c55aa5e commit f48bf2c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'sims.michael.gerritslackbot'
version '2.0.0'
version '2.0.1'

buildscript {
ext.kotlin_version = '1.1.50'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ data class ChangeMatcher(
) {

fun matches(event: ChangeEvent): Boolean {
return project.toLowerCase() in listOf("*", event.change.project.toLowerCase())
&& branch.toLowerCase() in listOf("*", event.change.branch.toLowerCase())
&& (isVerificationOnly == null || isVerificationOnly == event.isVerificationOnly)
&& (changeKind == null || changeKind.toLowerCase() == event.changeKindOrNull?.toLowerCase())
&& (subject == "*" || event.change.subject?.safeMatches(subject) ?: false)
val projectMatches = project.toLowerCase() in listOf("*", event.change.project.toLowerCase())
val branchMatches = branch.toLowerCase() in listOf("*", event.change.branch.toLowerCase())
val isVerificationOnlyMatches = isVerificationOnly == null || isVerificationOnly == event.isVerificationOnly
val eventChangeKind = event.changeKindOrNull
val changeKindMatches = changeKind == null || eventChangeKind == null
|| changeKind.toLowerCase() == eventChangeKind.toLowerCase()
val subjectMatches = subject == "*" || event.change.subject?.safeMatches(subject) ?: false
return projectMatches && branchMatches && isVerificationOnlyMatches && changeKindMatches && subjectMatches
}

private val ChangeEvent.isVerificationOnly: Boolean
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'sims.michael.gerritslackbot'
version '2.0.0'
version '2.0.1'

buildscript {
ext.kotlin_version = '1.1.50'
Expand Down
2 changes: 1 addition & 1 deletion tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'sims.michael.gerritslackbot'
version '2.0.0'
version '2.0.1'

buildscript {
ext.kotlin_version = '1.1.50'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class EventGroupingTransformerTest {
groups.any { it.events.any { it is PatchSetCreatedEvent && it.patchSet.kind != ChangeKind.REWORK } })
}

@Test
fun change_kind_matches_for_patch_set_created_events_only() {
val eventMatchingTransformer = EventGroupingTransformer(listOf(
ChangeMatcher("*", "*", "*", "channel", changeKind = "rework")
))
val groups = getEventGroupsWithTransformer(eventMatchingTransformer)
assertTrue("Change kind matcher should be applied to PatchSetCreatedEvent only",
groups.any { it.events.any { it.change.id == "6" } })
}

private fun getEventGroupsWithTransformer(eventGroupingTransformer: EventGroupingTransformer): List<EventGroup<*>> =
this::class.java.getResourceAsStream("test/json/events-for-matching.txt")
.bufferedReader().lineSequence().toFlowable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
{"type":"comment-added","author":{"name":"Turanga Leela","email":"[email protected]","username":"turangaleela"},"approvals":[{"type":"Code-Review","description":"Code-Review","value":"2","oldValue":null,"grantedOn":null,"by":null},{"type":"Verified","description":"Verified","value":"1","oldValue":null,"grantedOn":null,"by":null}],"comment":"What a sorry fella, rolled up and smoked like a Panetela","patchSet":{"number":1,"revision":"f87ccd05ea48fcd9d5f7c6671b85bf7e41435517","parents":["91aec6e161ce6fe82979654daf43c885bec857e7"],"ref":"refs/changes/43/88343/1","uploader":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"createdOn":1501530028,"author":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"isDraft":false,"kind":"REWORK","approvals":null,"comments":null,"files":null,"sizeInsertions":8,"sizeDeletions":-2},"change":{"project":"The Dungeon Master","branch":"my-feature","topic":null,"id":"3","number":88343,"subject":"This is a subject","owner":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"assignee":null,"url":"http://www.example.com/Id8db","commitMessage":"Made some changes","createdOn":null,"lastUpdated":null,"open":null,"status":"NEW","comments":null,"trackingIds":null,"currentPatchSet":null,"patchSets":null,"dependsOn":null,"neededBy":null,"submitRecords":null,"allReviewers":null},"type":"comment-added","eventCreatedOn":1501530512}
{"type":"patchset-created","uploader":{"name":"Bender \"Bending\" Rodriguez","email":"[email protected]","username":"bender"},"patchSet":{"number":1,"revision":"f87ccd05ea48fcd9d5f7c6671b85bf7e41435517","parents":["91aec6e161ce6fe82979654daf43c885bec857e7"],"ref":"refs/changes/43/88343/1","uploader":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"createdOn":1501530028,"author":{"name":"Bender \"Bending\" Rodriguez","email":"[email protected]","username":"bender"},"isDraft":false,"kind":"TRIVIAL_REBASE","approvals":null,"comments":null,"files":null,"sizeInsertions":8,"sizeDeletions":-2},"change":{"project":"Frobozz","branch":"feature-one","topic":null,"id":"4","number":88343,"subject":"WIP: This is a subject","owner":{"name":"Bender \"Bending\" Rodriguez","email":"[email protected]","username":"bender"},"assignee":null,"url":"http://www.example.com/dJk2i","commitMessage":"Made some changes","createdOn":null,"lastUpdated":null,"open":null,"status":"NEW","comments":null,"trackingIds":null,"currentPatchSet":null,"patchSets":null,"dependsOn":null,"neededBy":null,"submitRecords":null,"allReviewers":null},"type":"patchset-created","eventCreatedOn":1501530028}
{"type":"patchset-created","uploader":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"patchSet":{"number":5,"revision":"8d55a5ac28ba653ccef816b026b3d612d3a6698a","parents":["5e65caa6d114ef1492a283ac2ad2236b2c8b0109"],"ref":"refs/changes/94/87794/5","uploader":{"name":"Turanga Leela","email":"[email protected]","username":"turangaleela"},"createdOn":1501530090,"author":{"name":"Bender \"Bending\" Rodriguez","email":"[email protected]","username":"bender"},"isDraft":false,"kind":"REWORK","approvals":null,"comments":null,"files":null,"sizeInsertions":160,"sizeDeletions":-74},"change":{"project":"Froboztic","branch":"feature-two","topic":null,"id":"5","number":87794,"subject":"This is a subject","owner":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"assignee":null,"url":"http://www.example.com/qFAJc","commitMessage":"Made some changes","createdOn":null,"lastUpdated":null,"open":null,"status":"NEW","comments":null,"trackingIds":null,"currentPatchSet":null,"patchSets":null,"dependsOn":null,"neededBy":null,"submitRecords":null,"allReviewers":null},"type":"patchset-created","eventCreatedOn":1501530090}
{"type":"comment-added","author":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"approvals":[{"type":"Code-Review","description":"Code-Review","value":"2","oldValue":null,"grantedOn":null,"by":null}],"comment":"Cigars are evil, you won't miss 'em","patchSet":{"number":2,"revision":"0734b7a8c270ffca62553cb78955a0d4b35c611e","parents":["15b11756d9dc130bc7b87b5aa82886e8daff5a91"],"ref":"refs/changes/35/88335/2","uploader":{"name":"Turanga Leela","email":"[email protected]","username":"turangaleela"},"createdOn":1501526757,"author":{"name":"Turanga Leela","email":"[email protected]","username":"turangaleela"},"isDraft":false,"kind":"TRIVIAL_REBASE","approvals":null,"comments":null,"files":null,"sizeInsertions":4,"sizeDeletions":-4},"change":{"project":"Frobozz","branch":"my-feature","topic":null,"id":"6","number":88335,"subject":"This is a subject","owner":{"name":"Philip J. Fry","email":"[email protected]","username":"philipjfry"},"assignee":null,"url":"http://www.example.com/v5Txc","commitMessage":"Made some changes","createdOn":null,"lastUpdated":null,"open":null,"status":"NEW","comments":null,"trackingIds":null,"currentPatchSet":null,"patchSets":null,"dependsOn":null,"neededBy":null,"submitRecords":null,"allReviewers":null},"type":"comment-added","eventCreatedOn":1501530774}

0 comments on commit f48bf2c

Please sign in to comment.