-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the first contributor filter #891
Comments
Hi @orhun can i work on this? |
please do! @jaiakash |
I tested the suggested fix on And something isn't quite correct in the logic, it repots ## What's Changed
* feat(config): support multiple file formats by @orhun <[email protected]>
* feat(cache): use cache while fetching pages by @orhun <[email protected]>
* feat(ci): add pipeline config by @mcwarman <[email protected]> in #1
### New Contributors
* @mcwarman <[email protected]> made their first contribution in [#1](https://bitbucket.org/mcwarman-playground/git-cliff-readme-example/pull-requests/1)
* @orhun <[email protected]> made their first contribution
## What's Changed in v1.0.1
* refactor(parser): expose string functions by @orhun <[email protected]>
* chore(release): add release script by @orhun <[email protected]>
## What's Changed in v1.0.0
* Initial commit by @orhun <[email protected]>
* docs(project): add README.md by @orhun <[email protected]>
* feat(parser): add ability to parse arrays by @orhun <[email protected]>
* fix(args): rename help argument due to conflict by @orhun <[email protected]>
* docs(example)!: add tested usage example by @orhun <[email protected]>
### New Contributors
* @orhun <[email protected]> made their first contribution
<!-- generated by -cliff --> diff --git a/git-cliff-core/src/remote/bitbucket.rs b/git-cliff-core/src/remote/bitbucket.rs
index a3e3603..26ef85a 100644
--- a/git-cliff-core/src/remote/bitbucket.rs
+++ b/git-cliff-core/src/remote/bitbucket.rs
@@ -1,5 +1,6 @@
use crate::config::Remote;
use crate::error::*;
+use chrono::DateTime;
use reqwest_middleware::ClientWithMiddleware;
use serde::{
Deserialize,
@@ -33,6 +34,8 @@ pub(crate) const BITBUCKET_MAX_PAGE_PRS: usize = 50;
pub struct BitbucketCommit {
/// SHA.
pub hash: String,
+ /// SHA.
+ pub date: String,
/// Author of the commit.
pub author: Option<BitbucketCommitAuthor>,
}
@@ -45,6 +48,15 @@ impl RemoteCommit for BitbucketCommit {
fn username(&self) -> Option<String> {
self.author.clone().and_then(|v| v.login)
}
+
+ fn timestamp(&self) -> Option<i64> {
+ debug!("{} {}", self.hash.clone(), self.date.clone());
+ Some(
+ DateTime::parse_from_rfc3339(&self.date)
+ .unwrap()
+ .timestamp(),
+ )
+ }
} diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs
index a79137b..d4a9681 100644
--- a/git-cliff-core/src/remote/mod.rs
+++ b/git-cliff-core/src/remote/mod.rs
@@ -82,6 +82,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);
@@ -342,6 +344,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 |
I guess we still need to check the past releases... the logic here boggles my mind a bit.
🤔 |
I now understand this a little bit more after some debugging. |
Not sure if something like this works: .filter(|commit| {
//unreleased
self.timestamp == 0 ||
commit.timestamp() < Some(self.timestamp)
}) |
Yes, I think something like that might work. Are you getting the correct results with it? |
For the Bitbucket it was, but possibly more by the luck The approach isn't flawless, because I realised |
Hmm I see.. Either way, can you create a PR with your changes? I think anything that gets us to a more accurate result is welcome :) |
Also I just updated the issue labels. This turned out to be more difficult than I expected. I'm still not sure about the logic above. |
I think this works:
diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs
index a79137b..d83fe28 100644
--- a/git-cliff-core/src/remote/mod.rs
+++ b/git-cliff-core/src/remote/mod.rs
@@ -82,6 +82,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);
@@ -299,6 +301,7 @@ macro_rules! update_release_metadata {
pull_requests: Vec<Box<dyn RemotePullRequest>>,
) -> Result<()> {
let mut contributors: Vec<RemoteContributor> = Vec::new();
+ let mut release_commit_timestamp: Option<i64> = None;
// retain the commits that are not a part of this release for later
// on checking the first contributors.
commits.retain(|v| {
@@ -331,6 +334,11 @@ macro_rules! update_release_metadata {
});
}
commit.remote = Some(commit.$remote.clone());
+ // if remote commit is the release commit store timestamp for
+ // use in calculation of first time
+ if Some(v.id().clone()) == self.commit_id {
+ release_commit_timestamp = v.timestamp().clone();
+ }
false
} else {
true
@@ -342,6 +350,12 @@ macro_rules! update_release_metadata {
.map(|mut v| {
v.is_first_time = !commits
.iter()
+ .filter(|commit| {
+ // if current release is unreleased no need to filter
+ // commits or filter commits that are from
+ // newer releases
+ self.timestamp == 0 ||
+ commit.timestamp() < release_commit_timestamp
+ })
.map(|v| v.username())
.any(|login| login == v.username);
v Although to make it work bitbucket I had to override the endpoint because of #906 ## What's Changed
* feat(config): support multiple file formats by @orhun <[email protected]>
* feat(cache): use cache while fetching pages by @orhun <[email protected]>
* feat(ci): add pipeline config by @mcwarman <[email protected]> in #1
### New Contributors
* @mcwarman <[email protected]> made their first contribution in [#1](https://bitbucket.org/mcwarman-playground/git-cliff-readme-example/pull-requests/1)
## What's Changed in v1.0.1
* refactor(parser): expose string functions by @orhun <[email protected]>
* chore(release): add release script by @orhun <[email protected]>
## What's Changed in v1.0.0
* Initial commit by @orhun <[email protected]>
* docs(project): add README.md by @orhun <[email protected]>
* feat(parser): add ability to parse arrays by @orhun <[email protected]>
* fix(args): rename help argument due to conflict by @orhun <[email protected]>
* docs(example)!: add tested usage example by @orhun <[email protected]>
### New Contributors
* @orhun <[email protected]> made their first contribution
<!-- generated by -cliff --> |
Is there an existing issue for this?
Description of the bug
In the following scenario:
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.
git-cliff/git-cliff-core/src/remote/mod.rs
Lines 337 to 347 in 8d10edb
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:
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
The text was updated successfully, but these errors were encountered: