Skip to content
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

Bitbucket pull request matching does not work #905

Closed
1 task done
mcwarman opened this issue Oct 6, 2024 · 2 comments · Fixed by #907
Closed
1 task done

Bitbucket pull request matching does not work #905

mcwarman opened this issue Oct 6, 2024 · 2 comments · Fixed by #907
Assignees
Labels
integration Related to remote integration

Comments

@mcwarman
Copy link
Contributor

mcwarman commented Oct 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

When testing the Bitbucket integration the pull request matching does not work. Commits are not being matched to pull requests looking into the API response it looks to be for two reasons:

  • The BitbucketPullRequest struct does not match the API response
  • The merge_commit is shortened format in the API response.
Sample API response

{
  "values": [
    {
      "comment_count": 0,
      "task_count": 0,
      "type": "pullrequest",
      "id": 1,
      "title": "feat(ci): add git-cliff",
      "description": "",
      "state": "MERGED",
      "merge_commit": {
        "hash": "cfb00c51a374",
        "links": {
          "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/mcwarman-playground/playground/commit/cfb00c51a374"
          },
          "html": {
            "href": "https://bitbucket.org/mcwarman-playground/playground/commits/cfb00c51a374"
          }
        },
        "type": "commit"
      }
    }
    //...
  ],
  "pagelen": 10,
  "size": 1,
  "page": 1
}

Steps To Reproduce

git clone [email protected]:mcwarman-playground/playground.git
git cliff --current --context --bitbucket-repo "mcwarman-playground/playground" | jq .

vs API

curl https://api.bitbucket.org/2.0/repositories/mcwarman-playground/playground/pullrequests?state=MERGED | jq .

Expected behavior

Pull requests should be matched on merge commit and update context with PR details.

Screenshots / Logs

No response

Software information

  • Operating system: WSL - Debian GNU/Linux 12 (bookworm)
  • Rust version: N/A
  • Project version: 2.6.1

Additional context

Rust is not a language I'm to familiar with but I tested this locally and it works. Happy to raise a PR.

diff --git a/git-cliff-core/src/remote/bitbucket.rs b/git-cliff-core/src/remote/bitbucket.rs
index f45a47c..d0f4cd2 100644
--- a/git-cliff-core/src/remote/bitbucket.rs
+++ b/git-cliff-core/src/remote/bitbucket.rs
@@ -117,7 +117,7 @@ pub struct BitbucketPullRequest {
        /// Pull request title.
        pub title:            Option<String>,
        /// Bitbucket Pull Request Merge Commit
-       pub merge_commit_sha: BitbucketPullRequestMergeCommit,
+       pub merge_commit: BitbucketPullRequestMergeCommit,
        /// Author of Pull Request
        pub author:           BitbucketCommitAuthor,
 }
@@ -136,7 +136,7 @@ impl RemotePullRequest for BitbucketPullRequest {
        }

        fn merge_commit(&self) -> Option<String> {
-               Some(self.merge_commit_sha.hash.clone())
+               Some(self.merge_commit.hash.clone())
        }
 }

diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs
index 77d14e7..8b12ed1 100644
--- a/git-cliff-core/src/remote/mod.rs
+++ b/git-cliff-core/src/remote/mod.rs
@@ -306,9 +306,12 @@ macro_rules! update_release_metadata {
                                        if let Some(commit) =
                                                self.commits.iter_mut().find(|commit| commit.id == v.id())
                                        {
-                                               let pull_request = pull_requests
-                                                       .iter()
-                                                       .find(|pr| pr.merge_commit() == Some(v.id().clone()));
+                                               let sha_short =
+                                                       Some(v.id().clone().chars().take(12).collect());
+                                               let pull_request = pull_requests.iter().find(|pr| {
+                                                       pr.merge_commit() == Some(v.id().clone()) ||
+                                                               pr.merge_commit() == sha_short
+                                               });
                                                commit.$remote.username = v.username();
                                                commit.$remote.pr_number = pull_request.map(|v| v.number());
                                                commit.$remote.pr_title =
Details

~/code/src/github.com/orhun/git-cliff/target/debug/git-cliff --current --context | jq .
[
  {
    //...
    "bitbucket": {
      "contributors": [
        {
          "username": "...",
          "pr_title": "feat(ci): add git-cliff",
          "pr_number": 1,
          "pr_labels": [],
          "is_first_time": true
        }
      ]
    }
  }
]

@mcwarman mcwarman added the integration Related to remote integration label Oct 6, 2024
Copy link

welcome bot commented Oct 6, 2024

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

@mcwarman mcwarman changed the title Integration - Bitbucket pull request matching does not work Bitbucket pull request matching does not work Oct 6, 2024
@orhun
Copy link
Owner

orhun commented Oct 6, 2024

Hello, thanks for reporting! 🐻

This sounds reasonable - please go ahead and raise a PR! Also, see #763 #762 in case they are related in any way :)

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

Successfully merging a pull request may close this issue.

2 participants