xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
62.42k stars 13.4k forks source link

Auto-generate PR description [G4F] #2336

Closed yuri-val closed 2 weeks ago

yuri-val commented 3 weeks ago

๐ŸŽ‰ 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:

Let's streamline our workflow and improve collaboration! ๐Ÿš€

hqnicolas commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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

hqnicolas commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

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

yuri-val commented 3 weeks ago

@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/auto-pr-description-g4f-action@v1.2.4
        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 commented 3 weeks ago

workflows: write

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

github-actions[bot] commented 2 weeks ago

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.

hlohaus commented 2 weeks ago

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 commented 2 weeks ago

@hlohaus what do you mean?

hlohaus commented 2 weeks ago

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

yuri-val commented 2 weeks ago

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

As a result:

hlohaus commented 2 weeks ago

I will merge your PR, but you will see. ๐Ÿ™…โ€โ™‚๏ธ You have not enoght permission for writing to the Pull Request ๐Ÿ™…โ€โ™‚๏ธ

hlohaus commented 2 weeks ago

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

RuntimeError: Failed to fetch branches. Exit code: 32768

yuri-val commented 1 week ago

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:)" ยฉ๏ธ