Skip to content

Fix the first contributor filter #891

@orhun

Description

@orhun

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

In the following scenario:

  1. User foo contributes for the first time.
  2. New release is created and changelog is generated.
  3. User foo contributes after the release.
  4. New release is created and changelog is generated BUT user foo is removed from the first contributors section from the previous release.

Might be related to #825

Steps To Reproduce

See above.

Expected behavior

This happens due to not checking the dates of the new commits while updating the release metadata.

// mark contributors as first-time
self.$remote.contributors = contributors
.into_iter()
.map(|mut v| {
v.is_first_time = !commits
.iter()
.map(|v| v.username())
.any(|login| login == v.username);
v
})
.collect();

Here, we check all the commits, but you see, in the new release user foo already contributed, so his contribution is not marked as first time anymore.

To fix it, we should simply:

diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs
index 77d14e7..32e61a9 100644
--- a/git-cliff-core/src/remote/mod.rs
+++ b/git-cliff-core/src/remote/mod.rs
@@ -83,6 +83,8 @@ pub trait RemoteCommit: DynClone {
 	fn id(&self) -> String;
 	/// Commit author.
 	fn username(&self) -> Option<String>;
+	/// Timestamp.
+	fn timestamp(&self) -> Option<i64>;
 }
 
 dyn_clone::clone_trait_object!(RemoteCommit);
@@ -340,6 +342,9 @@ macro_rules! update_release_metadata {
 					.map(|mut v| {
 						v.is_first_time = !commits
 							.iter()
+							.filter(|commit| {
+								commit.timestamp() < Some(self.timestamp)
+							})
 							.map(|v| v.username())
 							.any(|login| login == v.username);
 						v

Apply the patch above and you will see that we are missing the implementation for GitHub, GitLab, etc. We need to check each remote and add the appropriate field for serializing the timestamp from their API response.

Screenshots / Logs

nA

Software information

nA

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededintegrationRelated to remote integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions