ml-intern / create-pr.sh
elisaklunder's picture
Fix bugs of message disappearing sometimes and being duplicate sometimes
4b58d20
raw
history blame
1.92 kB
#!/bin/bash
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check arguments
if [ $# -lt 1 ]; then
echo -e "${RED}Usage: ./create-pr.sh \"PR Title\" [\"Optional description\"]${NC}"
echo ""
echo "Example:"
echo " ./create-pr.sh \"Fix authentication bug\" \"This fixes the dev mode auth issue\""
exit 1
fi
TITLE="$1"
DESCRIPTION="${2:-}"
# Get current branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" = "main" ]; then
echo -e "${RED}Error: You're on the main branch. Please create a feature branch first.${NC}"
exit 1
fi
echo -e "${BLUE}Creating PR for branch: ${GREEN}$BRANCH${NC}"
echo -e "${BLUE}Title: ${GREEN}$TITLE${NC}"
# Get HF_TOKEN from .env
if [ ! -f .env ]; then
echo -e "${RED}Error: .env file not found${NC}"
exit 1
fi
HF_TOKEN=$(grep HF_TOKEN .env | cut -d '=' -f2)
if [ -z "$HF_TOKEN" ]; then
echo -e "${RED}Error: HF_TOKEN not found in .env${NC}"
exit 1
fi
# Create PR using HuggingFace API
echo -e "${BLUE}Creating pull request...${NC}"
PR_INFO=$(HF_TOKEN="$HF_TOKEN" uv run python - <<EOF
from huggingface_hub import HfApi
import os
api = HfApi(token=os.environ.get('HF_TOKEN'))
description = """$DESCRIPTION"""
discussion = api.create_discussion(
repo_id='smolagents/ml-agent',
repo_type='space',
title="""$TITLE""",
description=description if description.strip() else "Changes from branch $BRANCH",
pull_request=True,
)
print(f"{discussion.num}|{discussion.url}")
EOF
)
PR_NUM=$(echo "$PR_INFO" | cut -d '|' -f1)
PR_URL=$(echo "$PR_INFO" | cut -d '|' -f2)
echo -e "${GREEN}✓ PR created: #$PR_NUM${NC}"
echo -e "${BLUE}URL: $PR_URL${NC}"
# Push branch to PR ref
echo -e "${BLUE}Pushing changes to PR...${NC}"
git push -f origin "$BRANCH:refs/pr/$PR_NUM"
echo -e "${GREEN}✓ Done! Your PR is ready:${NC}"
echo -e "${GREEN} $PR_URL${NC}"