-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfinish_task.sh
executable file
·75 lines (63 loc) · 2.39 KB
/
finish_task.sh
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
#!/bin/bash
# Check if a PR title is provided
if [ -z "$1" ]; then
echo "Usage: $0 <pr_title> [pr_description]"
echo "Example: $0 \"Add user authentication\" \"This PR implements user login and registration\""
exit 1
fi
PR_TITLE="$1"
PR_DESCRIPTION="${2:-"No description provided."}"
# Get current branch name
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
if [ "$CURRENT_BRANCH" = "main" ]; then
echo "Error: You are on the main branch. Please switch to a feature branch."
exit 1
fi
# Check if there are any uncommitted changes
if ! git diff --quiet || ! git diff --staged --quiet; then
# Stage all changes
echo "Staging all changes..."
git add .
# Commit changes
echo "Committing changes with title: $PR_TITLE"
git commit -m "$PR_TITLE" -m "$PR_DESCRIPTION"
if [ $? -ne 0 ]; then
echo "Failed to commit changes."
exit 1
fi
# Push changes to remote
echo "Pushing changes to origin/$CURRENT_BRANCH..."
git push -u origin "$CURRENT_BRANCH"
if [ $? -ne 0 ]; then
echo "Failed to push changes to remote."
exit 1
fi
else
echo "No uncommitted changes found. Proceeding with PR creation for already committed changes."
fi
# Create PR using GitHub CLI
echo "Creating pull request..."
if command -v gh &> /dev/null; then
PR_URL=$(gh pr create --title "$PR_TITLE" --body "$PR_DESCRIPTION" --base main --head "$CURRENT_BRANCH")
if [ $? -eq 0 ]; then
echo "Pull request created successfully!"
echo "PR URL: $PR_URL"
# Try to open the PR URL in the default browser
if command -v xdg-open &> /dev/null; then
xdg-open "$PR_URL" &> /dev/null & # Linux
elif command -v open &> /dev/null; then
open "$PR_URL" &> /dev/null & # macOS
elif command -v start &> /dev/null; then
start "$PR_URL" &> /dev/null & # Windows
else
echo "Could not automatically open the PR in your browser."
fi
else
echo "Failed to create pull request using GitHub CLI."
echo "Please create a PR manually at: https://github.com/$(git config --get remote.origin.url | sed 's/.*github.com[:\/]\(.*\)\.git/\1/')/pull/new/$CURRENT_BRANCH"
fi
else
echo "GitHub CLI (gh) not found. Please install it to create PRs from the command line."
echo "You can create a PR manually at: https://github.com/$(git config --get remote.origin.url | sed 's/.*github.com[:\/]\(.*\)\.git/\1/')/pull/new/$CURRENT_BRANCH"
fi
echo "Task completion workflow finished!"