@@ -180,7 +180,9 @@ func TestShouldIncludeForGeneration(t *testing.T) {
180180}
181181
182182func TestGetConventionalCommitsSinceLastRelease (t * testing.T ) {
183+
183184 t .Parallel ()
185+
184186 pathAndMessages := []pathAndMessage {
185187 {
186188 path : "foo/a.txt" ,
@@ -202,8 +204,46 @@ func TestGetConventionalCommitsSinceLastRelease(t *testing.T) {
202204 path : "foo/c.txt" ,
203205 message : "feat(foo): another feature for foo" ,
204206 },
207+ {
208+ path : "foo/something.txt" ,
209+ message : `BEGIN_COMMIT_OVERRIDE
210+
211+ BEGIN_NESTED_COMMIT
212+ fix: a bug1 fix
213+
214+ This is another body.
215+
216+ PiperOrigin-RevId: 573342
217+ Library-IDs: foo
218+ Source-link: [googleapis/googleapis@fedcba0](https://github.com/googleapis/googleapis/commit/fedcba0)
219+ END_NESTED_COMMIT
220+
221+ BEGIN_NESTED_COMMIT
222+ fix: a bug2 fix
223+
224+ This is another body.
225+
226+ PiperOrigin-RevId: 573342
227+ Library-IDs: bar
228+ Source-link: [googleapis/googleapis@fedcba0](https://github.com/googleapis/googleapis/commit/fedcba0)
229+ END_NESTED_COMMIT
230+
231+ BEGIN_NESTED_COMMIT
232+ fix: a bug3 fix
233+
234+ This is another body.
235+
236+ PiperOrigin-RevId: 573342
237+ Library-IDs: foo, bar
238+ Source-link: [googleapis/googleapis@fedcba0](https://github.com/googleapis/googleapis/commit/fedcba0)
239+ END_NESTED_COMMIT
240+
241+ END_COMMIT_OVERRIDE` ,
242+ },
205243 }
244+
206245 repoWithCommits := setupRepoForGetCommits (t , pathAndMessages , []string {"foo-v1.0.0" })
246+
207247 for _ , test := range []struct {
208248 name string
209249 repo gitrepo.Repository
@@ -223,6 +263,28 @@ func TestGetConventionalCommitsSinceLastRelease(t *testing.T) {
223263 ReleaseExcludePaths : []string {"foo/README.md" },
224264 },
225265 want : []* conventionalcommits.ConventionalCommit {
266+ {
267+ Type : "fix" ,
268+ Subject : "a bug1 fix" ,
269+ LibraryID : "foo" ,
270+ Footers : map [string ]string {
271+ "PiperOrigin-RevId" : "573342" ,
272+ "Library-IDs" : "foo" ,
273+ "Source-link" : "[googleapis/googleapis@fedcba0](https://github.com/googleapis/googleapis/commit/fedcba0)" ,
274+ },
275+ IsNested : true ,
276+ },
277+ {
278+ Type : "fix" ,
279+ Subject : "a bug3 fix" ,
280+ LibraryID : "foo" ,
281+ Footers : map [string ]string {
282+ "PiperOrigin-RevId" : "573342" ,
283+ "Library-IDs" : "foo, bar" ,
284+ "Source-link" : "[googleapis/googleapis@fedcba0](https://github.com/googleapis/googleapis/commit/fedcba0)" ,
285+ },
286+ IsNested : true ,
287+ },
226288 {
227289 Type : "feat" ,
228290 Scope : "foo" ,
@@ -574,3 +636,75 @@ func TestNextVersion(t *testing.T) {
574636 })
575637 }
576638}
639+
640+ func TestLibraryFilter (t * testing.T ) {
641+ t .Parallel ()
642+ commits := []* conventionalcommits.ConventionalCommit {
643+ {
644+ LibraryID : "foo" ,
645+ Footers : map [string ]string {},
646+ },
647+ {
648+ LibraryID : "bar" ,
649+ Footers : map [string ]string {},
650+ },
651+ {
652+ Footers : map [string ]string {
653+ "Library-IDs" : "foo" ,
654+ },
655+ },
656+ {
657+ Footers : map [string ]string {
658+ "Library-IDs" : "bar" ,
659+ },
660+ },
661+ {
662+ Footers : map [string ]string {
663+ "Library-IDs" : "foo, bar" ,
664+ },
665+ },
666+ {
667+ Footers : map [string ]string {
668+ "Library-IDs" : "foo,bar" ,
669+ },
670+ },
671+ }
672+ for _ , test := range []struct {
673+ name string
674+ libraryID string
675+ want []* conventionalcommits.ConventionalCommit
676+ }{
677+ {
678+ name : "filter by foo" ,
679+ libraryID : "foo" ,
680+ want : []* conventionalcommits.ConventionalCommit {
681+ commits [0 ],
682+ commits [2 ],
683+ commits [4 ],
684+ commits [5 ],
685+ },
686+ },
687+ {
688+ name : "filter by bar" ,
689+ libraryID : "bar" ,
690+ want : []* conventionalcommits.ConventionalCommit {
691+ commits [1 ],
692+ commits [3 ],
693+ commits [4 ],
694+ commits [5 ],
695+ },
696+ },
697+ {
698+ name : "filter by baz" ,
699+ libraryID : "baz" ,
700+ want : nil ,
701+ },
702+ } {
703+ t .Run (test .name , func (t * testing.T ) {
704+ got := libraryFilter (commits , test .libraryID )
705+ if diff := cmp .Diff (test .want , got ); diff != "" {
706+ t .Errorf ("libraryFilter() mismatch (-want +got):\n %s" , diff )
707+ }
708+ })
709+ }
710+ }
0 commit comments