Daniel Lindmark 12aaa0056e
All checks were successful
Component Check / Generate_BOM (push) Successful in 54s
Remove extra request
2025-06-01 21:57:22 -05:00

65 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import os
import sys
from allspice import AllSpice, DesignReview
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="review_comment", description="Comment on a design review with markdown content."
)
parser.add_argument(
"--repository", help="The repo containing the project in the form 'owner/repo'"
)
parser.add_argument(
"--review_number", help="The design review number'"
)
parser.add_argument(
"--source_file",
help=(
"The path to the source file containing the content to post in the comment body."
),
)
parser.add_argument(
"--allspice_hub_url",
help="The URL of your AllSpice Hub instance. Defaults to https://hub.allspice.io.",
)
auth_token = os.environ.get("ALLSPICE_AUTH_TOKEN")
if auth_token is None:
print("Please set the environment variable ALLSPICE_AUTH_TOKEN")
exit(1)
auth_token = os.environ.get("ALLSPICE_AUTH_TOKEN")
args = parser.parse_args()
pr_number = args.review_number
repo_owner, repo_name = args.repository.split("/")
comment_file = args.source_file
if args.allspice_hub_url is None:
allspice = AllSpice(token_text=auth_token)
else:
allspice = AllSpice(token_text=auth_token, allspice_hub_url=args.allspice_hub_url)
if pr_number:
# Normal case: PR number is passed
design_review = DesignReview.request(allspice, repo_owner, repo_name, pr_number)
else:
print("No PR number provided. Falling back to newest design review.")
reviews = DesignReview.request(allspice, repo_owner, repo_name, 3)
if not reviews:
raise RuntimeError(f"No design reviews found for {repo_owner}/{repo_name}")
design_review = reviews
with open(comment_file, "r") as f:
design_review.create_comment(f.read())