-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-pr-create.sh
More file actions
executable file
·64 lines (50 loc) · 1.57 KB
/
git-pr-create.sh
File metadata and controls
executable file
·64 lines (50 loc) · 1.57 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
#!/bin/bash
set -euo pipefail
# Check if git command exists
if ! command -v git &> /dev/null; then
echo "Error: git command not found. Please install Git."
exit 1
fi
# Check if gh command exists
if ! command -v gh &> /dev/null; then
echo "Error: gh command not found. Please install GitHub CLI."
exit 1
fi
. $(dirname "$0")/_jira.sh
LANGUAGE=$1
TARGET_BRANCH=$2
PULL_REQUEST_TITLE=$3
PULL_REQUEST_BODY=${4:-_TODO_}
JIRA_COMPANY=${5:-}
if [ "${LANGUAGE}" = "pl" ]; then
BODY_HEADER="## Opis:"
elif [ "${LANGUAGE}" = "en" ]; then
BODY_HEADER="## Description:"
else
echo "Error: first argument must be 'pl' or 'en'."
exit 1
fi
if [ -z "${TARGET_BRANCH}" ]; then
read -p "Please enter the target branch name (e.g., 'master'): " TARGET_BRANCH
fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -n "${JIRA_COMPANY}" ]; then
JIRA_ISSUE_NUMBER=$(extract_jira_issue_number_from_string "${CURRENT_BRANCH}")
if [ -z "${JIRA_ISSUE_NUMBER}" ]; then
read -p "Could not find Jira issue number in branch name. Please enter the Jira issue number: " JIRA_ISSUE_NUMBER
fi
JIRA_ISSUE_URL="https://${JIRA_COMPANY}.atlassian.net/browse/${JIRA_ISSUE_NUMBER}"
JIRA_SECTION="
## Jira:
${JIRA_ISSUE_URL}"
else
JIRA_ISSUE_NUMBER=""
JIRA_SECTION=""
fi
PR_TITLE="${PULL_REQUEST_TITLE}"
if [ -n "${JIRA_ISSUE_NUMBER}" ]; then
PR_TITLE="${JIRA_ISSUE_NUMBER} ${PULL_REQUEST_TITLE}"
fi
# Create pull request
gh pr create --title "${PR_TITLE}" --body "${BODY_HEADER}
${PULL_REQUEST_BODY}${JIRA_SECTION}" --base ${TARGET_BRANCH} --head "${CURRENT_BRANCH}" --draft --assignee @me