Skip to content

Commit 2606366

Browse files
authored
Fix GitLab Author Metadata: Use username Instead of author_name, Add author_username Trait, and Improve Release Metadata Extraction (#1)
1 parent 871c3c9 commit 2606366

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

git-cliff-core/src/release.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ mod test {
551551
merge_commit_sha: Some(String::from(
552552
"1d244937ee6ceb8e0314a4a201ba93a7a61f2071",
553553
)),
554+
user: None,
554555
labels: vec![PullRequestLabel {
555556
name: String::from("rust"),
556557
}],
@@ -561,6 +562,7 @@ mod test {
561562
merge_commit_sha: Some(String::from(
562563
"21f6aa587fcb772de13f2fde0e92697c51f84162",
563564
)),
565+
user: None,
564566
labels: vec![PullRequestLabel {
565567
name: String::from("rust"),
566568
}],
@@ -571,6 +573,7 @@ mod test {
571573
merge_commit_sha: Some(String::from(
572574
"35d8c6b6329ecbcf131d7df02f93c3bbc5ba5973",
573575
)),
576+
user: None,
574577
labels: vec![PullRequestLabel {
575578
name: String::from("deps"),
576579
}],
@@ -581,6 +584,7 @@ mod test {
581584
merge_commit_sha: Some(String::from(
582585
"4d3ffe4753b923f4d7807c490e650e6624a12074",
583586
)),
587+
user: None,
584588
labels: vec![PullRequestLabel {
585589
name: String::from("deps"),
586590
}],
@@ -591,6 +595,7 @@ mod test {
591595
merge_commit_sha: Some(String::from(
592596
"5a55e92e5a62dc5bf9872ffb2566959fad98bd05",
593597
)),
598+
user: None,
594599
labels: vec![PullRequestLabel {
595600
name: String::from("github"),
596601
}],

git-cliff-core/src/remote/bitbucket.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ impl RemotePullRequest for BitbucketPullRequest {
149149
fn merge_commit(&self) -> Option<String> {
150150
Some(self.merge_commit.hash.clone())
151151
}
152+
153+
fn author_username(&self) -> Option<String> {
154+
self.author.login.clone()
155+
}
152156
}
153157

154158
/// <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-get>

git-cliff-core/src/remote/github.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ pub struct GitHubCommitAuthor {
9595
pub login: Option<String>,
9696
}
9797

98+
/// Author of the pull request.
99+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
100+
pub struct GitHubPullRequestUser {
101+
/// Username.
102+
pub login: Option<String>,
103+
}
104+
98105
/// Label of the pull request.
99106
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
100107
#[serde(rename_all = "camelCase")]
@@ -112,6 +119,8 @@ pub struct GitHubPullRequest {
112119
pub title: Option<String>,
113120
/// SHA of the merge commit.
114121
pub merge_commit_sha: Option<String>,
122+
/// Author of the pull request.
123+
pub user: Option<GitHubPullRequestUser>,
115124
/// Labels of the pull request.
116125
pub labels: Vec<PullRequestLabel>,
117126
}
@@ -132,6 +141,10 @@ impl RemotePullRequest for GitHubPullRequest {
132141
fn merge_commit(&self) -> Option<String> {
133142
self.merge_commit_sha.clone()
134143
}
144+
145+
fn author_username(&self) -> Option<String> {
146+
self.user.clone().and_then(|v| v.login)
147+
}
135148
}
136149

137150
impl RemoteEntry for GitHubPullRequest {

git-cliff-core/src/remote/gitlab.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ impl RemotePullRequest for GitLabMergeRequest {
194194
.or(self.squash_commit_sha.clone())
195195
.or(Some(self.sha.clone()))
196196
}
197+
198+
fn author_username(&self) -> Option<String> {
199+
Some(self.author.username.clone())
200+
}
197201
}
198202

199203
impl RemoteEntry for GitLabMergeRequest {

git-cliff-core/src/remote/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ pub trait RemotePullRequest: DynClone {
115115
fn labels(&self) -> Vec<String>;
116116
/// Merge commit SHA.
117117
fn merge_commit(&self) -> Option<String>;
118+
/// Username of the author of the pull request.
119+
fn author_username(&self) -> Option<String> {
120+
None
121+
}
118122
}
119123

120124
dyn_clone::clone_trait_object!(RemotePullRequest);
@@ -354,7 +358,10 @@ macro_rules! update_release_metadata {
354358
pr.merge_commit() == Some(v.id().clone()) ||
355359
pr.merge_commit() == sha_short
356360
});
357-
commit.$remote.username = v.username();
361+
let username = pull_request
362+
.and_then(|pr| pr.author_username())
363+
.or_else(|| v.username());
364+
commit.$remote.username = username.clone();
358365
commit.$remote.pr_number = pull_request.map(|v| v.number());
359366
commit.$remote.pr_title =
360367
pull_request.and_then(|v| v.title().clone());

0 commit comments

Comments
 (0)