-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr_script.sh
More file actions
executable file
·89 lines (74 loc) · 2.18 KB
/
pr_script.sh
File metadata and controls
executable file
·89 lines (74 loc) · 2.18 KB
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
82
83
84
85
86
87
88
89
#!/bin/bash
# Get arguments
PR_NUMBER="$1"
PR_TITLE="$2"
PR_URL="$3"
GITHUB_TOKEN="${GITHUB_TOKEN:-}"
# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed. Please install it first:"
echo "For Linux:"
echo " ./gh_install.sh"
echo "For macOS:"
echo " brew install gh"
exit 1
fi
# If GITHUB_TOKEN is not set, try to get it from gh
if [ -z "$GITHUB_TOKEN" ]; then
GITHUB_TOKEN=$(gh auth token)
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: Could not get GitHub token. Please either:"
echo "1. Set GITHUB_TOKEN environment variable"
echo "2. Run 'gh auth login' to authenticate GitHub CLI"
exit 1
fi
fi
# Export token for gh to use
export GITHUB_TOKEN
# Log the pull request information
echo "New pull request received!"
echo "PR Number: $PR_NUMBER"
echo "PR Title: $PR_TITLE"
echo "PR URL: $PR_URL"
# Write PR information to a file
LOG_FILE="pr_details.log"
echo "=== Pull Request Details ===" > "$LOG_FILE"
echo "Timestamp: $(date)" >> "$LOG_FILE"
echo "PR Number: $PR_NUMBER" >> "$LOG_FILE"
echo "PR Title: $PR_TITLE" >> "$LOG_FILE"
echo "PR URL: $PR_URL" >> "$LOG_FILE"
echo "===========================" >> "$LOG_FILE"
# Log that we wrote to the file
echo "PR details written to $LOG_FILE"
# Extract repository information from PR_URL
# Expected format: https://github.com/owner/repo/pull/number
REPO_OWNER_AND_NAME=$(echo "$PR_URL" | sed -E 's|https://github.com/||' | sed -E 's|/pull/.*||')
# Create a temporary directory for checkout
TEMP_DIR=$(mktemp -d)
echo "Created temporary directory: $TEMP_DIR"
# Clone and checkout PR using gh cli
echo "Cloning repository and checking out PR #$PR_NUMBER..."
cd "$TEMP_DIR"
gh pr checkout "$PR_NUMBER" --repo "$REPO_OWNER_AND_NAME"
if [ $? -ne 0 ]; then
echo "Failed to checkout PR"
cd -
rm -rf "$TEMP_DIR"
exit 1
fi
# Run make command
echo "Running make command..."
if ! make; then
echo "Make command failed!"
cd -
rm -rf "$TEMP_DIR"
exit 1
fi
# Clean up
echo "Cleaning up temporary directory..."
cd -
rm -rf "$TEMP_DIR"
# Log completion
echo "Pull request processing completed!"
# Exit successfully
exit 0