Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JuryA
Copy link

@JuryA JuryA commented Jun 21, 2025

…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:

  • Added a new method author_username to the RemotePullRequest trait, which returns the username of the pull request's author. A default implementation returning None is provided for backward compatibility. (git-cliff-core/src/remote/mod.rs, git-cliff-core/src/remote/mod.rsR118-R121)

Platform-Specific Implementations:

  • GitHub:

    • Introduced a new struct GitHubPullRequestUser to represent the pull request author.
    • Updated the GitHubPullRequest struct to include a user field of type Option<GitHubPullRequestUser>.
    • Implemented the author_username method for GitHubPullRequest to return the author's username. (git-cliff-core/src/remote/github.rs, [1] [2] [3]
  • GitLab: Implemented the author_username method for GitLabMergeRequest 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 for BitbucketPullRequest 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:

  • Modified the update_release_metadata macro to use the author_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:

  • Updated test cases in git-cliff-core/src/release.rs to include the user field with a None value for pull requests, ensuring compatibility with the new GitHubPullRequest 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…Add `author_username` Trait, and Improve Release Metadata Extraction (#1)
Copy link

welcome bot commented Jun 21, 2025

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@JuryA JuryA marked this pull request as ready for review June 21, 2025 17:54
@Copilot Copilot AI review requested due to automatic review settings June 21, 2025 17:54
@JuryA JuryA requested a review from orhun as a code owner June 21, 2025 17:54
Copy link

@Copilot Copilot AI left a 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 the RemotePullRequest trait with a default None 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 to GitHubPullRequestAuthor (and the user 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 a GitLabMergeRequest 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 ensure author_username correctly returns the author.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();
Copy link
Preview

Copilot AI Jun 21, 2025

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.

Suggested change
commit.$remote.username = username.clone();
commit.$remote.username = username;

Copilot uses AI. Check for mistakes.

@JuryA
Copy link
Author

JuryA commented Jun 21, 2025

@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.

Copy link
Contributor

@ognis1205 ognis1205 left a 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())
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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
},

Copy link
Author

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.

Copy link
Contributor

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.

/// Commit author.
fn username(&self) -> Option<String>;

@orhun
Copy link
Owner

orhun commented Jun 22, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants