forked from DiUS/java-faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-pr.sh
More file actions
executable file
·54 lines (42 loc) · 1.09 KB
/
create-pr.sh
File metadata and controls
executable file
·54 lines (42 loc) · 1.09 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
#!/usr/bin/env bash
# Creates a PR from the current branch targeting this repo's master branch.
# Usage: ./create-pr.sh [title] [body]
# If title/body are omitted, they are derived from the branch name and commit log.
set -euo pipefail
REPO="TheJavaGuy/java-faker"
BASE="master"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" == "$BASE" ]]; then
echo "Error: already on $BASE — create a feature branch first." >&2
exit 1
fi
# Use provided title or derive from branch name (kebab-case → sentence)
TITLE="${1:-$(echo "$BRANCH" | tr '-' ' ')}"
# Use provided body or build from commits since master
if [[ $# -ge 2 ]]; then
BODY="$2"
else
COMMITS=$(git log "$BASE".."$BRANCH" --oneline)
BODY="$(cat <<EOF
## Summary
$(git log "$BASE".."$BRANCH" --pretty=format:"- %s")
## Commits
\`\`\`
$COMMITS
\`\`\`
## Test plan
- [ ] All tests pass: \`./mvnw test\`
EOF
)"
fi
echo "Creating PR: '$TITLE'"
echo " repo: $REPO"
echo " base: $BASE"
echo " head: $BRANCH"
echo ""
gh pr create \
--repo "$REPO" \
--base "$BASE" \
--head "$BRANCH" \
--title "$TITLE" \
--body "$BODY"