Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions buildbot/lib/buildbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,36 @@ def print_buildbot_info(utility_name):

print()

str_git = os.popen("git log -n 1 --decorate=full").read()
try:
r_log = subprocess.run(
["git", "log", "-n", "1", "--decorate=full"],
capture_output=True,
text=True,
)
if r_log.returncode != 0:
raise RuntimeError("git log failed")

git_hash = str_git.split()[1]
git_head = str_git[str_git.find("HEAD -> ") + 8 : str_git.find(")")]
str_git = r_log.stdout
git_hash = str_git.split()[1]
git_head = str_git[str_git.find("HEAD -> ") + 8 : str_git.find(")")]

git_head = git_head.split(",")
git_head = git_head.split(",")

if len(git_head) == 1:
git_head = "\033[1;92m" + git_head[0] + "\033[0;0m"
else:
git_head = "\033[1;92m" + git_head[0] + "\033[0;0m , \033[1;91m" + git_head[0] + "\033[0;0m"
if len(git_head) == 1:
git_head = "\033[1;92m" + git_head[0] + "\033[0;0m"
else:
git_head = (
"\033[1;92m" + git_head[0] + "\033[0;0m , \033[1;91m" + git_head[0] + "\033[0;0m"
Comment on lines +80 to +81
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The git_head variable is duplicated in the string formatting when len(git_head) > 1. It appears there might be an intention to display multiple heads or branches, but currently, it prints the first element twice. If there are multiple heads (e.g., HEAD -> main, origin/main), you should display git_head[0] and git_head[1] (or iterate through git_head if more are possible).

Suggested change
git_head = (
"\033[1;92m" + git_head[0] + "\033[0;0m , \033[1;91m" + git_head[0] + "\033[0;0m"
git_head = (
"\033[1;92m" + git_head[0] + "\033[0;0m , \033[1;91m" + git_head[1] + "\033[0;0m"
)

)

print("\033[1;34mGit status \033[0;0m: ")
print(" \033[1;93mcommit \033[0;0m: ", git_hash)
print(" \033[1;36mHEAD \033[0;0m: ", git_head)
print(" \033[1;31mmodified files\033[0;0m (since last commit):")
print(os.popen('git diff-index --name-only HEAD -- | sed "s/^/ /g"').read())
print("\033[1;90m" + "-" * col_cnt + "\033[0;0m\n")
print("\033[1;34mGit status \033[0;0m: ")
print(" \033[1;93mcommit \033[0;0m: ", git_hash)
print(" \033[1;36mHEAD \033[0;0m: ", git_head)
print(" \033[1;31mmodified files\033[0;0m (since last commit):")
print(os.popen('git diff-index --name-only HEAD -- | sed "s/^/ /g"').read())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The git diff-index command still uses os.popen. For consistency and improved error handling, it's recommended to use subprocess.run for all external command executions, similar to how git log was updated. This also allows for better error handling and avoids shell injection risks associated with os.popen.

Suggested change
print(os.popen('git diff-index --name-only HEAD -- | sed "s/^/ /g"').read())
r_diff = subprocess.run(
["git", "diff-index", "--name-only", "HEAD", "--"],
capture_output=True,
text=True,
check=True,
)
modified_files = "".join([" " + line for line in r_diff.stdout.splitlines(keepends=True)])
print(modified_files)

print("\033[1;90m" + "-" * col_cnt + "\033[0;0m\n")
except Exception: # noqa: BLE001
Comment thread
tdavidcl marked this conversation as resolved.
print("Warn : couldn't get git status")


def run_cmd(str):
Expand Down
Loading