-
Notifications
You must be signed in to change notification settings - Fork 6
fix(entrypoint): infer server url and normalize repo; docs update #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,6 +52,11 @@ validate_env() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| missing+=("GITEA_TOKEN or GITHUB_TOKEN") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check for server URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -z "$GITEA_SERVER_URL" ] && [ -z "$GITHUB_SERVER_URL" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| missing+=("GITEA_SERVER_URL or GITHUB_SERVER_URL") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check for at least one LLM API key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -z "$DEEPSEEK_API_KEY" ] && [ -z "$ANTHROPIC_API_KEY" ] && [ -z "$OPENAI_API_KEY" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| missing+=("DEEPSEEK_API_KEY, ANTHROPIC_API_KEY, or OPENAI_API_KEY") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -68,6 +73,63 @@ validate_env() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_success "Environment validated" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| infer_gitea_server_url() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$GITEA_SERVER_URL" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$GITHUB_SERVER_URL" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export GITEA_SERVER_URL="$GITHUB_SERVER_URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Best-effort inference from git remote when running locally with -v $(pwd):/workspace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -d "/workspace/.git" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+87
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local remote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remote=$(git -C /workspace remote get-url origin 2>/dev/null || true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$remote" =~ ^https?:// ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host=$(echo "$remote" | sed -E 's#^(https?://[^/]+).*#\1#') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$host" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export GITEA_SERVER_URL="$host" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_info "Inferred GITEA_SERVER_URL from git remote: $GITEA_SERVER_URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SSH-style: git@host:owner/repo.git -> assume https://host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$remote" =~ ^git@[^:]+: ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host=$(echo "$remote" | sed -E 's#^git@([^:]+):.*#\1#') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$host" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export GITEA_SERVER_URL="https://$host" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_info "Inferred GITEA_SERVER_URL from git remote: $GITEA_SERVER_URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+104
to
+108
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host=$(echo "$remote" | sed -E 's#^git@([^:]+):.*#\1#') | |
| if [ -n "$host" ]; then | |
| export GITEA_SERVER_URL="https://$host" | |
| log_info "Inferred GITEA_SERVER_URL from git remote: $GITEA_SERVER_URL" | |
| return 0 | |
| host=$(echo "$remote" | sed -E 's#^git@([A-Za-z0-9._-]+):.*#\1#') | |
| if [ -n "$host" ] && [[ "$host" =~ ^[A-Za-z0-9._-]+$ ]]; then | |
| export GITEA_SERVER_URL="https://$host" | |
| log_info "Inferred GITEA_SERVER_URL from git remote: $GITEA_SERVER_URL" | |
| return 0 | |
| else | |
| log_warn "Skipping SSH remote inference due to invalid host: '$host'" |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normalize_repo_context() function silently fails when REPO_NAME contains "owner/repo" format but the owner_part doesn't match the existing REPO_OWNER. In this case, REPO_NAME remains in "owner/repo" format instead of being normalized to just "repo", which could cause issues in tools expecting only the repository name.
For example, if REPO_NAME="alice/myrepo" and REPO_OWNER="bob", the function returns without normalizing, leaving REPO_NAME as "alice/myrepo". This might break API calls that construct paths like "/repos/{REPO_OWNER}/{REPO_NAME}" resulting in "/repos/bob/alice/myrepo".
Consider logging a warning when there's a mismatch, or explicitly handling this conflict case.
| return 0 | |
| return 0 | |
| else | |
| # Mismatch between owner in REPO_NAME and existing REPO_OWNER. | |
| # Normalize REPO_NAME to just the repo part to avoid paths like /repos/OWNER/owner/repo. | |
| log_warn "REPO_NAME owner '$owner_part' does not match REPO_OWNER '$REPO_OWNER'; using REPO_OWNER with repo '$repo_part'." | |
| export REPO_NAME="$repo_part" | |
| return 0 |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normalize_repo_context() function doesn't handle the edge case where REPO_NAME contains multiple slashes (e.g., "owner/sub/repo"). The pattern matching */* will match this case, and the parsing logic using %%/* and #*/ will split on the first and last slash respectively, potentially creating unexpected results.
For example, if REPO_NAME="org/team/myrepo", then:
- owner_part="org" (first part before first slash)
- repo_part="team/myrepo" (everything after first slash)
This would set REPO_NAME to "team/myrepo" which is still not a valid repository name. Consider adding validation to ensure REPO_NAME contains at most one slash.
| if [ -n "$REPO_NAME" ] && [[ "$REPO_NAME" == */* ]]; then | |
| local owner_part="${REPO_NAME%%/*}" | |
| local repo_part="${REPO_NAME#*/}" | |
| if [ -z "$REPO_OWNER" ]; then | |
| export REPO_OWNER="$owner_part" | |
| export REPO_NAME="$repo_part" | |
| return 0 | |
| fi | |
| if [ "$owner_part" = "$REPO_OWNER" ]; then | |
| export REPO_NAME="$repo_part" | |
| return 0 | |
| if [ -n "$REPO_NAME" ]; then | |
| # Validate that REPO_NAME contains at most one slash. | |
| # Examples of valid values: | |
| # - "myrepo" | |
| # - "myorg/myrepo" | |
| # Invalid example (multiple slashes): | |
| # - "org/team/myrepo" | |
| if [[ "$REPO_NAME" == */*/* ]]; then | |
| log_error "Invalid REPO_NAME '$REPO_NAME'. Expected 'repo' or 'owner/repo' (at most one '/')." | |
| exit 1 | |
| fi | |
| if [[ "$REPO_NAME" == */* ]]; then | |
| local owner_part="${REPO_NAME%%/*}" | |
| local repo_part="${REPO_NAME#*/}" | |
| if [ -z "$REPO_OWNER" ]; then | |
| export REPO_OWNER="$owner_part" | |
| export REPO_NAME="$repo_part" | |
| return 0 | |
| fi | |
| if [ "$owner_part" = "$REPO_OWNER" ]; then | |
| export REPO_NAME="$repo_part" | |
| return 0 | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After
infer_gitea_server_url()is called, the validation at lines 56-58 checks for both GITEA_SERVER_URL and GITHUB_SERVER_URL. However, the inference function always exports to GITEA_SERVER_URL (line 82), so if inference succeeds via GITHUB_SERVER_URL, the validation will pass even though GITHUB_SERVER_URL might not be set.This is functionally correct but could be clearer. Consider either: