3
3
salacious-code-reviews script entrypoint
4
4
"""
5
5
6
+ import ast
7
+ import json
6
8
import os
7
9
import re
8
- import json
9
- import ast
10
+
10
11
import openai
11
- from github import Github , PullRequest , GithubException
12
+ from github import Github , GithubException , PullRequest
12
13
from openai import OpenAI
14
+
13
15
from code_reviews import config , constants
14
16
15
17
16
18
def get_github_session () -> Github :
17
19
log .info ("Creating GitHub Session..." )
18
20
19
21
if not os .getenv ("GITHUB_TOKEN" ):
20
- log .error ("Please provide a valid GITHUB_TOKEN environment variable! " )
21
- raise SystemExit (1 )
22
+ log .error ("No GITHUB_TOKEN environment variable was detected " )
23
+ raise SystemExit (0 )
22
24
23
25
return Github (os .getenv ("GITHUB_TOKEN" ))
24
26
@@ -27,8 +29,8 @@ def get_openai_session() -> OpenAI:
27
29
log .info ("Setting up OpenAI Session..." )
28
30
29
31
if not os .getenv ("OPENAI_API_KEY" ):
30
- log .error ("Please provide a valid OPENAI_API_KEY environment variable! " )
31
- raise SystemExit (1 )
32
+ log .error ("No OPENAI_API_KEY environment variable was detected " )
33
+ raise SystemExit (0 )
32
34
33
35
return OpenAI (api_key = os .getenv ("OPENAI_API_KEY" ))
34
36
@@ -42,7 +44,7 @@ def get_repo_and_pr() -> dict:
42
44
log .info ("Getting repo and pull request from runner environment..." )
43
45
44
46
if not github_ref :
45
- log .error ("Cannot find pull request, exiting! " )
47
+ log .error ("Failed to find the GITHUB_REF environment variable " )
46
48
raise SystemExit (1 )
47
49
48
50
# If the split from GITHUB_REF is not an int, exit
@@ -56,8 +58,8 @@ def get_repo_and_pr() -> dict:
56
58
log .error (f"GITHUB_REF does not contain a valid PR number: { github_ref } " )
57
59
raise SystemExit (1 )
58
60
else :
59
- log .error ( "GITHUB_REF does not reference a pull request" )
60
- raise SystemExit (1 )
61
+ log .warn ( "Not running on a pull request; skipping the Salacious code review... " )
62
+ raise SystemExit (0 )
61
63
62
64
if not github_repo :
63
65
log .error ("Cannot get repository name, exiting!" )
@@ -209,10 +211,10 @@ def sanitize_json_string(json_string):
209
211
"ChatCompletion object does not contain expected 'choices' or 'message' structure"
210
212
)
211
213
212
- except openai .APIError as err :
213
- log .error (f"Salacious failed due to API error: { err } " )
214
214
except openai .RateLimitError as err :
215
215
log .error (f"Salacious failed due to an exceeded rate limit: { err } " )
216
+ except openai .APIError as err :
217
+ log .error (f"Salacious failed due to API error: { err } " )
216
218
except Exception as e :
217
219
log .error (f"Salacious failed due to unexpected error during API call: { str (e )} " )
218
220
0 commit comments