Created
May 8, 2023 12:26
-
-
Save Najki/c1b34c3dbed8baaeda83986471d54c6a to your computer and use it in GitHub Desktop.
Automated pull request creation for Fitatu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Example: | |
# jira_issue_number=$(extract_jira_issue_number_from_string "nikodem/ABC-123-test") | |
# ABC-123 | |
extract_jira_issue_number_from_string() { | |
local input="$1" | |
local issue_number=$(rg -o '\b[A-Za-z]{2,5}-\d+\b' <<< "$input") | |
if [ -z "$issue_number" ]; then | |
echo "" | |
else | |
issue_number=$(echo "$issue_number" | tr '[:lower:]' '[:upper:]') | |
echo "$issue_number" | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
. $(dirname "$0")/_jira.sh | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 TARGET_BRANCH PULL_REQUEST_TITLE" | |
exit 1 | |
fi | |
target_branch=$1 | |
pull_request_title=$2 | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
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 | |
commits=$(git --no-pager log --oneline --no-merges --no-decorate $target_branch..$current_branch | sed -E 's/^([0-9a-z]+) (.+)/* \2 \1/g' | tac) | |
jira_issue_url="https://fitatu.atlassian.net/browse/$jira_issue_number" | |
# DO CREATE PULL REQUEST | |
gh pr create --title "$jira_issue_number $pull_request_title" --body "$commits | |
$jira_issue_url" --base $target_branch --head "$current_branch" --draft |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment