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

Auto-generate PR description [G4F] #2336

Merged
merged 2 commits into from
Nov 17, 2024
Merged

Auto-generate PR description [G4F] #2336

merged 2 commits into from
Nov 17, 2024

Conversation

yuri-val
Copy link
Contributor

@yuri-val yuri-val commented Nov 6, 2024

🎉 Feature Addition: Auto-generate Pull Request Descriptions! 🎉

This PR introduces a new GitHub Actions workflow that automatically generates descriptions for pull requests when they are opened or synchronized.

Key Changes:

Benefits:

  • 📋 Saves time by automating PR description generation.
  • 🔍 Enhances clarity and consistency in pull request management.

Let's streamline our workflow and improve collaboration! 🚀

@hqnicolas
Copy link

hqnicolas commented Nov 6, 2024

It seems like a good way to steal the secrets.GITHUB_TOKEN to your classmates accounts,
I like it, I'm going to adopt it, thanks

@hqnicolas
Copy link

hqnicolas commented Nov 7, 2024

It's alive!
https://github.com/hqnicolas/auto-pr-description-g4f-action/releases

I was going to comment that you code as fast as a room full of Chinese hackers but then I saw your repertoire from 11 days ago

https://github.com/yuri-val/auto-pr-description-action

That's a thing G4F solved....

@yuri-val
Copy link
Contributor Author

yuri-val commented Nov 7, 2024

Yes, you are right. It's just a "free" rewrote to Python version of main action

@hqnicolas
Copy link

hqnicolas commented Nov 7, 2024

@yuri-val

if I dont provide Rulles....

Generated description (attempt 1):
This pull request is empty.  There are no changes to describe.
Updating PR description...
Error updating PR description: 403 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/pulls/pulls#update-a-pull-request", "status": "403"}
Action failed: 403 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/pulls/pulls#update-a-pull-request", "status": "403"}
Traceback (most recent call last):
  File "/app/main.py", line 169, in <module>
    main()
    ~~~~^^
  File "/app/main.py", line 86, in main
    update_pr_description(github_token, context, pr_number, generated_description)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/main.py", line 160, in update_pr_description
    pull_request.edit(body=new_description)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/PullRequest.py", line 559, in edit
    headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 586, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 744, in __check
    raise self.createException(status, responseHeaders, data)
github.GithubException.GithubException: [40](https://github.com/hqnicolas/Ollama-Pilot-CasaOs/actions/runs/11727371552/job/32668320091?pr=1#step:4:41)3 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/pulls/pulls#update-a-pull-request", "status": "403"}

@hqnicolas
Copy link

hqnicolas commented Nov 7, 2024

@yuri-val
after added rules....
https://github.com/hqnicolas/Ollama-Pilot-CasaOs/actions/runs/11727966913/job/32670320667?pr=4

Sending request to GPT-4 with temperature 0.7
Received response from o1-mini. Length: 65 characters
Generated description (attempt 1):
This pull request is empty.  There are no changes to describe.  🤔
Creating comment with original description...
Error updating PR description: 403 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/issues/comments#create-an-issue-comment", "status": "403"}
Action failed: 403 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/issues/comments#create-an-issue-comment", "status": "403"}
Traceback (most recent call last):
  File "/app/main.py", line 169, in <module>
    main()
    ~~~~^^
  File "/app/main.py", line 86, in main
    update_pr_description(github_token, context, pr_number, generated_description)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/main.py", line 156, in update_pr_description
    pull_request.create_issue_comment(f'**Original description**:\n\n{current_description}')
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/PullRequest.py", line 477, in create_issue_comment
    headers, data = self._requester.requestJsonAndCheck("POST", f"{self.issue_url}/comments", input=post_parameters)
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 586, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
                         ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 856, in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 977, in __requestEncode
    status, responseHeaders, output = self.__requestRaw(cnx, verb, url, requestHeaders, encoded_input)
                                      ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 1011, in __requestRaw
    response = cnx.getresponse()
  File "/usr/local/lib/python3.13/site-packages/github/Requester.py", line 202, in getresponse
    r = verb(
        url,
    ...<4 lines>...
        allow_redirects=False,
    )
  File "/usr/local/lib/python3.13/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.13/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
        method=request.method,
    ...<9 lines>...
        chunked=chunked,
    )
  File "/usr/local/lib/python3.13/site-packages/urllib3/connectionpool.py", line 9[34](https://github.com/hqnicolas/Ollama-Pilot-CasaOs/actions/runs/11727661900/job/32669291658#step:4:35), in urlopen
    retries = retries.increment(method, url, response=response, _pool=self)
  File "/usr/local/lib/python3.13/site-packages/github/GithubRetry.py", line 187, in increment
    raise Requester.createException(response.status, response.headers, content)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
github.GithubException.GithubException: 403 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/issues/comments#create-an-issue-comment", "status": "[40](https://github.com/hqnicolas/Ollama-Pilot-CasaOs/actions/runs/11727661900/job/32669291658#step:4:41)3"}

@yuri-val
Copy link
Contributor Author

yuri-val commented Nov 7, 2024

You should also check repo Action permissions
Repo -> Settings -> Actions -> General

@yuri-val
Copy link
Contributor Author

yuri-val commented Nov 7, 2024

@hqnicolas

Your workflow looks mostly correct, but the permission issue (403: Resource not accessible by integration) could still arise if the default GitHub token lacks appropriate scope. Below are a few recommendations to troubleshoot and resolve the error:

  1. Adjust permissions Settings

The permissions you’ve set (pull-requests: write, issues: write) should generally be sufficient, but sometimes GitHub’s permission model requires more than expected. I recommend explicitly adding permissions for workflow runs and checking if it helps:

permissions:
  contents: read
  pull-requests: write
  issues: write
  workflows: write
  1. Use a Personal Access Token (PAT)

If you’re running this workflow in a forked repository or GitHub Actions environments where the default GITHUB_TOKEN might have limited permissions, using a PAT might be necessary. To generate a PAT:
• Go to your GitHub settings.
• Under “Developer Settings,” generate a new PAT with repo and workflow scopes.
• Store this token in your repository secrets, for example, under PAT_TOKEN.

Update your workflow to use the PAT:

with:
  github_token: ${{ secrets.PAT_TOKEN }}
  1. Debugging Permissions Issues

GitHub’s 403 errors can be tricky. Here are some additional steps for debugging:
• Ensure that the workflow is triggered by an event that grants the correct permissions. In particular, PR events from forked repositories often lack write permissions for security reasons.
• You can add a debugging step in your workflow to output information about the GitHub token’s permissions:

      - name: Debug Token Permissions
        run: |
          echo "Checking token permissions..."
          curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}

