anc95 / ChatGPT-CodeReview

🐥 A code review bot powered by ChatGPT
https://github.com/apps/cr-gpt
ISC License
3.77k stars 361 forks source link

OPENAI_API_KEY configuration error: Issues during GitHub Action execution #67

Open HyoJeong1019 opened 1 year ago

HyoJeong1019 commented 1 year ago

I have a problem with OPENAI_API_KEY not being recognized.

Screenshot 2023-04-10 at 00 30 56

name: Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: anc95/ChatGPT-CodeReview@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

Screenshot 2023-04-10 at 00 50 09

Screenshot 2023-04-10 at 00 33 36

Please tell me how to solve the problem.🥲

anc95 commented 1 year ago

@julian-jeong is your pull request from one forked repo to the main repo?

HyoJeong1019 commented 1 year ago

@anc95 This is pull request for the "a branch" that originated from the "main branch". Please refer to the attached image.

Screenshot 2023-04-10 at 12 25 44
anc95 commented 1 year ago

@julian-jeong Your setup should be fine, I suggest creating a simple GitHub action demo to test it out, such as https://docs.github.com/en/actions/security-guides/encrypted-secrets#example-using-bash.

XiaoRIGE commented 1 year ago

Have you solved this problem? I seem to have encountered the same situation

anc95 commented 1 year ago

@XiaoRIGE It may not be a code bug, but rather some restrictions on the use of GitHub secrets. I am unable to reproduce it, so at the moment I have no idea how to assist with this.

mralexandernickel commented 1 year ago

@anc95 it looks like here is the problem:

https://github.com/anc95/ChatGPT-CodeReview/blob/17cbc89909aadaa332245b1d51adb231d8395e18/src/bot.ts#L18

:top: this code is executed even though it seems to be not needed. when this variable is added inside the repository, then the error is gone... no matter which value the variable has (does not need to be an api key)

anc95 commented 1 year ago

@mralexandernickel https://github.com/anc95/ChatGPT-CodeReview/blob/17cbc89909aadaa332245b1d51adb231d8395e18/src/bot.ts#L10-L19

If OPEN_API_KEY is properly set, the code should go into the first if statement. However, it seems that the secret was not successfully injected to the environment when running the GitHub action. This has resulted in falling back to querying the OPENAI_API_KEY in the variable. Setting the key in the variable when using GitHub action integration is not recommended. This is because GitHub displays the variable in the action running log, which compromises security.

mralexandernickel commented 1 year ago

@anc95 yeah i have seen that, but the interesting part is, that our OPENAI_API_KEY in fact is set up correctly, and we also get responses/comments from chatgpt in our pul requests afterwards. 🤷

so in fact "it is working", but we get that strange comment that the variable is not set. for us we have set up the OPENAI_API_KEY as an organization secret, even though I can not see a reason why that should be a problem...escpecially since it is working. really strange. 🤔

mralexandernickel commented 1 year ago

@anc95

This could also be a hint to the problem:

the comment about "api key variable not set up" seem to be created via default GITHUB_TOKEN (commet is made by user "cr-gpt"), even though we have added a PAT in the yaml to be used. and the comment after that, with the response coming from chatgpt is then made by using the PAT we have set via yaml. maybe that information could be helping...

anc95 commented 1 year ago

@mralexandernickel it seems that you setup both GitHub action and GitHub app integrations. The warning comment is sent by GitHub app. So try to remove the GitHub app from your repo to see if it will be no warning in comment.

mralexandernickel commented 1 year ago

@anc95

🤦 exactly that has been the problem, thank you very much! I have removed the github app from our organization and instead only use the github action. now we got the behaviour we'd like to have 😊

sorry for my misunderstanding of setting up the integration, and thank you for your support and great work here!