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

Avoid hardcoded secrets name when checking OpenAI API Key

Open stefanusgusega opened this issue 3 months ago • 4 comments

Summary

I noticed that this tool assumed that OpenAI API Key is always stored in OPENAI_API_KEY secrets variable (https://github.com/anc95/ChatGPT-CodeReview/blob/dev/src/bot.ts#L21). I want to make this key can be stored with using flexible secrets variable name. This is recommended because the tool also initiated Chat object with OpenAI API Key fetched from environment variables, instead of directly to secrets variable (https://github.com/anc95/ChatGPT-CodeReview/blob/dev/src/bot.ts#L10).

This improvement should be good, because somehow the bot commented on the pull request indicating that I did not set OPENAI_API_KEY secrets variable (indeed I did not set it up, instead I set up the other variable). The PR can be seen on this link: https://github.com/stefanusgusega/sepotifai-retriever/pull/2

stefanusgusega avatar Sep 20 '25 15:09 stefanusgusega

I'm sorry, I think I probably misunderstood the code. So, the flow is: return Chat using process.env.OPENAI_API_KEY if any --> if not set, get OPENAI_API_KEY manually. Is it right?

stefanusgusega avatar Sep 20 '25 16:09 stefanusgusega

@stefanusgusega yes. your understanding is correct, if OPENAI_API_KEY existing in ENV, then use it. if not, then trying to retrieve it from github variables

anc95 avatar Sep 22 '25 03:09 anc95

Okay, but in my following PR (https://github.com/stefanusgusega/sepotifai-retriever/pull/2), I have set OPENAI_API_KEY on my ENV (https://github.com/stefanusgusega/sepotifai-retriever/blob/master/.github/workflows/review-bot.yml#L27), but I still get the message that I do not set the OpenAI API Key. Is it expecetd?

stefanusgusega avatar Sep 23 '25 01:09 stefanusgusega

the github action looks working.

yes, it's expected.

if you are using github bot, it can only access the OPENAI_API_KEY in variables, so it raised the error. either you deploy the bot yourself with OPENAI_API_KEY env var or you have set OPENAI_API_KEY in variables, it should work

anc95 avatar Sep 23 '25 08:09 anc95