This will allow you to understand whether the token has the correct permissions or is restricted.

Summary of Changes

1.	Add explicit workflows: write permission to the job.
2.	Try using a PAT instead of the default GITHUB_TOKEN if the repository is forked.
3.	Debug the token’s permissions using a debugging step.

Here’s an updated version of your workflow incorporating these suggestions:

name: Auto generate PR Description [C4F]

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  generate-pr-description:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      issues: write
      workflows: write

    steps:
      - name: Check out repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Debug Token Permissions
        run: |
          echo "Checking token permissions..."
          curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}

      - name: Auto-generate PR Description
        uses: hqnicolas/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          model: 'o1-mini'

Let me know if this helps solve the issue, or if you need more support in adjusting the permissions.

@hqnicolas
Copy link

workflows: write

it brokes the app...........

Copy link

Bumping this pull request because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

@github-actions github-actions bot added the stale label Nov 15, 2024
@hlohaus
Copy link
Collaborator

hlohaus commented Nov 15, 2024

You need to do things like the copilot does to work properly.
https://github.com/xtekky/gpt4free/blob/main/.github%2Fworkflows%2Fcopilot.yml

@yuri-val
Copy link
Contributor Author

@hlohaus what do you mean?

@hlohaus
Copy link
Collaborator

hlohaus commented Nov 15, 2024

Hey, you need to run it on unit test workflow.
And this event has the correct GitHub token.

@yuri-val
Copy link
Contributor Author

yuri-val commented Nov 15, 2024

@hlohaus I don't see the point of doing this for several reasons:

  • The PR description shouldn't depend on whether the tests have passed or not
  • I will lose the context of the event

As a result:

  • I will have to adapt the action specifically for your project
  • If someone wants to use this action, they will have to adapt their workflow to this action

@github-actions github-actions bot removed the stale label Nov 16, 2024
@hlohaus
Copy link
Collaborator

hlohaus commented Nov 17, 2024

I will merge your PR, but you will see. 🙅‍♂️ You have not enoght permission for writing to the Pull Request 🙅‍♂️

@hlohaus hlohaus merged commit 45407d3 into xtekky:main Nov 17, 2024
@hlohaus
Copy link
Collaborator

hlohaus commented Nov 17, 2024

https://github.com/xtekky/gpt4free/actions/runs/11881376591/job/33105637066

RuntimeError: Failed to fetch branches. Exit code: 32768

@yuri-val
Copy link
Contributor Author

https://github.com/xtekky/gpt4free/actions/runs/11881376591/job/33105637066

RuntimeError: Failed to fetch branches. Exit code: 32768

Ok, I'll check it tomorrow.
"On my machine it works fine:)" ©️

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