akseljoonas HF Staff commited on
Commit
34fe7a0
·
1 Parent(s): 6b54665

Remove unused create-pr.sh

Browse files
Files changed (1) hide show
  1. create-pr.sh +0 -123
create-pr.sh DELETED
@@ -1,123 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # Colors for output
5
- GREEN='\033[0;32m'
6
- BLUE='\033[0;34m'
7
- RED='\033[0;31m'
8
- NC='\033[0m' # No Color
9
-
10
- # Check arguments
11
- if [ $# -lt 1 ]; then
12
- echo -e "${RED}Usage: ./create-pr.sh \"PR Title\" [\"Optional description\"]${NC}"
13
- echo ""
14
- echo "Example:"
15
- echo " ./create-pr.sh \"Fix authentication bug\" \"This fixes the dev mode auth issue\""
16
- exit 1
17
- fi
18
-
19
- TITLE="$1"
20
- DESCRIPTION="${2:-}"
21
-
22
- # Get current branch
23
- BRANCH=$(git rev-parse --abbrev-ref HEAD)
24
-
25
- if [ "$BRANCH" = "main" ]; then
26
- echo -e "${RED}Error: You're on the main branch. Please create a feature branch first.${NC}"
27
- exit 1
28
- fi
29
-
30
- echo -e "${BLUE}Creating PR for branch: ${GREEN}$BRANCH${NC}"
31
- echo -e "${BLUE}Title: ${GREEN}$TITLE${NC}"
32
-
33
- # Get HF_TOKEN from .env
34
- if [ ! -f .env ]; then
35
- echo -e "${RED}Error: .env file not found${NC}"
36
- exit 1
37
- fi
38
-
39
- HF_TOKEN=$(grep HF_TOKEN .env | cut -d '=' -f2)
40
-
41
- if [ -z "$HF_TOKEN" ]; then
42
- echo -e "${RED}Error: HF_TOKEN not found in .env${NC}"
43
- exit 1
44
- fi
45
-
46
- # Get list of changed files
47
- echo -e "${BLUE}Detecting changed files...${NC}"
48
- CHANGED_FILES=$(git diff --name-only main.."$BRANCH")
49
-
50
- if [ -z "$CHANGED_FILES" ]; then
51
- echo -e "${RED}Error: No changes detected between main and $BRANCH${NC}"
52
- exit 1
53
- fi
54
-
55
- echo -e "${BLUE}Changed files:${NC}"
56
- echo "$CHANGED_FILES" | while read -r file; do
57
- echo -e " ${GREEN}$file${NC}"
58
- done
59
-
60
- # Create PR using HuggingFace API with actual file operations
61
- echo -e "${BLUE}Creating pull request with file changes...${NC}"
62
-
63
- PR_URL=$(HF_TOKEN="$HF_TOKEN" uv run python - <<EOF
64
- from huggingface_hub import HfApi, CommitOperationAdd
65
- import os
66
- import sys
67
-
68
- api = HfApi(token=os.environ.get('HF_TOKEN'))
69
-
70
- # Get changed files from stdin
71
- changed_files = """$CHANGED_FILES""".strip().split('\n')
72
-
73
- operations = []
74
- for file_path in changed_files:
75
- file_path = file_path.strip()
76
- if not file_path:
77
- continue
78
-
79
- try:
80
- with open(file_path, 'rb') as f:
81
- operations.append(
82
- CommitOperationAdd(
83
- path_in_repo=file_path,
84
- path_or_fileobj=f.read()
85
- )
86
- )
87
- except FileNotFoundError:
88
- print(f"Warning: File {file_path} not found, skipping", file=sys.stderr)
89
- continue
90
-
91
- if not operations:
92
- print("Error: No valid file operations", file=sys.stderr)
93
- sys.exit(1)
94
-
95
- description = """$DESCRIPTION"""
96
- commit_message = """$TITLE"""
97
-
98
- # Create PR with actual file changes
99
- try:
100
- result = api.create_commit(
101
- repo_id='smolagents/ml-agent',
102
- repo_type='space',
103
- commit_message=commit_message,
104
- commit_description=description if description.strip() else f"Changes from branch $BRANCH",
105
- operations=operations,
106
- create_pr=True,
107
- )
108
- print(result.pr_url)
109
- except Exception as e:
110
- print(f"Error creating PR: {e}", file=sys.stderr)
111
- import traceback
112
- traceback.print_exc(file=sys.stderr)
113
- sys.exit(1)
114
- EOF
115
- )
116
-
117
- if [ $? -ne 0 ]; then
118
- echo -e "${RED}Failed to create PR${NC}"
119
- exit 1
120
- fi
121
-
122
- echo -e "${GREEN}✓ PR created successfully!${NC}"
123
- echo -e "${GREEN} $PR_URL${NC}"