4747
4848GITHUB_ACTION_LOG = f"{ GITHUB_SERVER_URL } /{ GITHUB_REPOSITORY } /actions/runs/{ GITHUB_RUN_ID } "
4949
50- GITHUB_USER = os .getenv ("GITHUB_USER" , os .getenv ("GITHUB_USER" , getuser ()))
5150GITHUB_API_ENDPOINT = f"https://api.github.com/repos/{ GITHUB_REPOSITORY } "
5251
5352REDMINE_CUSTOM_FIELD_ID_BACKPORT = 2
@@ -112,8 +111,10 @@ def process(self, msg, kwargs):
112111log .addHandler (log_stream )
113112log .setLevel (logging .INFO )
114113
115- def gitauth ():
116- return (GITHUB_USER , GITHUB_TOKEN )
114+ GITHUB_HEADERS = {
115+ "Authorization" : f"Bearer { GITHUB_TOKEN } " ,
116+ "X-GitHub-Api-Version" : "2022-11-28" ,
117+ }
117118
118119def post_github_comment (session , pr_id , body ):
119120 """Helper to post a comment to a GitHub PR."""
@@ -125,7 +126,7 @@ def post_github_comment(session, pr_id, body):
125126 endpoint = f"{ GITHUB_API_ENDPOINT } /issues/{ pr_id } /comments"
126127 payload = {'body' : body }
127128 try :
128- response = session .post (endpoint , auth = gitauth () , json = payload )
129+ response = session .post (endpoint , headers = GITHUB_HEADERS , json = payload )
129130 response .raise_for_status ()
130131 log .info (f"Successfully posted comment to PR #{ pr_id } ." )
131132 return True
@@ -341,7 +342,7 @@ def fetch_pr(self):
341342 endpoint = f"{ GITHUB_API_ENDPOINT } /pulls/{ pr_id } "
342343 params = {}
343344 try :
344- response = self .github_session .get (endpoint , auth = gitauth () , params = params )
345+ response = self .github_session .get (endpoint , headers = GITHUB_HEADERS , params = params )
345346 response .raise_for_status ()
346347 pr_data = response .json ()
347348 self .logger .debug ("PR #%d json:\n %s" , pr_id , pr_data )
@@ -1395,6 +1396,10 @@ def main():
13951396 log .fatal ("REDMINE_API_KEY not found! Please set REDMINE_API_KEY environment variable or ~/.redmine_key." )
13961397 sys .exit (1 )
13971398
1399+ if GITHUB_TOKEN is None :
1400+ log .fatal ("GITHUB_TOKEN not found! Please set GITHUB_TOKEN environment variable or ~/.github_token." )
1401+ sys .exit (1 )
1402+
13981403 if IS_GITHUB_ACTION and GITHUB_REPOSITORY != "ceph/ceph" :
13991404 log .fatal ("refusing to run ceph/ceph.git github action for repository {GITHUB_REPOSITORY}" )
14001405 sys .exit (0 )
0 commit comments