@@ -44,53 +44,53 @@ def main():
4444 print (f"summary_url: { summary_url } " )
4545 print ("######################" )
4646
47- # try:
48- # x = requests.get(summary_url, stream=True, auth=('token',GITHUB_TOKEN))
49- # x.raise_for_status()
50- # except requests.exceptions.HTTPError as errh:
51- # output = "GITHUB API Http Error:" + str(errh)
52- # print(f"Error: {output}")
53- # print(f"::set-output name=result::{output}")
54- # return x.status_code
55- # except requests.exceptions.ConnectionError as errc:
56- # output = "GITHUB API Error Connecting:" + str(errc)
57- # print(f"Error: {output}")
58- # print(f"::set-output name=result::{output}")
59- # return x.status_code
60- # except requests.exceptions.Timeout as errt:
61- # output = "Timeout Error:" + str(errt)
62- # print(f"Error: {output}")
63- # print(f"::set-output name=result::{output}")
64- # return x.status_code
65- # except requests.exceptions.RequestException as err:
66- # output = "GITHUB API Non catched error conecting:" + str(err)
67- # print(f"Error: {output}")
68- # print(f"::set-output name=result::{output}")
69- # return x.status_code
70- # except Exception as e:
71- # print("Internal error", e)
72- # return x.status_code
73-
74- # summary = x.json()
75-
76- # summary.pop('repository')
77-
78- # summary["repository"]=summary["head_repository"]["name"]
79- # summary["repository_full"]=summary["head_repository"]["full_name"]
80-
81- # summary.pop('head_repository')
82-
83- # utc_time = datetime.strptime(summary["updated_at"], "%Y-%m-%dT%H:%M:%SZ")
84- # epoch_time = (utc_time - datetime(1970, 1, 1)).total_seconds()
85-
86- # event={'event':json.dumps(summary),'sourcetype':SPLUNK_SOURCETYPE,'source':'workflow_summary','host':host,'time':epoch_time}
87- # event=json.dumps(event)
88-
89- # x=requests.post(SPLUNK_HEC_URL, data=event, headers=headers)
90-
91-
92- # url = "{url}/repos/{repo}/actions/runs/{run_id}/logs".format(url=GITHUB_API_URL,repo=GITHUB_REPOSITORY,run_id=GITHUB_WORKFLOWID)
93- # print(url)
47+ try :
48+ x = requests .get (summary_url , stream = True , auth = ('token' ,GITHUB_TOKEN ))
49+ x .raise_for_status ()
50+ except requests .exceptions .HTTPError as errh :
51+ output = "GITHUB API Http Error:" + str (errh )
52+ print (f"Error: { output } " )
53+ print (f"::set-output name=result::{ output } " )
54+ return x .status_code
55+ except requests .exceptions .ConnectionError as errc :
56+ output = "GITHUB API Error Connecting:" + str (errc )
57+ print (f"Error: { output } " )
58+ print (f"::set-output name=result::{ output } " )
59+ return x .status_code
60+ except requests .exceptions .Timeout as errt :
61+ output = "Timeout Error:" + str (errt )
62+ print (f"Error: { output } " )
63+ print (f"::set-output name=result::{ output } " )
64+ return x .status_code
65+ except requests .exceptions .RequestException as err :
66+ output = "GITHUB API Non catched error conecting:" + str (err )
67+ print (f"Error: { output } " )
68+ print (f"::set-output name=result::{ output } " )
69+ return x .status_code
70+ except Exception as e :
71+ print ("Internal error" , e )
72+ return x .status_code
73+
74+ summary = x .json ()
75+
76+ summary .pop ('repository' )
77+
78+ summary ["repository" ]= summary ["head_repository" ]["name" ]
79+ summary ["repository_full" ]= summary ["head_repository" ]["full_name" ]
80+
81+ summary .pop ('head_repository' )
82+
83+ utc_time = datetime .strptime (summary ["updated_at" ], "%Y-%m-%dT%H:%M:%SZ" )
84+ epoch_time = (utc_time - datetime (1970 , 1 , 1 )).total_seconds ()
85+
86+ event = {'event' :json .dumps (summary ),'sourcetype' :SPLUNK_SOURCETYPE ,'source' :'workflow_summary' ,'host' :host ,'time' :epoch_time }
87+ event = json .dumps (event )
88+
89+ x = requests .post (SPLUNK_HEC_URL , data = event , headers = headers )
90+
91+
92+ url = "{url}/repos/{repo}/actions/runs/{run_id}/logs" .format (url = GITHUB_API_URL ,repo = GITHUB_REPOSITORY ,run_id = GITHUB_WORKFLOWID )
93+ print (url )
9494
9595 # try:
9696 # x = requests.get(url, stream=True, auth=('token',GITHUB_TOKEN))
0 commit comments