git-release 0.1.1

Set the release information based on all commits of a tag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
use crate::common_test::new_commit;
use crate::workspace::commit::Reference;
use crate::workspace::commit::{Commit, Verb};

#[cfg(test)]
mod title {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn message_is_one_line() -> Result<(), Box<dyn std::error::Error>> {
        let title = "this is a title";
        let body = format!("{title}\n\nThis is the body");
        let (repo, oid) = new_commit("filename", &body)?;
        let commit: Commit = repo.find_commit(oid)?.into();
        let res = commit.title().ok_or("no title")?;
        assert_eq!(title, res);
        Ok(())
    }
}

#[cfg(test)]
mod verb {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn no_verbs() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "nothing is here",
            "(and): so this one",
            "title\n\nignore: this",
        ];
        for body in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            let res = commit.verb();
            assert_eq!(Verb::Misc, res, "{body}");
        }
        Ok(())
    }

    #[test]
    fn verb_with_no_section() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            ("feat", Verb::Feature),
            ("feature", Verb::Feature),
            ("fix", Verb::Fix),
            ("fixed", Verb::Fix),
            ("fixes", Verb::Fix),
            ("ref", Verb::Refactor),
            ("refactor", Verb::Refactor),
            ("refactored", Verb::Refactor),
            ("chore", Verb::Chore),
            ("enhance", Verb::Enhancements),
            ("enhanced", Verb::Enhancements),
            ("enhancement", Verb::Enhancements),
            ("enhancements", Verb::Enhancements),
            ("improve", Verb::Enhancements),
            ("improved", Verb::Enhancements),
            ("improves", Verb::Enhancements),
            ("improvement", Verb::Enhancements),
            ("improvements", Verb::Enhancements),
            ("style", Verb::Style),
            ("ci", Verb::CI),
            ("CI", Verb::CI),
            ("doc", Verb::Documentation),
            ("docs", Verb::Documentation),
        ];
        for tc in tcs {
            let body = format!("{} something", tc.0);
            let (repo, oid) = new_commit("filename", &body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            let res = commit.verb();
            assert_eq!(tc.1, res, "{}", tc.0);
        }
        Ok(())
    }

    #[test]
    fn verb_with_section() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "(repo) something",
            "(s3) something",
            "(repo): something",
            "(repo,server) something",
            "(s3,server) something",
            "(server,s3) something",
            "(repo, server) something",
            "(s3, server) something",
            "(server, s3) something",
            "(repo.exec): something",
            "(s3.exec): something",
            "(exec.s3): something",
            "(repo-exec): something",
            "(s3-exec): something",
            "(exec-s3): something",
            "(repo_exec): something",
            "(s3_exec): something",
            "(repo exec): something",
            "(s3 exec): something",
            "(repo/exec): something",
            "(s3/exec): something",
            "(exec/s3): something",
            "(server)!: something",
            "!(server): something",
        ];
        for tc in tcs {
            let body = format!("feat{tc}");
            let (repo, oid) = new_commit("filename", &body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            let res = commit.verb();
            assert_eq!(Verb::Feature, res);
        }
        Ok(())
    }
}

#[cfg(test)]
mod references {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn no_references() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "feat(commit): this is a title",
            "feat(commit): 123 this is a title",
            "feat(commit): #,123 this is a title",
            "feat(commit): # 123 this is a title",
            "feat(commit): #-123 this is a title",
            "feat(commit): #a123 this is a title",
        ];
        for body in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert_eq!(Vec::<Reference>::new(), commit.references(), "{body}");
        }
        Ok(())
    }

    #[test]
    fn in_summary() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat(commit): this links to #123\n\nSomething is here";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();
        assert_eq!(vec![Reference(123)], commit.references(), "{body}");
        Ok(())
    }

    #[test]
    fn in_start_of_line() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat:something 23\n\n#123: is the ref";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();
        assert_eq!(vec![Reference(123)], commit.references(), "{body}");
        Ok(())
    }

    #[test]
    fn at_the_end_of_line() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat:something 23\n\nRef #123";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();
        assert_eq!(vec![Reference(123)], commit.references());
        Ok(())
    }

    #[test]
    fn multiple_refs_in_line() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat:something 23\n\nRef #123, Close #456";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();
        assert_eq!(vec![Reference(123), Reference(456)], commit.references());
        Ok(())
    }
}

#[cfg(test)]
mod subjects {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn no_subject() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "something",
            "ref something",
            "ref(): something",
            "ref: something",
            "ref: (something)",
            "ref: (something): something",
        ];
        for body in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            let subjects = commit.subjects();
            assert!(subjects.is_none(), "{body} -> {:?}", subjects.unwrap());
        }
        Ok(())
    }

    #[test]
    fn subjects() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            ("ref(repo): something", vec!["repo"]),
            ("ref(Repo): something", vec!["Repo"]),
            ("ref (repo): something", vec!["repo"]),
            ("ref (repo) : something", vec!["repo"]),
            ("ref ( repo ) : something", vec!["repo"]),
            ("ref(repo,server): something", vec!["repo", "server"]),
            ("ref(repo, server): something", vec!["repo", "server"]),
            ("ref(repo ,server): something", vec!["repo", "server"]),
            ("ref(repo server): something", vec!["repo server"]),
            ("ref(repo.server): something", vec!["repo.server"]),
            ("ref(repo .server): something", vec!["repo .server"]),
            ("ref(repo. server): something", vec!["repo. server"]),
            ("ref(repo-server): something", vec!["repo-server"]),
            ("ref(repo -server): something", vec!["repo -server"]),
            ("ref(repo- server): something", vec!["repo- server"]),
            ("ref(repo - server): something", vec!["repo - server"]),
            ("ref(repo_server): something", vec!["repo_server"]),
            ("ref(repo _server): something", vec!["repo _server"]),
            ("ref(repo_ server): something", vec!["repo_ server"]),
            ("ref(repo _ server): something", vec!["repo _ server"]),
            ("ref(repo/server): something", vec!["repo/server"]),
            (
                "ref(repo server, repo): something",
                vec!["repo server", "repo"],
            ),
        ];
        for (body, want) in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            let subjects = commit.subjects();
            assert!(subjects.is_some(), "{body}");
            assert_eq!(&subjects.unwrap(), &want);
        }
        Ok(())
    }
}

