Skip to content

Commit b101f8c

Browse files
committed
fix: assign commits to correct release
The algorithm to determine if a commit belongs to a specific release is incorrectly assigning commits to the wrong releases for any release except the first one. It iterates over all commits with an enumerator attached, then skip any commits belonging to previous releases, then skipping the commits belonging to the current release, and finally uses the new enumerator value as the count for the number of commits belonging to the release. This is incorrect, as the enumerator shouldn't start counting until after skipping the commits not belonging to the current release. This is fixed by simplifying the iterator logic to count the relevant commits.
1 parent e7e88b7 commit b101f8c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/changelog/changeset.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,25 @@ impl<'a> ChangeSet<'a> {
5757
}
5858

5959
let idx = match tag {
60-
None => Some(commits.len().checked_sub(1).unwrap_or_default()),
61-
Some(tag) => commits
62-
.iter()
63-
.enumerate()
64-
.skip(offset)
65-
.skip_while(|(_, c)| c.id != tag.commit.id)
66-
.map(|(idx, _)| idx)
67-
.next(),
60+
None => commits.iter().skip(offset).count(),
61+
Some(tag) => {
62+
commits
63+
.iter()
64+
.skip(offset)
65+
.take_while(|c| c.id != tag.commit.id)
66+
.count()
67+
+ 1
68+
}
6869
};
6970

70-
let changes = match idx {
71-
None => return Ok(offset),
72-
Some(idx) => commits
73-
.iter()
74-
.skip(offset)
75-
.take(idx)
76-
.filter_map(|commit| Change::new(&commit).ok())
77-
.collect::<Vec<_>>(),
78-
};
71+
let changes = commits
72+
.iter()
73+
.skip(offset)
74+
.take(idx)
75+
.filter_map(|commit| Change::new(&commit).ok())
76+
.collect::<Vec<_>>();
7977

80-
offset += idx.unwrap_or_default();
78+
offset += idx;
8179

8280
self.changes.append(
8381
&mut changes

0 commit comments

Comments
 (0)