Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	package/hatch_build.py
#	pandaserver/test/test_error_classification.py
  • Loading branch information
JammelBrooks committed Nov 19, 2024
2 parents 9ee12bd + 21a7498 commit 1a5c3f9
Show file tree
Hide file tree
Showing 35 changed files with 4,142 additions and 11,097 deletions.
2 changes: 1 addition & 1 deletion PandaPkgInfo.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = "0.3.22"
release_version = "0.4.2"
71 changes: 52 additions & 19 deletions package/hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,93 @@
import os
import pwd
import re
import requests
import socket
import stat
import subprocess
import sys
import sysconfig


import requests
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

PACKAGE_EMOJI = ":panda_face:"
PACKAGE_NAME = "panda-server"


def get_user():
# Run the 'klist' command and capture its output
result = subprocess.run(["klist"], capture_output=True, text=True)

# Filter the lines containing 'Default principal' and extract the last field
for line in result.stdout.splitlines():
if "Default principal" in line:
# Split the line by spaces and get the last element (field)
default_principal = line.split()[-1]
default_principal = default_principal.split("@")[0]
return default_principal

return ""


def get_repo_info() -> object:
# Get the current remote URL of the repository
repo_url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).strip().decode()
repo_url = subprocess.check_output(["git", "config", "--get", "remote.origin.url"]).strip().decode()

# Get the repo and branch name
match = re.match(r'https://github.com/(.*).git@(.*)', repo_url)
match = re.match(r"https://github.com/(.*).git@(.*)", repo_url)

if match:
repo_name = match.group(1)
branch_name = match.group(2)
else:
repo_name = repo_url.rstrip('.git')
branch_name = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode()
repo_name = repo_url.removesuffix(".git")
branch_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode()

# Commit hash
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip().decode()
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode()

return repo_name, branch_name, commit_hash


def mm_notification():
# Environment variable to check if we should silence the notification
if os.environ.get("DISABLE_MM"):
return

# Get user that is running the upgrade
user = get_user()

# Get repository information
repo_name, branch_name, commit_hash = get_repo_info()

#Get Server Name
# Get Server Name
server_name = socket.gethostname()

# TODO: decide on the best path for the hook URL
file_path = os.path.expanduser('~/mm_webhook_url.txt')
with open(file_path, 'r') as file:
file_path = os.path.expanduser("~/mm_webhook_url.txt")
with open(file_path, "r") as file:
mm_webhook_url = file.read().strip()
if not mm_webhook_url:
return

# On the repository name we enter an empty space to prevent the URLs to preview on Mattermost
# We shorten the commit hash to the first seven characters, as they are usually enough to identify a commit
mm_message = {
"text": f"⚙️**Install Information.** **Server Name:** {server_name}. **Package:** \"{repo_name[:7]}\u200B{repo_name[7:]}\". **Branch:** {branch_name}. **Commit:** {commit_hash}."
"text": f"{PACKAGE_EMOJI}**{PACKAGE_NAME}@{branch_name} upgrade on:** `{server_name}` by `{user}`.",
"props": {
"card": f"""
| **Property** | **Value** |
|--------------|-----------|
| **Package** | {repo_name} |
| **Branch** | [`{branch_name}`]({repo_name}/tree/{branch_name}) |
| **Commit** | [`{commit_hash}`]({repo_name}/commit/{commit_hash}) |
"""
},
}
headers = {'Content-Type': 'application/json'}
headers = {"Content-Type": "application/json"}
try:
response = requests.post(mm_webhook_url, data=json.dumps(mm_message), headers=headers)
if response.status_code == 200:
print("Message sent successfully to Mattermost")
else:
print(f"Failed to send message: {response.status_code}, {response.text}")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
pass


class CustomBuildHook(BuildHookInterface):
Expand Down Expand Up @@ -161,4 +191,7 @@ def finalize(self, version, build_data, artifact_path):
pass

# update the mattermost chat-ops channel
mm_notification()
try:
mm_notification()
except:
pass
4 changes: 0 additions & 4 deletions pandaserver/brokerage/ErrorCode.py

This file was deleted.

2 changes: 1 addition & 1 deletion pandaserver/brokerage/SiteMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_child_site_spec(self, site_spec, resource_spec):
# calculate the minRSS for the child queue
if resource_spec.minrampercore is not None:
child_site_spec.minrss = max(
child_site_spec.coreCount * resource_spec.minrampercore,
child_site_spec.coreCount * resource_spec.minrampercore - child_site_spec.coreCount + 1,
site_spec.minrss * child_site_spec.coreCount / core_count,
)
else:
Expand Down
Loading

0 comments on commit 1a5c3f9

Please sign in to comment.