Skip to content

Commit

Permalink
Merge branch 'master' into fix-grep-3
Browse files Browse the repository at this point in the history
  • Loading branch information
JackPGreen authored Aug 16, 2024
2 parents 60c1ab4 + 31f5d6f commit 4a0c4cd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Test PR

on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: ./backport.functions_tests
7 changes: 5 additions & 2 deletions backport
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function usage() {
echo " - create a PR from the new branch to 5.2.z branch with body and labels from the original PR (if found)"
}

# shellcheck source=/dev/null
. backport.functions

check_command() {
if ! [ -x "$(command -v "$1")" ]; then
echo "Error: '$1' tool required - $2"
Expand Down Expand Up @@ -104,8 +107,8 @@ SUFFIX="${TARGET##*/}"

log_info "Backporting the last commit from $SOURCE onto $TARGET"

COMMIT_MSG=$(git show -s --format='%s' "$SOURCE")
ORIGINAL_PR_NUMBER=$(echo "$COMMIT_MSG" | grep --extended-regexp --only-matching '#[0-9]+' | tail -n1 | cut -c2-)
COMMIT_MSG=$(git show -s --format='%s' "$SOURCE")ORIGINAL_PR_NUMBER=$(echo "$COMMIT_MSG" | grep --extended-regexp --only-matching '
ORIGINAL_PR_NUMBER=$(get_pr_number "$COMMIT_MSG")
NEW_COMMIT_MSG="$( echo "${COMMIT_MSG// \(\#$ORIGINAL_PR_NUMBER\)}" | sed -r 's/ \[.+\]//g') [$SUFFIX]"
UPSTREAM_URL="$(git remote get-url upstream)"
if [[ $UPSTREAM_URL == http* ]]; then
Expand Down
9 changes: 9 additions & 0 deletions backport.functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

function get_pr_number() {

local commit_msg=$1
echo "$commit_msg" | grep -oP '#(\d+)' | tail -n1 | cut -c2-
}
26 changes: 26 additions & 0 deletions backport.functions_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -eu
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

# Source the latest version of assert.sh unit testing library and include in current shell
assert_script_content=$(curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh)
# shellcheck source=/dev/null
. <(echo "${assert_script_content}")
. "$SCRIPT_DIR"/backport.functions

TESTS_RESULT=0

function test_get_pr_number {
local commit_msg=$1
local expected_pr_number=$2
local actual_pr_number=$(get_pr_number "$commit_msg")
local MSG="Expected PR Number extracted from \"$commit_msg\""
assert_eq "$expected_pr_number" "$actual_pr_number" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}

log_header "Tests for get_pr_number"
test_get_pr_number 'Fix private test repository access [DI-236] (#221)' '221'
test_get_pr_number 'Fix private test repository access [DI-236] (#221) (#222)' '222'

assert_eq 0 "$TESTS_RESULT" "All tests should pass"

0 comments on commit 4a0c4cd

Please sign in to comment.