Compare commits
10 Commits
fix/issue-
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28b343f817 | ||
|
|
836fde07fc | ||
|
|
c8bb0b36f4 | ||
| 937b7c69de | |||
|
|
2051266809 | ||
| 80a3228be9 | |||
|
|
d68a63af41 | ||
| 56310755b8 | |||
|
|
fb33be3a64 | ||
| 1b19c9a92c |
@@ -93,6 +93,10 @@ EOF
|
|||||||
|
|
||||||
ensure_dirs() {
|
ensure_dirs() {
|
||||||
mkdir -p "$SESSIONS_DIR"
|
mkdir -p "$SESSIONS_DIR"
|
||||||
|
mkdir -p "$LOGS_DIR"
|
||||||
|
mkdir -p "$WORKTREES_DIR"
|
||||||
|
mkdir -p "$QUEUE_DIR"
|
||||||
|
mkdir -p "$QUEUE_ITEMS_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_worktree_dir() {
|
ensure_worktree_dir() {
|
||||||
@@ -257,7 +261,9 @@ PYEOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_queue_dirs() {
|
ensure_queue_dirs() {
|
||||||
|
mkdir -p "$QUEUE_DIR"
|
||||||
mkdir -p "$QUEUE_ITEMS_DIR"
|
mkdir -p "$QUEUE_ITEMS_DIR"
|
||||||
|
mkdir -p "$LOGS_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_queue_id() {
|
generate_queue_id() {
|
||||||
@@ -848,6 +854,11 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_issue_ref_from_message() {
|
parse_issue_ref_from_message() {
|
||||||
|
# DEPRECATED: This function is not called anywhere.
|
||||||
|
# The active implementation is extract_issue_ref_from_message()
|
||||||
|
# in kugetsu-session.sh which is used by cmd_delegate.
|
||||||
|
# This function is kept for backwards compatibility and will
|
||||||
|
# be removed in a future release.
|
||||||
local message="$1"
|
local message="$1"
|
||||||
|
|
||||||
local gitserver=""
|
local gitserver=""
|
||||||
@@ -855,21 +866,20 @@ parse_issue_ref_from_message() {
|
|||||||
local repo=""
|
local repo=""
|
||||||
local issue_number=""
|
local issue_number=""
|
||||||
|
|
||||||
if echo "$message" | grep -qE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(issues|pull)/[0-9]+'; then
|
if [[ "$message" =~ (https?://)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)/(issues|pull)/([0-9]+) ]]; then
|
||||||
gitserver=$(echo "$message" | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+' | head -1 | sed 's/\/[^/]*\/[^/]*$//')
|
gitserver="${BASH_REMATCH[2]}"
|
||||||
local full_path=$(echo "$message" | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(issues|pull)/[0-9]+' | head -1)
|
owner="${BASH_REMATCH[3]}"
|
||||||
owner=$(echo "$full_path" | cut -d'/' -f2)
|
repo="${BASH_REMATCH[4]}"
|
||||||
repo=$(echo "$full_path" | cut -d'/' -f3)
|
issue_number="${BASH_REMATCH[6]}"
|
||||||
issue_number=$(echo "$full_path" | grep -oE '[0-9]+$' | head -1)
|
elif [[ "$message" =~ (https?://)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)#([0-9]+) ]]; then
|
||||||
elif echo "$message" | grep -qE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#[0-9]+'; then
|
gitserver="${BASH_REMATCH[2]}"
|
||||||
gitserver=$(echo "$message" | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+' | head -1)
|
owner="${BASH_REMATCH[3]}"
|
||||||
owner=$(echo "$gitserver" | cut -d'/' -f2)
|
repo="${BASH_REMATCH[4]}"
|
||||||
repo=$(echo "$gitserver" | cut -d'/' -f3)
|
issue_number="${BASH_REMATCH[5]}"
|
||||||
issue_number=$(echo "$message" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | head -1)
|
elif [[ "$message" =~ ([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)#([0-9]+) ]]; then
|
||||||
elif echo "$message" | grep -qE '[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#([0-9]+)'; then
|
owner="${BASH_REMATCH[1]}"
|
||||||
owner=$(echo "$message" | grep -oE '[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#' | sed 's/#$//' | cut -d'/' -f1)
|
repo="${BASH_REMATCH[2]}"
|
||||||
repo=$(echo "$message" | grep -oE '[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#' | sed 's/#$//' | cut -d'/' -f2)
|
issue_number="${BASH_REMATCH[3]}"
|
||||||
issue_number=$(echo "$message" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | head -1)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${gitserver}|${owner}|${repo}|${issue_number}"
|
echo "${gitserver}|${owner}|${repo}|${issue_number}"
|
||||||
|
|||||||
@@ -43,15 +43,24 @@ kugetsu_add_notification() {
|
|||||||
notifications=$(cat "$NOTIFICATIONS_FILE")
|
notifications=$(cat "$NOTIFICATIONS_FILE")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local new_notification=$(python3 -c "import json; print(json.dumps({
|
notifications=$(echo "$notifications" | python3 -c "
|
||||||
'type': '$notification_type',
|
import json
|
||||||
'message': '$message',
|
import sys
|
||||||
'issue_ref': '$issue_ref',
|
|
||||||
'timestamp': '$timestamp',
|
notifications = json.load(sys.stdin)
|
||||||
'read': False
|
new_notification = {
|
||||||
}))")
|
'type': '$notification_type',
|
||||||
|
'message': '''$message'''.replace('\"', '\"'),
|
||||||
notifications=$(python3 -c "import json; n=json.loads('$notifications'); n.append(json.loads('$new_notification')); print(json.dumps(n[-50:] if len(n)>50 else n, indent=2))")
|
'issue_ref': '$issue_ref' if '$issue_ref' else None,
|
||||||
|
'timestamp': '$timestamp',
|
||||||
|
'read': False
|
||||||
|
}
|
||||||
|
|
||||||
|
notifications.append(new_notification)
|
||||||
|
notifications = notifications[-50:] if len(notifications) > 50 else notifications
|
||||||
|
|
||||||
|
print(json.dumps(notifications, indent=2))
|
||||||
|
")
|
||||||
|
|
||||||
echo "$notifications" > "$NOTIFICATIONS_FILE"
|
echo "$notifications" > "$NOTIFICATIONS_FILE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,13 +156,11 @@ extract_issue_ref_from_message() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$message" =~ (https?://[a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+/(issues|pull)/[0-9]+) ]]; then
|
if [[ "$message" =~ (https?://)?([a-zA-Z0-9.-]+)/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)/(issues|pull)/([0-9]+) ]]; then
|
||||||
local url="${BASH_REMATCH[1]}"
|
local instance="${BASH_REMATCH[2]}"
|
||||||
local path=$(echo "$url" | sed 's|https\?://||' | cut -d'/' -f2-)
|
local owner="${BASH_REMATCH[3]}"
|
||||||
local instance=$(echo "$path" | cut -d'/' -f1)
|
local repo="${BASH_REMATCH[4]}"
|
||||||
local owner=$(echo "$path" | cut -d'/' -f2)
|
local num="${BASH_REMATCH[6]}"
|
||||||
local repo=$(echo "$path" | cut -d'/' -f3)
|
|
||||||
local num=$(echo "$path" | grep -oE '[0-9]+$')
|
|
||||||
echo "${instance}/${owner}/${repo}#${num}"
|
echo "${instance}/${owner}/${repo}#${num}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -248,7 +246,7 @@ cmd_start() {
|
|||||||
local before_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
local before_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
||||||
local before_set="|$before_sessions|"
|
local before_set="|$before_sessions|"
|
||||||
|
|
||||||
create_worktree "$issue_ref"
|
create_worktree "$issue_ref" "$WORKTREES_DIR"
|
||||||
|
|
||||||
local after_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
local after_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
||||||
local new_session_id=""
|
local new_session_id=""
|
||||||
@@ -481,10 +479,6 @@ cmd_destroy() {
|
|||||||
local target="${1:-}"
|
local target="${1:-}"
|
||||||
local force=false
|
local force=false
|
||||||
|
|
||||||
if [ "$target" = "--base" ]; then
|
|
||||||
target=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$2" = "-y" ]; then
|
if [ "$2" = "-y" ]; then
|
||||||
force=true
|
force=true
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ issue_ref_to_worktree_path() {
|
|||||||
local issue_ref="$1"
|
local issue_ref="$1"
|
||||||
local parent_dir="${2:-$WORKTREES_DIR}"
|
local parent_dir="${2:-$WORKTREES_DIR}"
|
||||||
local worktree_name=$(issue_ref_to_worktree_name "$issue_ref")
|
local worktree_name=$(issue_ref_to_worktree_name "$issue_ref")
|
||||||
echo "$parent_dir/.kugetsu-worktrees/$worktree_name"
|
echo "$parent_dir/$worktree_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_ref_to_branch_name() {
|
issue_ref_to_branch_name() {
|
||||||
@@ -41,7 +41,7 @@ get_repo_url() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local instance=$(echo "$issue_ref" | cut -d'/' -f1 | cut -d'#' -f1)
|
local instance=$(echo "$issue_ref" | cut -d'/' -f1 | cut -d'#' -f1)
|
||||||
local rest=$(echo "$issue_ref" | sed 's/.*\///' | sed 's/#.*//')
|
local rest=$(echo "$issue_ref" | sed 's/^[^\/]*\///' | sed 's/#.*//')
|
||||||
|
|
||||||
if [ -n "${GIT_SERVERS[$instance]:-}" ]; then
|
if [ -n "${GIT_SERVERS[$instance]:-}" ]; then
|
||||||
echo "${GIT_SERVERS[$instance]}/${rest}.git"
|
echo "${GIT_SERVERS[$instance]}/${rest}.git"
|
||||||
|
|||||||
298
skills/kugetsu/tests/test-git-url-parsing.sh
Normal file
298
skills/kugetsu/tests/test-git-url-parsing.sh
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Git URL Parsing Tests for kugetsu
|
||||||
|
# Tests all functions that parse or construct git URLs and issue refs
|
||||||
|
#
|
||||||
|
# Run with: bash skills/kugetsu/tests/test-git-url-parsing.sh
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
source "$SCRIPT_DIR/../scripts/kugetsu-config.sh"
|
||||||
|
source "$SCRIPT_DIR/../scripts/kugetsu-worktree.sh"
|
||||||
|
source "$SCRIPT_DIR/../scripts/kugetsu-session.sh"
|
||||||
|
|
||||||
|
PASS=0
|
||||||
|
FAIL=0
|
||||||
|
|
||||||
|
pass() {
|
||||||
|
echo "PASS: $1"
|
||||||
|
PASS=$((PASS + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
echo "FAIL: $1"
|
||||||
|
echo " Expected: $2"
|
||||||
|
echo " Got: $3"
|
||||||
|
FAIL=$((FAIL + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "=== Git URL Parsing Test Suite ==="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test: get_repo_url with standard GitHub issue ref
|
||||||
|
echo "--- Test: get_repo_url with github.com ---"
|
||||||
|
result=$(get_repo_url "github.com/shoko/kugetsu#14")
|
||||||
|
expected="https://github.com/shoko/kugetsu.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url standard github issue ref"
|
||||||
|
else
|
||||||
|
fail "get_repo_url standard github issue ref" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with custom instance
|
||||||
|
echo "--- Test: get_repo_url with git.fbrns.co ---"
|
||||||
|
result=$(get_repo_url "git.fbrns.co/shoko/kugetsu#158")
|
||||||
|
expected="https://git.fbrns.co/shoko/kugetsu.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url custom instance issue ref (ISSUE #181)"
|
||||||
|
else
|
||||||
|
fail "get_repo_url custom instance issue ref (ISSUE #181)" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with gitlab.com (if configured)
|
||||||
|
echo "--- Test: get_repo_url with gitlab.com ---"
|
||||||
|
if [ -n "${GIT_SERVERS[gitlab.com]:-}" ]; then
|
||||||
|
result=$(get_repo_url "gitlab.com/someuser/somerepo#42")
|
||||||
|
expected="https://gitlab.com/someuser/somerepo.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url gitlab.com issue ref"
|
||||||
|
else
|
||||||
|
fail "get_repo_url gitlab.com issue ref" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "SKIP: get_repo_url gitlab.com (not configured in GIT_SERVERS)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with bitbucket.org (if configured)
|
||||||
|
echo "--- Test: get_repo_url with bitbucket.org ---"
|
||||||
|
if [ -n "${GIT_SERVERS[bitbucket.org]:-}" ]; then
|
||||||
|
result=$(get_repo_url "bitbucket.org/myteam/myproject#7")
|
||||||
|
expected="https://bitbucket.org/myteam/myproject.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url bitbucket.org issue ref"
|
||||||
|
else
|
||||||
|
fail "get_repo_url bitbucket.org issue ref" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "SKIP: get_repo_url bitbucket.org (not configured in GIT_SERVERS)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with large issue number
|
||||||
|
echo "--- Test: get_repo_url with large issue number ---"
|
||||||
|
result=$(get_repo_url "github.com/shoko/kugetsu#999999")
|
||||||
|
expected="https://github.com/shoko/kugetsu.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url with large issue number"
|
||||||
|
else
|
||||||
|
fail "get_repo_url with large issue number" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_worktree_name standard
|
||||||
|
echo "--- Test: issue_ref_to_worktree_name standard ---"
|
||||||
|
result=$(issue_ref_to_worktree_name "github.com/shoko/kugetsu#14")
|
||||||
|
expected="github.com-shoko-kugetsu-14"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_worktree_name standard"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_worktree_name standard" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_worktree_name with custom instance
|
||||||
|
echo "--- Test: issue_ref_to_worktree_name custom instance ---"
|
||||||
|
result=$(issue_ref_to_worktree_name "git.fbrns.co/shoko/kugetsu#158")
|
||||||
|
expected="git.fbrns.co-shoko-kugetsu-158"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_worktree_name custom instance"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_worktree_name custom instance" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_branch_name with number
|
||||||
|
echo "--- Test: issue_ref_to_branch_name with number ---"
|
||||||
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#14")
|
||||||
|
expected="fix/issue-14"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_branch_name with number"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_branch_name with number" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_branch_name with discuss suffix
|
||||||
|
# Note: #-discuss falls through to fix/issue-temp because #[^-]+$ doesn't match #-<text-with-hyphens>
|
||||||
|
echo "--- Test: issue_ref_to_branch_name with discuss suffix ---"
|
||||||
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#-discuss")
|
||||||
|
expected="fix/issue-temp"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_branch_name with discuss suffix"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_branch_name with discuss suffix" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_branch_name with identifier that has no hyphens
|
||||||
|
echo "--- Test: issue_ref_to_branch_name with pure identifier ---"
|
||||||
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#someid")
|
||||||
|
expected="fix/someid"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_branch_name with pure identifier"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_branch_name with pure identifier" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_branch_name without number
|
||||||
|
echo "--- Test: issue_ref_to_branch_name without number ---"
|
||||||
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#abc")
|
||||||
|
expected="fix/abc"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_branch_name without number"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_branch_name without number" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: extract_issue_ref_from_message with short form
|
||||||
|
echo "--- Test: extract_issue_ref_from_message short form ---"
|
||||||
|
result=$(extract_issue_ref_from_message "github.com/shoko/kugetsu#14")
|
||||||
|
expected="github.com/shoko/kugetsu#14"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "extract_issue_ref_from_message short form"
|
||||||
|
else
|
||||||
|
fail "extract_issue_ref_from_message short form" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: extract_issue_ref_from_message with https URL
|
||||||
|
echo "--- Test: extract_issue_ref_from_message with https URL ---"
|
||||||
|
result=$(extract_issue_ref_from_message "https://github.com/shoko/kugetsu/issues/14")
|
||||||
|
expected="github.com/shoko/kugetsu#14"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "extract_issue_ref_from_message with https URL"
|
||||||
|
else
|
||||||
|
fail "extract_issue_ref_from_message with https URL" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: extract_issue_ref_from_message with custom instance
|
||||||
|
echo "--- Test: extract_issue_ref_from_message custom instance ---"
|
||||||
|
result=$(extract_issue_ref_from_message "https://git.fbrns.co/shoko/kugetsu/issues/158")
|
||||||
|
expected="git.fbrns.co/shoko/kugetsu#158"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "extract_issue_ref_from_message custom instance"
|
||||||
|
else
|
||||||
|
fail "extract_issue_ref_from_message custom instance" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: extract_issue_ref_from_message with empty message
|
||||||
|
echo "--- Test: extract_issue_ref_from_message empty message ---"
|
||||||
|
result=$(extract_issue_ref_from_message "")
|
||||||
|
expected=""
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "extract_issue_ref_from_message empty message"
|
||||||
|
else
|
||||||
|
fail "extract_issue_ref_from_message empty message" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: extract_issue_ref_from_message with no issue ref
|
||||||
|
echo "--- Test: extract_issue_ref_from_message no issue ref ---"
|
||||||
|
result=$(extract_issue_ref_from_message "Just a regular message without any issue reference")
|
||||||
|
expected=""
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "extract_issue_ref_from_message no issue ref"
|
||||||
|
else
|
||||||
|
fail "extract_issue_ref_from_message no issue ref" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: extract_issue_ref_from_message with gitlab URL
|
||||||
|
echo "--- Test: extract_issue_ref_from_message gitlab URL ---"
|
||||||
|
result=$(extract_issue_ref_from_message "https://gitlab.com/someuser/somerepo/issues/42")
|
||||||
|
expected="gitlab.com/someuser/somerepo#42"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "extract_issue_ref_from_message gitlab URL"
|
||||||
|
else
|
||||||
|
fail "extract_issue_ref_from_message gitlab URL" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: validate_issue_ref valid format
|
||||||
|
echo "--- Test: validate_issue_ref valid format ---"
|
||||||
|
if validate_issue_ref "github.com/shoko/kugetsu#14" 2>/dev/null; then
|
||||||
|
pass "validate_issue_ref valid format"
|
||||||
|
else
|
||||||
|
fail "validate_issue_ref valid format" "exit 0" "exit non-zero"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: validate_issue_ref invalid format (missing parts)
|
||||||
|
echo "--- Test: validate_issue_ref invalid format ---"
|
||||||
|
if ! validate_issue_ref "invalid-ref" 2>/dev/null; then
|
||||||
|
pass "validate_issue_ref invalid format"
|
||||||
|
else
|
||||||
|
fail "validate_issue_ref invalid format" "exit non-zero" "exit 0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: issue_ref_to_filename
|
||||||
|
echo "--- Test: issue_ref_to_filename ---"
|
||||||
|
result=$(issue_ref_to_filename "github.com/shoko/kugetsu#14")
|
||||||
|
expected="github.com-shoko-kugetsu-14.json"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "issue_ref_to_filename"
|
||||||
|
else
|
||||||
|
fail "issue_ref_to_filename" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: filename_to_issue_ref
|
||||||
|
echo "--- Test: filename_to_issue_ref ---"
|
||||||
|
result=$(filename_to_issue_ref "github.com-shoko-kugetsu-14.json")
|
||||||
|
expected="github.com/shoko/kugetsu#14"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "filename_to_issue_ref"
|
||||||
|
else
|
||||||
|
fail "filename_to_issue_ref" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with org having hyphen
|
||||||
|
echo "--- Test: get_repo_url with hyphenated org ---"
|
||||||
|
result=$(get_repo_url "github.com/my-org/my-repo#1")
|
||||||
|
expected="https://github.com/my-org/my-repo.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url with hyphenated org"
|
||||||
|
else
|
||||||
|
fail "get_repo_url with hyphenated org" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with repo having dots
|
||||||
|
echo "--- Test: get_repo_url with dotted repo ---"
|
||||||
|
result=$(get_repo_url "github.com/shoko/kugetsu.utils#5")
|
||||||
|
expected="https://github.com/shoko/kugetsu.utils.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url with dotted repo"
|
||||||
|
else
|
||||||
|
fail "get_repo_url with dotted repo" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with underscore in username
|
||||||
|
echo "--- Test: get_repo_url with underscore in user ---"
|
||||||
|
result=$(get_repo_url "github.com/my_user/my_repo#10")
|
||||||
|
expected="https://github.com/my_user/my_repo.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url with underscore in user"
|
||||||
|
else
|
||||||
|
fail "get_repo_url with underscore in user" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test: get_repo_url with instance not in GIT_SERVERS (fallback)
|
||||||
|
echo "--- Test: get_repo_url with unknown instance ---"
|
||||||
|
result=$(get_repo_url "unknown.example.com/owner/repo#1")
|
||||||
|
expected="https://unknown.example.com/owner/repo.git"
|
||||||
|
if [ "$result" = "$expected" ]; then
|
||||||
|
pass "get_repo_url with unknown instance"
|
||||||
|
else
|
||||||
|
fail "get_repo_url with unknown instance" "$expected" "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Test Results ==="
|
||||||
|
echo "Passed: $PASS"
|
||||||
|
echo "Failed: $FAIL"
|
||||||
|
|
||||||
|
if [ $FAIL -eq 0 ]; then
|
||||||
|
echo "All tests passed!"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Some tests failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user