Skip to content

Commit

Permalink
clean-upp style
Browse files Browse the repository at this point in the history
  • Loading branch information
vsc46128 vscuser committed Jan 25, 2024
1 parent 39a9161 commit d504f1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
12 changes: 8 additions & 4 deletions eessi_bot_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Local application imports (anything from EESSI/eessi-bot-software-layer)
from connections import github
import tasks.build as build
from tasks.build import check_build_permission, get_architecture_targets, get_repo_cfg, submit_build_jobs, request_bot_build_issue_comments
from tasks.build import check_build_permission, get_architecture_targets, get_repo_cfg, \ submit_build_jobs, request_bot_build_issue_comments
import tasks.deploy as deploy
from tasks.deploy import deploy_built_artefacts
from tools import config
Expand Down Expand Up @@ -493,12 +493,16 @@ def handle_bot_command_status(self, event_info, bot_command):
repo_name = event_info['raw_request_body']['repository']['full_name']
pr_number = event_info['raw_request_body']['issue']['number']
status_table = request_bot_build_issue_comments(repo_name, pr_number)

comment = f"This is the status of all the `bot: build` commands:"
comment += f"\n|arch|result|date|status|url|"
comment += f"\n|----|------|----|------|---|"
for x in range(0,len(status_table['date'])):
comment += f"\n|{status_table['arch'][x]}|{status_table['result'][x]}|{status_table['date'][x]}|{status_table['status'][x]}|{status_table['url'][x]}|"
for x in range(0, len(status_table['date'])):
comment += f"\n|{status_table['arch'][x]}|"
comment += f"{status_table['result'][x]}|"
comment += f"{status_table['date'][x]}|"
comment += f"{status_table['status'][x]}|"
comment += f"{status_table['url'][x]}|"

self.log(f"PR opened: comment '{comment}'")
repo = gh.get_repo(repo_name)
Expand Down
25 changes: 13 additions & 12 deletions tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,35 +771,36 @@ def request_bot_build_issue_comments(repo_name, pr_number):
for x in range(1,5):
curl_cmd = f'curl -L https://api.github.com/repos/{repo_name}/issues/{pr_number}/comments?per_page=100&page={x}'
curl_output, curl_error, curl_exit_code = run_cmd(curl_cmd, "fetch all comments")

comments = json.loads(curl_output)
for comment in comments: #iterate through the comments to find the one where the status of the build was in

for comment in comments: # iterate through the comments to find the one where the status of the build was in
if config.read_config()["submitted_job_comments"]['initial_comment'][:20] in comment['body']:

#get archictecture from comment['body']
# get archictecture from comment['body']
first_line = comment['body'][:comment['body'].find('/n')]
arch_map = get_architecture_targets(cfg)
for arch in arch_map.keys():
target_arch = '/'.join(arch.split('/')[1:])
if target_arch in first_line:
status_table['arch'].append(target_arch)

#get date, status, url and result from the markdown table
# get date, status, url and result from the markdown table
comment_table = comment['body'][comment['body'].find('|'):comment['body'].rfind('|')+1]

# Convert markdown table to a dictionary
lines = comment_table.split('\n')
ret = []
keys = []
for i,l in enumerate(lines):
if i==0:
keys=[_i.strip() for _i in l.split('|')]
elif i==1: continue
for i, l in enumerate(lines):
if i == 0:
keys = [_i.strip() for _i in l.split('|')]
elif i == 1:
continue
else:
ret.append({keys[_i]:v.strip() for _i,v in enumerate(l.split('|')) if _i>0 and _i<len(keys)-1})
# add date, status, url to status_table if
ret.append({keys[_i]: v.strip() for _i, v in enumerate(l.split('|')) if _i > 0 and _i<len(keys)-1})

# add date, status, url to status_table if
for row in ret:
if row['job status'] == 'finished':
status_table['date'].append(row['date'])
Expand Down

0 comments on commit d504f1c

Please sign in to comment.