git-cliff icon indicating copy to clipboard operation
git-cliff copied to clipboard

404 Errors Fetching PR Details with Git Cliff in Monorepo (Github)

Open JacobAmar opened this issue 1 year ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Description of the bug

I am currently experiencing an issue with Git Cliff where I am unable to retrieve the pull request number to include in the changelog of a specific project structured as a monorepo. While attempting to use Git Cliff with specific configurations tailored to our project's directory and tagging structure, I continue to encounter multiple "404 Not Found" errors.

** Errors Received: **

  • Multiple 404 errors specifically related to commits and pull requests fetching:
ERROR git_cliff_core::remote > Request error: {"message":"Not Found", "documentation_url":"https://docs.github.com/rest/commits/commits#list-commits", "status":"404"}
ERROR git_cliff_core::remote > Request error: {"message":"Not Found", "documentation_url":"https://docs.github.com/rest/pulls/pulls#list-pull-requests", "status":"404"}
  • Debug logs indicated an issue while fetching page due to an unexpected JSON format:
DEBUG git_cliff_core::remote > Error while fetching page: JsonError(Error("invalid type: map, expected a sequence", line: 1, column: 0))

Steps To Reproduce

Steps to Reproduce the Issue with Git Cliff in a Monorepo:

  1. Create a Private Repository:

    • Set up a new private repository under your organization on GitHub.
  2. Establish Directory Structure:

    • Inside the repository, create a directory named charts/.
    • Under the charts/ directory, add another directory. Let's refer to this as <dir-name>.
    • This structure mimics a monorepo where different projects or components are managed in separate directories.
  3. Initial Setup and Release:

    • Inside the directory, create any file (e.g., README.md) and populate it with some content.
    • Commit these changes to the main branch.
    • Create a Git tag and a release with the pattern <name-of-the-dir-you-created>/0.1.0 and push it to GitHub.
  4. Modify Content with Conventional Commit:

    • Make modifications in the <dir-name> directory, such as editing the README.md file.
    • Commit the changes using a conventional commit message, for example: fix: test update of README.
    • Push the changes to the main branch.
  5. Run Git Cliff Command:

    • Execute the Git Cliff tool with verbose logging and specific configurations tailored to the monorepo structure: git cliff -v --github-repo <my-org>/<my-repo> --include-path "charts/<dir-name>/*" --tag-pattern "<dir-name>/(.)" -x

    • Replace and with your actual GitHub organization and repository names, and with the name of your directory under the charts/ structure.

  6. Check for PR Number in the JSON Output:

    • After running the command, examine the output JSON (if available) for the presence of prnumber or any related data such as prtitle.

Expected behavior

When using Git Cliff with the appropriate configuration in a GitHub monorepo, the expected behavior would include the successful extraction and display of GitHub metadata such as pr_number and pr_label in the context of the output. This data is crucial for generating detailed and accurate changelogs that reflect the pull requests associated with each commit.

Screenshots / Logs

No response

Software information

Im encountering the issue with Git Cliff both when running through GitHub Actions and locally on my macOS machine.

  • Operating System: macOS 14.6.1
  • Rust Version: 1.81.0
  • Git Cliff Version: 2.6.0

Additional context

No response

JacobAmar avatar Sep 23 '24 14:09 JacobAmar

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

welcome[bot] avatar Sep 23 '24 14:09 welcome[bot]

Hello 👋🏼 thanks for reporting and reproduce instructions. Can you possibly share the full logs? It is a bit hard to figure out what is going wrong from the lines you have provided.

Also, if you project is open source, I'm happy to take a look at it :)

orhun avatar Sep 23 '24 19:09 orhun

Hi @orhun thanks for answering, my project is not open source and theres no additional log that adds any information but this is what i get:

