ChatGPT-CodeReview icon indicating copy to clipboard operation
ChatGPT-CodeReview copied to clipboard

OPENAI_API_KEY configuration error: Issues during GitHub Action execution

Open HyoJeong1019 opened this issue 2 years ago • 11 comments

I have a problem with OPENAI_API_KEY not being recognized.

Screenshot 2023-04-10 at 00 30 56

  • In the first attempt, I set the OPENAI_API_KEY variable in the Variables tab. The GitHub Action runs, but OPENAI_API_KEY is empty, and the error message says it cannot be found. Screenshot 2023-04-10 at 00 31 39

  • In the second attempt, I set up the YAML file like this and pushed it, but OPENAI_API_KEY is still empty.

  • Despite setting up the OPENAI_API_KEY in Actions secrets and variables, you are still encountering an issue where the OPENAI_API_KEY value is not being recognized.

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.🥲

HyoJeong1019 avatar Apr 09 '23 15:04 HyoJeong1019

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

anc95 avatar Apr 10 '23 03:04 anc95

@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

HyoJeong1019 avatar Apr 10 '23 03:04 HyoJeong1019

@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.

anc95 avatar Apr 10 '23 06:04 anc95

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

XiaoRIGE avatar Apr 23 '23 07:04 XiaoRIGE

@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.

anc95 avatar Apr 23 '23 15:04 anc95

@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)

mralexandernickel avatar Apr 27 '23 14:04 mralexandernickel

@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.

anc95 avatar Apr 27 '23 15:04 anc95

@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 avatar Apr 27 '23 15:04 mralexandernickel

@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...

mralexandernickel avatar Apr 27 '23 15:04 mralexandernickel

@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.

anc95 avatar Apr 27 '23 16:04 anc95

@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!

mralexandernickel avatar Apr 28 '23 09:04 mralexandernickel