Compare commits
11 Commits
c1385f22fd
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99d09c7dda | ||
|
|
28b343f817 | ||
|
|
836fde07fc | ||
|
|
c8bb0b36f4 | ||
| 937b7c69de | |||
|
|
2051266809 | ||
| 80a3228be9 | |||
|
|
d68a63af41 | ||
| 56310755b8 | |||
|
|
fb33be3a64 | ||
| 1b19c9a92c |
@@ -854,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=""
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -201,6 +199,45 @@ cmd_delegate() {
|
|||||||
echo "Delegated to PM agent (logged to $(basename "$log_file"))"
|
echo "Delegated to PM agent (logged to $(basename "$log_file"))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_dev_agent_message() {
|
||||||
|
local issue_ref="$1"
|
||||||
|
local user_message="${2:-}"
|
||||||
|
|
||||||
|
local instance=$(echo "$issue_ref" | cut -d'/' -f1 | cut -d'#' -f1)
|
||||||
|
local owner=$(echo "$issue_ref" | cut -d'/' -f2)
|
||||||
|
local repo=$(echo "$issue_ref" | cut -d'/' -f3 | cut -d'#' -f1)
|
||||||
|
local number=$(echo "$issue_ref" | grep -oE '#[0-9]+$' | tr -d '#')
|
||||||
|
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref")
|
||||||
|
|
||||||
|
local base_message="You are assigned to work on $issue_ref.
|
||||||
|
|
||||||
|
Workflow:
|
||||||
|
1. Read the issue at $instance/$owner/$repo/issues/$number AND all comments on that issue
|
||||||
|
2. Check if a PR already exists for this issue
|
||||||
|
- If PR exists and is open, review it and learn from it
|
||||||
|
- If PR makes sense to continue, work on it instead
|
||||||
|
- If PR is not worth continuing, create a new branch/PR but explain in PR description why you're creating a new one instead of continuing the existing PR
|
||||||
|
3. Read README.md (if exists) to understand the general concept of this repository
|
||||||
|
4. Read CONTRIBUTING.md (if exists) to understand how to contribute
|
||||||
|
- If CONTRIBUTING.md doesn't exist, follow steps 5-9 as your guideline
|
||||||
|
5. Explore the repository to understand the codebase
|
||||||
|
6. If anything is unclear, post a comment on the issue asking for clarification before implementing
|
||||||
|
7. Implement the solution
|
||||||
|
8. Create a branch named fix/issue-$number and implement the fix
|
||||||
|
9. Create a PR when the implementation is complete
|
||||||
|
|
||||||
|
Work directory: $worktree_path"
|
||||||
|
|
||||||
|
if [ -n "$user_message" ]; then
|
||||||
|
echo "$base_message
|
||||||
|
|
||||||
|
Additional instructions from delegator:
|
||||||
|
$user_message"
|
||||||
|
else
|
||||||
|
echo "$base_message"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cmd_start() {
|
cmd_start() {
|
||||||
local issue_ref="${1:-}"
|
local issue_ref="${1:-}"
|
||||||
local message="${2:-}"
|
local message="${2:-}"
|
||||||
@@ -248,7 +285,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=""
|
||||||
@@ -272,6 +309,12 @@ cmd_start() {
|
|||||||
|
|
||||||
add_issue_to_index "$issue_ref" "$session_file"
|
add_issue_to_index "$issue_ref" "$session_file"
|
||||||
|
|
||||||
|
local dev_message=$(build_dev_agent_message "$issue_ref" "$message")
|
||||||
|
|
||||||
|
load_agent_env "dev"
|
||||||
|
|
||||||
|
(cd "$worktree_path" && nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$dev_message' --continue --session '$new_session_id'" >> "$LOGS_DIR/dev-$new_session_id.log" 2>&1 &) && disown
|
||||||
|
|
||||||
echo "Session started for '$issue_ref': $new_session_id"
|
echo "Session started for '$issue_ref': $new_session_id"
|
||||||
echo "Worktree: $worktree_path"
|
echo "Worktree: $worktree_path"
|
||||||
}
|
}
|
||||||
@@ -317,19 +360,16 @@ cmd_continue() {
|
|||||||
|
|
||||||
local opencode_session_id=$(python3 -c "import json; print(json.load(open('$session_path')).get('opencode_session_id', ''))" 2>/dev/null || echo "")
|
local opencode_session_id=$(python3 -c "import json; print(json.load(open('$session_path')).get('opencode_session_id', ''))" 2>/dev/null || echo "")
|
||||||
local worktree_path=$(python3 -c "import json; print(json.load(open('$session_path')).get('worktree_path', ''))" 2>/dev/null || echo "")
|
local worktree_path=$(python3 -c "import json; print(json.load(open('$session_path')).get('worktree_path', ''))" 2>/dev/null || echo "")
|
||||||
|
local issue_ref=$(python3 -c "import json; print(json.load(open('$session_path')).get('issue_ref', ''))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
if [ -z "$message" ]; then
|
||||||
|
message=$(build_dev_agent_message "$issue_ref" "")
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
||||||
if [ -n "$message" ]; then
|
(cd "$worktree_path" && nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &) && disown
|
||||||
(cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" "$@")
|
|
||||||
else
|
else
|
||||||
(cd "$worktree_path" && opencode --continue --session "$opencode_session_id" "$@")
|
nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 & && disown
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ -n "$message" ]; then
|
|
||||||
opencode run "$message" --continue --session "$opencode_session_id" "$@"
|
|
||||||
else
|
|
||||||
opencode --continue --session "$opencode_session_id" "$@"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,10 +521,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