▸▹▹▹▹ Retrieving data from GitHub... (<my-org>/<my-repo>)                                                                                                                                                                                                           DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=0
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=1
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=2
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=3
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=4
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=5
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=6
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=7
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=8
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/commits?per_page=100&page=9
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/pulls?per_page=100&page=0&state=closed
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/pulls?per_page=100&page=1&state=closed
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/pulls?per_page=100&page=2&state=closed
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/pulls?per_page=100&page=3&state=closed
 DEBUG git_cliff_core::remote    > Sending request to: https://api.github.com/repos/<my-org>/<my-repo>/pulls?per_page=100&page=4&state=closed
 DEBUG reqwest::connect          > starting new connection: https://api.github.com/
 DEBUG reqwest::connect          > starting new connection: https://api.github.com/
 DEBUG reqwest::connect          > starting new connection: https://api.github.com/
 DEBUG reqwest::connect          > starting new connection: https://api.github.com/
 DEBUG reqwest::connect          > starting new connection: https://api.github.com/
 DEBUG reqwest::connect          > starting new connection: https://api.github.com/
 DEBUG rustls::client::hs        > No cached session for DnsName("api.github.com")
 DEBUG rustls::client::hs        > Not resuming any session
 DEBUG rustls::client::hs        > No cached session for DnsName("api.github.com")
 DEBUG rustls::client::hs        > Not resuming any session
 DEBUG rustls::client::hs        > No cached session for DnsName("api.github.com")
 DEBUG rustls::client::hs        > Using ciphersuite TLS13_AES_128_GCM_SHA256
 DEBUG rustls::client::tls13     > Not resuming
 DEBUG rustls::client::tls13     > TLS1.3 encrypted extensions: [ServerNameAck, Protocols([ProtocolName(687474702f312e31)])]
 DEBUG rustls::client::hs        > ALPN protocol is Some(b"http/1.1")
 DEBUG rustls::client::hs        > Using ciphersuite TLS13_AES_128_GCM_SHA256
 ERROR git_cliff_core::remote    > Request error: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/pulls/pulls#list-pull-requests","status":"404"}
 DEBUG git_cliff_core::remote    > Error while fetching page: JsonError(Error("invalid type: map, expected a sequence", line: 1, column: 0))
 DEBUG rustls::common_state      > Sending warning alert CloseNotify
 DEBUG rustls::common_state      > Sending warning alert CloseNotify
 DEBUG rustls::common_state      > Sending warning alert CloseNotify
 DEBUG rustls::common_state      > Sending warning alert CloseNotify
 ERROR git_cliff_core::remote    > Request error: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/commits/commits#list-commits","status":"404"}
 ERROR git_cliff_core::remote    > Request error: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/commits/commits#list-commits","status":"404"}
 ERROR git_cliff_core::remote    > Request error: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/commits/commits#list-commits","status":"404"}
 ERROR git_cliff_core::remote    > Request error: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/commits/commits#list-commits","status":"404"}
 DEBUG git_cliff_core::remote    > Error while fetching page: JsonError(Error("invalid type: map, expected a sequence", line: 1, column: 0))
 DEBUG rustls::common_state      > Sending warning alert CloseNotify
 DEBUG git_cliff_core::changelog > Number of GitHub commits: 0
 DEBUG git_cliff_core::changelog > Number of GitHub pull requests: 0

JacobAmar avatar Sep 24 '24 05:09 JacobAmar

@orhun I have made an update and fixed my GitHub token to include permissions to the repository as outlined in https://github.com/octokit/octokit.rb/issues/935#issuecomment-351187007. Now, I can view the PR number, but only in the contributor section. I've also updated my template to incorporate the PR number through the contributor section:

{% for contributor in github.contributors %}
  {% if contributor.prnumber %} All changes can be found in this pull request: [#{{ contributor.pr_number }}](https://github.com/ironsource-mobile/yaakov-demo/pull/{{ contributor.pr_number }}) \n {%- endif %}
{%- endfor -%}

However, I suspect there is still an issue where the PR number is not being attached to the commit.

Therefore, I suggest putting more emphasis in the documentation regarding the necessary permissions. Additionally, I’m using GitHub Actions, so I added the following permissions:

permissions:
  contents: write
  issues: write
  pull-requests: write

(Note: I’m pushing the new tag via the pull request.)

Looking forward to your feedback on this matter!

JacobAmar avatar Sep 24 '24 06:09 JacobAmar

Happy to hear that it is now working after setting the permissions!

incorporate the PR number through the contributor section:

There is a typo in your template:

{% if contributor.prnumber %} -> {% if contributor.pr_number %}

However, I suspect there is still an issue where the PR number is not being attached to the commit.

Can you expand on this a bit? What exactly are you experiencing?

so I added the following permissions:

Actually, content: read & pull-requests: read should be enough since git-cliff does not have anything to do with writing contents to the repository. Can you also test it out with these narrowed down permissions?

orhun avatar Sep 25 '24 08:09 orhun