#[cfg(test)]
mod is_breaking {
    use super::*;

    #[test]
    fn not_breaking() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "ref: something 23\n\nRef #123, Close #456",
            "ref: !something 23\n\nRef #123, Close #456",
            "ref(repo): something 23\n\nRef #123, Close #456",
            "ref(repo): something 23\n\nRef #123!, Close #456",
        ];
        for body in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert!(!commit.is_breaking(), "{body}");
        }
        Ok(())
    }

    #[test]
    fn in_title() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "ref!: something 23\n\nRef #123, Close #456",
            "ref(repo)!: something 23\n\nRef #123, Close #456",
            "ref!(repo): something 23\n\nRef #123, Close #456",
        ];
        for body in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert!(commit.is_breaking(), "{body}");
        }
        Ok(())
    }

    #[test]
    fn in_footer() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            "ref(repo): this is a new api\n\nBREAKING CHANGE: this is a changed api",
            "ref(repo): this is a new api\n\nSomething.\nBREAKING CHANGE: this is a changed api",
        ];
        for body in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert!(commit.is_breaking(), "{body}");
        }
        Ok(())
    }
}

#[cfg(test)]
mod display_fmt {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn just_title() -> Result<(), Box<dyn std::error::Error>> {
        let body = "this is a test\n\nBody.\n\nFooter";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();

        let want = "This is a test";
        assert_eq!(want, format!("{commit}"));

        Ok(())
    }

    #[test]
    fn with_verb() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat: this is a test\n\nBody.\n\nFooter";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();
        let want = "This is a test";
        assert_eq!(want, format!("{commit}"));

        Ok(())
    }

    #[test]
    fn with_subjects() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat(repo, server): this is a test\n\nBody.\n\nFooter";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();

        let want = "**repo, server:** This is a test";
        assert_eq!(want, format!("{commit}"));

        Ok(())
    }

    #[test]
    fn with_breaking_in_summary() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat!: this is a test\n\nBody.\n\nFooter";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();

        let want = "This is a test [**BREAKING CHANGE**]";
        assert_eq!(want, format!("{commit}"));

        Ok(())
    }

    #[test]
    fn with_breaking_in_footer() -> Result<(), Box<dyn std::error::Error>> {
        let body = "feat: this is a test\n\nBody.\n\nBREAKING CHANGE: there was a change";
        let (repo, oid) = new_commit("filename", body)?;
        let commit: Commit = repo.find_commit(oid)?.into();

        let want = "This is a test [**BREAKING CHANGE**]";
        assert_eq!(want, format!("{commit}"));

        Ok(())
    }

    #[test]
    fn issue_in_summary() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            ("title ref #123", "Title (ref #123)"),
            ("title (ref #123)", "Title (ref #123)"),
            ("title close #123", "Title (ref #123)"),
            ("title close #123 ref #456", "Title (ref #123, ref #456)"),
        ];
        for (body, want) in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert_eq!(want, format!("{commit}"));
        }

        Ok(())
    }

    #[test]
    fn issue_in_body() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            ("title\n\nbody ref #123", "Title (ref #123)"),
            ("title\n\nbody (ref #123)", "Title (ref #123)"),
            ("title\n\nbody close #123", "Title (ref #123)"),
            (
                "title\n\nbody close #123 and ref #456",
                "Title (ref #123, ref #456)",
            ),
        ];
        for (body, want) in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert_eq!(want, format!("{commit}"));
        }

        Ok(())
    }

    #[test]
    fn issue_in_footer() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            ("title\n\nbody\n\n ref #123", "Title (ref #123)"),
            ("title\n\nbody\n\n (ref #123)", "Title (ref #123)"),
            ("title\n\nbody\n\n close #123", "Title (ref #123)"),
            (
                "title\n\nbody\n\n close #123 and ref #456",
                "Title (ref #123, ref #456)",
            ),
        ];
        for (body, want) in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert_eq!(want, format!("{commit}"));
        }

        Ok(())
    }

    #[test]
    fn issue_in_all_places() -> Result<(), Box<dyn std::error::Error>> {
        let tcs = vec![
            (
                "title ref #11\n\nbody ref #22.\n\nref #33",
                "Title (ref #11, ref #22, ref #33)",
            ),
            (
                "title (ref #11)\n\nbody (ref #22).\n\n(ref #33)",
                "Title (ref #11, ref #22, ref #33)",
            ),
            (
                "title ref #11\n\nbody ref #22.\nanother ref #33\n\nref #44",
                "Title (ref #11, ref #22, ref #33, ref #44)",
            ),
        ];
        for (body, want) in tcs {
            let (repo, oid) = new_commit("filename", body)?;
            let commit: Commit = repo.find_commit(oid)?.into();
            assert_eq!(want, format!("{commit}"));
        }

        Ok(())
    }
}