-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
release.rs
923 lines (898 loc) · 26.9 KB
/
release.rs
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
use crate::commit::Commit;
use crate::config::Bump;
use crate::error::Result;
#[cfg(any(feature = "github", feature = "gitlab", feature = "bitbucket"))]
use crate::remote::{
RemoteCommit,
RemoteContributor,
RemotePullRequest,
RemoteReleaseMetadata,
};
use next_version::VersionUpdater;
use semver::Version;
use serde::{
Deserialize,
Serialize,
};
/// Representation of a release.
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Release<'a> {
/// Release version, git tag.
pub version: Option<String>,
/// Commits made for the release.
pub commits: Vec<Commit<'a>>,
/// Commit ID of the tag.
#[serde(rename = "commit_id")]
pub commit_id: Option<String>,
/// Timestamp of the release in seconds, from epoch.
pub timestamp: i64,
/// Previous release.
pub previous: Option<Box<Release<'a>>>,
/// Contributors.
#[cfg(feature = "github")]
pub github: RemoteReleaseMetadata,
/// Contributors.
#[cfg(feature = "gitlab")]
pub gitlab: RemoteReleaseMetadata,
/// Contributors.
#[cfg(feature = "bitbucket")]
pub bitbucket: RemoteReleaseMetadata,
}
#[cfg(feature = "github")]
crate::update_release_metadata!(github, update_github_metadata);
#[cfg(feature = "gitlab")]
crate::update_release_metadata!(gitlab, update_gitlab_metadata);
#[cfg(feature = "bitbucket")]
crate::update_release_metadata!(bitbucket, update_bitbucket_metadata);
impl<'a> Release<'a> {
/// Calculates the next version based on the commits.
///
/// It uses the default bump version configuration to calculate the next
/// version.
pub fn calculate_next_version(&self) -> Result<String> {
self.calculate_next_version_with_config(&Bump::default())
}
/// Calculates the next version based on the commits.
///
/// It uses the given bump version configuration to calculate the next
/// version.
pub(super) fn calculate_next_version_with_config(
&self,
config: &Bump,
) -> Result<String> {
match self
.previous
.as_ref()
.and_then(|release| release.version.clone())
{
Some(version) => {
let mut semver = Version::parse(&version);
let mut prefix = None;
if semver.is_err() && version.split('.').count() >= 2 {
let mut found_numeric = false;
for (i, c) in version.chars().enumerate() {
if c.is_numeric() && !found_numeric {
found_numeric = true;
let version_prefix = version[..i].to_string();
let remaining = version[i..].to_string();
let version = Version::parse(&remaining);
if version.is_ok() {
semver = version;
prefix = Some(version_prefix);
break;
}
} else if !c.is_numeric() && found_numeric {
found_numeric = false;
}
}
}
let next_version = VersionUpdater::new()
.with_features_always_increment_minor(
config.features_always_bump_minor.unwrap_or(true),
)
.with_breaking_always_increment_major(
config.breaking_always_bump_major.unwrap_or(true),
)
.increment(
&semver?,
self.commits
.iter()
.map(|commit| commit.message.trim_end().to_string())
.collect::<Vec<String>>(),
)
.to_string();
if let Some(prefix) = prefix {
Ok(format!("{prefix}{next_version}"))
} else {
Ok(next_version)
}
}
None => {
warn!("No releases found, using 0.1.0 as the next version.");
Ok(String::from("0.1.0"))
}
}
}
}
/// Representation of a list of releases.
#[derive(Serialize)]
pub struct Releases<'a> {
/// Releases.
pub releases: &'a Vec<Release<'a>>,
}
impl<'a> Releases<'a> {
/// Returns the list of releases as JSON.
pub fn as_json(&self) -> Result<String> {
Ok(serde_json::to_string(self.releases)?)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn bump_version() -> Result<()> {
fn build_release<'a>(version: &str, commits: &'a [&str]) -> Release<'a> {
Release {
version: None,
commits: commits
.iter()
.map(|v| Commit::from(v.to_string()))
.collect(),
commit_id: None,
timestamp: 0,
previous: Some(Box::new(Release {
version: Some(String::from(version)),
..Default::default()
})),
#[cfg(feature = "github")]
github: crate::remote::RemoteReleaseMetadata {
contributors: vec![],
},
#[cfg(feature = "gitlab")]
gitlab: crate::remote::RemoteReleaseMetadata {
contributors: vec![],
},
#[cfg(feature = "bitbucket")]
bitbucket: crate::remote::RemoteReleaseMetadata {
contributors: vec![],
},
}
}
let test_shared = [
("1.0.0", "1.1.0", vec!["feat: add xyz", "fix: fix xyz"]),
("1.0.0", "1.0.1", vec!["fix: add xyz", "fix: aaaaaa"]),
("1.0.0", "2.0.0", vec!["feat!: add xyz", "feat: zzz"]),
("1.0.0", "2.0.0", vec!["feat!: add xyz\n", "feat: zzz\n"]),
("2.0.0", "2.0.1", vec!["fix: something"]),
("foo/1.0.0", "foo/1.1.0", vec![
"feat: add xyz",
"fix: fix xyz",
]),
("bar/1.0.0", "bar/2.0.0", vec![
"fix: add xyz",
"fix!: aaaaaa",
]),
("zzz-123/test/1.0.0", "zzz-123/test/1.0.1", vec![
"fix: aaaaaa",
]),
("v100.0.0", "v101.0.0", vec!["feat!: something"]),
("v1.0.0-alpha.1", "v1.0.0-alpha.2", vec!["fix: minor"]),
("testing/v1.0.0-beta.1", "testing/v1.0.0-beta.2", vec![
"feat: nice",
]),
("tauri-v1.5.4", "tauri-v1.6.0", vec!["feat: something"]),
(
"rocket/rocket-v4.0.0-rc.1",
"rocket/rocket-v4.0.0-rc.2",
vec!["chore!: wow"],
),
(
"aaa#/@#$@9384!#%^#@#@!#!239432413-idk-9999.2200.5932-alpha.419",
"aaa#/@#$@9384!#%^#@#@!#!239432413-idk-9999.2200.5932-alpha.420",
vec!["feat: damn this is working"],
),
];
for (version, expected_version, commits) in test_shared.iter().chain(
[
("0.0.1", "0.0.2", vec!["fix: fix xyz"]),
("0.0.1", "0.1.0", vec!["feat: add xyz", "fix: fix xyz"]),
("0.0.1", "1.0.0", vec!["feat!: add xyz", "feat: zzz"]),
("0.1.0", "0.1.1", vec!["fix: fix xyz"]),
("0.1.0", "0.2.0", vec!["feat: add xyz", "fix: fix xyz"]),
("0.1.0", "1.0.0", vec!["feat!: add xyz", "feat: zzz"]),
]
.iter(),
) {
let release = build_release(version, commits);
let next_version = release.calculate_next_version()?;
assert_eq!(expected_version, &next_version);
let next_version =
release.calculate_next_version_with_config(&Bump::default())?;
assert_eq!(expected_version, &next_version);
}
for (version, expected_version, commits) in test_shared.iter().chain(
[
("0.0.1", "0.0.2", vec!["fix: fix xyz"]),
("0.0.1", "0.0.2", vec!["feat: add xyz", "fix: fix xyz"]),
("0.0.1", "0.0.2", vec!["feat!: add xyz", "feat: zzz"]),
("0.1.0", "0.1.1", vec!["fix: fix xyz"]),
("0.1.0", "0.1.1", vec!["feat: add xyz", "fix: fix xyz"]),
("0.1.0", "0.2.0", vec!["feat!: add xyz", "feat: zzz"]),
]
.iter(),
) {
let release = build_release(version, commits);
let next_version =
release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(false),
breaking_always_bump_major: Some(false),
})?;
assert_eq!(expected_version, &next_version);
}
for (version, expected_version, commits) in test_shared.iter().chain(
[
("0.0.1", "0.0.2", vec!["fix: fix xyz"]),
("0.0.1", "0.1.0", vec!["feat: add xyz", "fix: fix xyz"]),
("0.0.1", "0.1.0", vec!["feat!: add xyz", "feat: zzz"]),
("0.1.0", "0.1.1", vec!["fix: fix xyz"]),
("0.1.0", "0.2.0", vec!["feat: add xyz", "fix: fix xyz"]),
("0.1.0", "0.2.0", vec!["feat!: add xyz", "feat: zzz"]),
]
.iter(),
) {
let release = build_release(version, commits);
let next_version =
release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(true),
breaking_always_bump_major: Some(false),
})?;
assert_eq!(expected_version, &next_version);
}
for (version, expected_version, commits) in test_shared.iter().chain(
[
("0.0.1", "0.0.2", vec!["fix: fix xyz"]),
("0.0.1", "0.0.2", vec!["feat: add xyz", "fix: fix xyz"]),
("0.0.1", "1.0.0", vec!["feat!: add xyz", "feat: zzz"]),
("0.1.0", "0.1.1", vec!["fix: fix xyz"]),
("0.1.0", "0.1.1", vec!["feat: add xyz", "fix: fix xyz"]),
("0.1.0", "1.0.0", vec!["feat!: add xyz", "feat: zzz"]),
]
.iter(),
) {
let release = build_release(version, commits);
let next_version =
release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(false),
breaking_always_bump_major: Some(true),
})?;
assert_eq!(expected_version, &next_version);
}
let empty_release = Release {
previous: Some(Box::new(Release {
version: None,
..Default::default()
})),
..Default::default()
};
assert_eq!("0.1.0", empty_release.calculate_next_version()?);
for (features_always_bump_minor, breaking_always_bump_major) in
[(true, true), (true, false), (false, true), (false, false)]
{
assert_eq!(
"0.1.0",
empty_release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(features_always_bump_minor),
breaking_always_bump_major: Some(breaking_always_bump_major),
})?
);
}
Ok(())
}
#[cfg(feature = "github")]
#[test]
fn update_github_metadata() -> Result<()> {
use crate::remote::github::{
GitHubCommit,
GitHubCommitAuthor,
GitHubPullRequest,
PullRequestLabel,
};
let mut release = Release {
version: None,
commits: vec![
Commit::from(String::from(
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071 add github \
integration",
)),
Commit::from(String::from(
"21f6aa587fcb772de13f2fde0e92697c51f84162 fix github \
integration",
)),
Commit::from(String::from(
"35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973 update metadata",
)),
Commit::from(String::from(
"4d3ffe4753b923f4d7807c490e650e6624a12074 do some stuff",
)),
Commit::from(String::from(
"5a55e92e5a62dc5bf9872ffb2566959fad98bd05 alright",
)),
Commit::from(String::from(
"6c34967147560ea09658776d4901709139b4ad66 should be fine",
)),
],
commit_id: None,
timestamp: 0,
previous: Some(Box::new(Release {
version: Some(String::from("1.0.0")),
..Default::default()
})),
github: RemoteReleaseMetadata {
contributors: vec![],
},
gitlab: RemoteReleaseMetadata {
contributors: vec![],
},
bitbucket: RemoteReleaseMetadata {
contributors: vec![],
},
};
release.update_github_metadata(
vec![
GitHubCommit {
sha: String::from("1d244937ee6ceb8e0314a4a201ba93a7a61f2071"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("orhun")),
}),
},
GitHubCommit {
sha: String::from("21f6aa587fcb772de13f2fde0e92697c51f84162"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("orhun")),
}),
},
GitHubCommit {
sha: String::from("35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("nuhro")),
}),
},
GitHubCommit {
sha: String::from("4d3ffe4753b923f4d7807c490e650e6624a12074"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("awesome_contributor")),
}),
},
GitHubCommit {
sha: String::from("5a55e92e5a62dc5bf9872ffb2566959fad98bd05"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("orhun")),
}),
},
GitHubCommit {
sha: String::from("6c34967147560ea09658776d4901709139b4ad66"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("someone")),
}),
},
GitHubCommit {
sha: String::from("0c34967147560e809658776d4901709139b4ad68"),
author: Some(GitHubCommitAuthor {
login: Some(String::from("idk")),
}),
},
GitHubCommit {
sha: String::from("kk34967147560e809658776d4901709139b4ad68"),
author: None,
},
GitHubCommit {
sha: String::new(),
author: None,
},
]
.into_iter()
.map(|v| Box::new(v) as Box<dyn RemoteCommit>)
.collect(),
vec![
GitHubPullRequest {
title: Some(String::from("1")),
number: 42,
merge_commit_sha: Some(String::from(
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071",
)),
labels: vec![PullRequestLabel {
name: String::from("rust"),
}],
},
GitHubPullRequest {
title: Some(String::from("2")),
number: 66,
merge_commit_sha: Some(String::from(
"21f6aa587fcb772de13f2fde0e92697c51f84162",
)),
labels: vec![PullRequestLabel {
name: String::from("rust"),
}],
},
GitHubPullRequest {
title: Some(String::from("3")),
number: 53,
merge_commit_sha: Some(String::from(
"35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973",
)),
labels: vec![PullRequestLabel {
name: String::from("deps"),
}],
},
GitHubPullRequest {
title: Some(String::from("4")),
number: 1000,
merge_commit_sha: Some(String::from(
"4d3ffe4753b923f4d7807c490e650e6624a12074",
)),
labels: vec![PullRequestLabel {
name: String::from("deps"),
}],
},
GitHubPullRequest {
title: Some(String::from("5")),
number: 999999,
merge_commit_sha: Some(String::from(
"5a55e92e5a62dc5bf9872ffb2566959fad98bd05",
)),
labels: vec![PullRequestLabel {
name: String::from("github"),
}],
},
]
.into_iter()
.map(|v| Box::new(v) as Box<dyn RemotePullRequest>)
.collect(),
)?;
let expected_commits = vec![
Commit {
id: String::from("1d244937ee6ceb8e0314a4a201ba93a7a61f2071"),
message: String::from("add github integration"),
github: RemoteContributor {
username: Some(String::from("orhun")),
pr_title: Some(String::from("1")),
pr_number: Some(42),
pr_labels: vec![String::from("rust")],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("21f6aa587fcb772de13f2fde0e92697c51f84162"),
message: String::from("fix github integration"),
github: RemoteContributor {
username: Some(String::from("orhun")),
pr_title: Some(String::from("2")),
pr_number: Some(66),
pr_labels: vec![String::from("rust")],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973"),
message: String::from("update metadata"),
github: RemoteContributor {
username: Some(String::from("nuhro")),
pr_title: Some(String::from("3")),
pr_number: Some(53),
pr_labels: vec![String::from("deps")],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("4d3ffe4753b923f4d7807c490e650e6624a12074"),
message: String::from("do some stuff"),
github: RemoteContributor {
username: Some(String::from("awesome_contributor")),
pr_title: Some(String::from("4")),
pr_number: Some(1000),
pr_labels: vec![String::from("deps")],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("5a55e92e5a62dc5bf9872ffb2566959fad98bd05"),
message: String::from("alright"),
github: RemoteContributor {
username: Some(String::from("orhun")),
pr_title: Some(String::from("5")),
pr_number: Some(999999),
pr_labels: vec![String::from("github")],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("6c34967147560ea09658776d4901709139b4ad66"),
message: String::from("should be fine"),
github: RemoteContributor {
username: Some(String::from("someone")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: false,
},
..Default::default()
},
];
assert_eq!(expected_commits, release.commits);
release
.github
.contributors
.sort_by(|a, b| a.pr_number.cmp(&b.pr_number));
let expected_metadata = RemoteReleaseMetadata {
contributors: vec![
RemoteContributor {
username: Some(String::from("someone")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: true,
},
RemoteContributor {
username: Some(String::from("orhun")),
pr_title: Some(String::from("1")),
pr_number: Some(42),
pr_labels: vec![String::from("rust")],
is_first_time: true,
},
RemoteContributor {
username: Some(String::from("nuhro")),
pr_title: Some(String::from("3")),
pr_number: Some(53),
pr_labels: vec![String::from("deps")],
is_first_time: true,
},
RemoteContributor {
username: Some(String::from("awesome_contributor")),
pr_title: Some(String::from("4")),
pr_number: Some(1000),
pr_labels: vec![String::from("deps")],
is_first_time: true,
},
],
};
assert_eq!(expected_metadata, release.github);
Ok(())
}
#[cfg(feature = "gitlab")]
#[test]
fn update_gitlab_metadata() -> Result<()> {
use crate::remote::gitlab::{
GitLabCommit,
GitLabMergeRequest,
GitLabUser,
};
let mut release = Release {
version: None,
commits: vec![
Commit::from(String::from(
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071 add github \
integration",
)),
Commit::from(String::from(
"21f6aa587fcb772de13f2fde0e92697c51f84162 fix github \
integration",
)),
Commit::from(String::from(
"35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973 update metadata",
)),
Commit::from(String::from(
"4d3ffe4753b923f4d7807c490e650e6624a12074 do some stuff",
)),
Commit::from(String::from(
"5a55e92e5a62dc5bf9872ffb2566959fad98bd05 alright",
)),
Commit::from(String::from(
"6c34967147560ea09658776d4901709139b4ad66 should be fine",
)),
],
commit_id: None,
timestamp: 0,
previous: Some(Box::new(Release {
version: Some(String::from("1.0.0")),
..Default::default()
})),
github: RemoteReleaseMetadata {
contributors: vec![],
},
gitlab: RemoteReleaseMetadata {
contributors: vec![],
},
bitbucket: RemoteReleaseMetadata {
contributors: vec![],
},
};
release.update_gitlab_metadata(
vec![
GitLabCommit {
id: String::from(
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071",
),
author_name: String::from("orhun"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"21f6aa587fcb772de13f2fde0e92697c51f84162",
),
author_name: String::from("orhun"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973",
),
author_name: String::from("nuhro"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"4d3ffe4753b923f4d7807c490e650e6624a12074",
),
author_name: String::from("awesome_contributor"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"5a55e92e5a62dc5bf9872ffb2566959fad98bd05",
),
author_name: String::from("orhun"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"6c34967147560ea09658776d4901709139b4ad66",
),
author_name: String::from("someone"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"0c34967147560e809658776d4901709139b4ad68",
),
author_name: String::from("idk"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
GitLabCommit {
id: String::from(
"kk34967147560e809658776d4901709139b4ad68",
),
author_name: String::from("orhun"),
short_id: String::from(""),
title: String::from(""),
author_email: String::from(""),
authored_date: String::from(""),
committer_name: String::from(""),
committer_email: String::from(""),
committed_date: String::from(""),
created_at: String::from(""),
message: String::from(""),
parent_ids: vec![],
web_url: String::from(""),
},
]
.into_iter()
.map(|v| Box::new(v) as Box<dyn RemoteCommit>)
.collect(),
vec![Box::new(GitLabMergeRequest {
title: String::from("1"),
merge_commit_sha: Some(String::from(
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071",
)),
id: 1,
iid: 1,
project_id: 1,
description: String::from(""),
state: String::from(""),
created_at: String::from(""),
author: GitLabUser {
id: 1,
name: String::from("42"),
username: String::from("42"),
state: String::from("42"),
avatar_url: None,
web_url: String::from("42"),
},
sha: String::from(
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071",
),
web_url: String::from(""),
squash_commit_sha: None,
labels: vec![String::from("rust")],
})],
)?;
let expected_commits = vec![
Commit {
id: String::from("1d244937ee6ceb8e0314a4a201ba93a7a61f2071"),
message: String::from("add github integration"),
gitlab: RemoteContributor {
username: Some(String::from("orhun")),
pr_title: Some(String::from("1")),
pr_number: Some(1),
pr_labels: vec![String::from("rust")],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("21f6aa587fcb772de13f2fde0e92697c51f84162"),
message: String::from("fix github integration"),
gitlab: RemoteContributor {
username: Some(String::from("orhun")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973"),
message: String::from("update metadata"),
gitlab: RemoteContributor {
username: Some(String::from("nuhro")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("4d3ffe4753b923f4d7807c490e650e6624a12074"),
message: String::from("do some stuff"),
gitlab: RemoteContributor {
username: Some(String::from("awesome_contributor")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("5a55e92e5a62dc5bf9872ffb2566959fad98bd05"),
message: String::from("alright"),
gitlab: RemoteContributor {
username: Some(String::from("orhun")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: false,
},
..Default::default()
},
Commit {
id: String::from("6c34967147560ea09658776d4901709139b4ad66"),
message: String::from("should be fine"),
gitlab: RemoteContributor {
username: Some(String::from("someone")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: false,
},
..Default::default()
},
];
assert_eq!(expected_commits, release.commits);
release
.github
.contributors
.sort_by(|a, b| a.pr_number.cmp(&b.pr_number));
let expected_metadata = RemoteReleaseMetadata {
contributors: vec![
RemoteContributor {
username: Some(String::from("orhun")),
pr_title: Some(String::from("1")),
pr_number: Some(1),
pr_labels: vec![String::from("rust")],
is_first_time: false,
},
RemoteContributor {
username: Some(String::from("nuhro")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: true,
},
RemoteContributor {
username: Some(String::from("awesome_contributor")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: true,
},
RemoteContributor {
username: Some(String::from("someone")),
pr_title: None,
pr_number: None,
pr_labels: vec![],
is_first_time: true,
},
],
};
assert_eq!(expected_metadata, release.gitlab);
Ok(())
}
}