File size: 1,916 Bytes
0cc1ea4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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}"