-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprcreate.sh
More file actions
executable file
·57 lines (47 loc) · 1.49 KB
/
Copy pathprcreate.sh
File metadata and controls
executable file
·57 lines (47 loc) · 1.49 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
#!/bin/bash
# Create a git PR, taking a title and a URL.
# Example usage:
# ./prcreate.sh "82. Remove Duplicates from Sorted List II" https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/description/
# Convert a string to snake case
to_snake_case() {
local s="$1"
# Convert to lowercase, replace non-alphanumeric characters (except underscore) with underscores
s=$(echo "$s" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/_/g')
# Replace multiple underscores with a single underscore
s=$(echo "$s" | sed 's/__*/_/g')
# Remove leading/trailing underscores
s=$(echo "$s" | sed 's/^_//;s/_$//')
echo "$s"
}
TITLE="$1"
URL="$2"
# Check if a directory name was provided
if [ -z "$TITLE" ]; then
echo "Usage: $0 <directory_name>"
exit 1
fi
# Convert the raw input to snake case == branch name.
DIR_NAME=$(to_snake_case "$TITLE")
# Check if it's a Git repository
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: Not a Git repository. Please run this script inside a Git repository."
exit 1
fi
echo "Adding, committing, and pushing to git..."
# git push
git checkout "$DIR_NAME"
git add "$DIR_NAME"
git commit -m "$TITLE
$URL"
git push --set-upstream origin "$DIR_NAME"
# Create PR
echo "Creating PR..."
echo -e "# $TITLE\n\n$URL" | gh pr create \
--base main \
--head "$DIR_NAME" \
--title "$TITLE" \
--body-file=-
echo "$TITLE を解いたのでレビューいただけると幸いです。"
echo "問題: $URL"
echo "PR: TBD"
echo "言語: C言語"