-
-
Notifications
You must be signed in to change notification settings - Fork 235
Fix GitLab Author Metadata: Use username
Instead of author_name
, …
#1186
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
base: main
Are you sure you want to change the base?
Conversation
…Add `author_username` Trait, and Improve Release Metadata Extraction (#1)
Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances pull request metadata by introducing a unified author_username
method across all supported remotes and updating release metadata to leverage it.
- Added
author_username
to theRemotePullRequest
trait with a defaultNone
implementation. - Implemented
author_username
for GitHub, GitLab, and Bitbucket pull request types. - Updated the release metadata macro to use
author_username
and adjusted existing tests for compatibility.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/remote/mod.rs | Added trait method and updated macro to use it. |
src/remote/github.rs | Introduced GitHubPullRequestUser and author_username . |
src/remote/gitlab.rs | Implemented author_username for GitLabMergeRequest. |
src/remote/bitbucket.rs | Implemented author_username for BitbucketPullRequest. |
src/release.rs | Adjusted tests to include new user field. |
Comments suppressed due to low confidence (3)
git-cliff-core/src/remote/github.rs:100
- [nitpick] Consider renaming
GitHubPullRequestUser
toGitHubPullRequestAuthor
(and theuser
field accordingly) to better reflect its role as the PR author and align with other platforms.
pub struct GitHubPullRequestUser {
git-cliff-core/src/remote/gitlab.rs:198
- There are no unit tests verifying that
author_username
returns the expected username for GitLab. Consider adding a test that constructs aGitLabMergeRequest
with a known author.username and asserts the method's output.
fn author_username(&self) -> Option<String> {
git-cliff-core/src/remote/bitbucket.rs:153
- Similarly, add a unit test for
BitbucketPullRequest
to ensureauthor_username
correctly returns theauthor.login
value.
fn author_username(&self) -> Option<String> {
let username = pull_request | ||
.and_then(|pr| pr.author_username()) | ||
.or_else(|| v.username()); | ||
commit.$remote.username = username.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The cloning of username
could be streamlined by directly assigning the Option<String>
rather than calling .clone()
on the final value. For example, bind the result of .or_else(...)
directly to the target field.
commit.$remote.username = username.clone(); | |
commit.$remote.username = username; |
Copilot uses AI. Check for mistakes.
@orhun Hi, I’ve proposed a fix, but this is only my third contribution to a Rust project, so I may need some guidance. I’m a DevOps Engineer rather than a developer, so I apologize in advance if anything is off. :) I’d really appreciate it if you could take a look—and feel free to correct or suggest improvements where needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, is this PR meant to address issue #687?
From my understanding, the root cause seems to be related to deserialization of the GitLab API response. If that's correct, it seems that the current changes might not fully resolve the issue — but please let me know if I misunderstood anything.
@@ -354,7 +358,10 @@ macro_rules! update_release_metadata { | |||
pr.merge_commit() == Some(v.id().clone()) || | |||
pr.merge_commit() == sha_short | |||
}); | |||
commit.$remote.username = v.username(); | |||
let username = pull_request | |||
.and_then(|pr| pr.author_username()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since commit.remote.username is a field intended to represent the commit author, I believe it would be problematic to associate the PR author here if they are different. Linking the PR author as the commit author in this context might lead to confusion or misrepresentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue was that the username
was incorrectly read as author_name
, which resulted in the metadata being absent in most cases. I noticed this when I wondered why it wasn’t returning @username
. I then called the API in the same way as git-cliff
, and in that case, the information was correct. To confirm, I ran a test and compiled with these changes, and voilà—the metadata appeared! There may still be some room for fine-tuning, but the outcome was already much better than before. Therefore, I am confident that this is the root cause of the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely caused by this swap:
"gitlab": {
"username": null,
"pr_title": null,
"pr_number": null,
"pr_labels": [],
"is_first_time": false
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linking the PR author as the commit author in this context might lead to confusion or misrepresentation.
Maybe you’re right! In that case, we can probably use the correct username from the commit—it should also be available there. The main problem is that author_name
can be anything; it is not a unique identifier that can be easily used to match records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the replay.
My original concern was more about the semantic meaning of the commit.remote.username
field. Even if we now retrieve the username
, if that value corresponds to the PR author and not the commit author, I believe it could still lead to incorrect attribution.
git-cliff/git-cliff-core/src/remote/mod.rs
Lines 94 to 95 in 2606366
/// Commit author. | |
fn username(&self) -> Option<String>; |
I'm not sure how this is fixing #687 - can you take a step back and explain the actual problem behind the missing metadata and how this PR is fixing it? |
…Add
author_username
Trait, and Improve Release Metadata Extraction (#1)Description
This pull request introduces support for retrieving the author's username from pull requests across different remote platforms (GitHub, GitLab, and Bitbucket). It also updates the release metadata logic to incorporate this new functionality. Below is a summary of the most important changes:
Enhancements to
RemotePullRequest
Trait:author_username
to theRemotePullRequest
trait, which returns the username of the pull request's author. A default implementation returningNone
is provided for backward compatibility. (git-cliff-core/src/remote/mod.rs
, git-cliff-core/src/remote/mod.rsR118-R121)Platform-Specific Implementations:
GitHub:
GitHubPullRequestUser
to represent the pull request author.GitHubPullRequest
struct to include auser
field of typeOption<GitHubPullRequestUser>
.author_username
method forGitHubPullRequest
to return the author's username. (git-cliff-core/src/remote/github.rs
, [1] [2] [3]GitLab: Implemented the
author_username
method forGitLabMergeRequest
to return the author's username. (git-cliff-core/src/remote/gitlab.rs
, git-cliff-core/src/remote/gitlab.rsR197-R200)Bitbucket: Implemented the
author_username
method forBitbucketPullRequest
to return the author's username. (git-cliff-core/src/remote/bitbucket.rs
, git-cliff-core/src/remote/bitbucket.rsR152-R155)Updates to Release Metadata Logic:
update_release_metadata
macro to use theauthor_username
method when setting the username in release metadata. This ensures that the author's username is correctly captured from the associated pull request, falling back to the existing logic if unavailable. (git-cliff-core/src/remote/mod.rs
, git-cliff-core/src/remote/mod.rsL357-R364)Test Adjustments:
git-cliff-core/src/release.rs
to include theuser
field with aNone
value for pull requests, ensuring compatibility with the newGitHubPullRequest
structure. (git-cliff-core/src/release.rs
, [1] [2] [3] [4] [5]Motivation and Context
The primary motivation was to resolve the issue with loading metadata from GitLab.
#810, #687
How Has This Been Tested?
I’m not much of a programmer—especially not in Rust—but I was able to identify the root of the issue. The tests still need to be completed, and a proper code review is required. (There may be other things as well, but I’m probably not equipped to handle those.)
Screenshots / Logs (if applicable)
N/A
Types of Changes
Checklist: