Browse Source

fix bugs

sign sync commits

Nostr-Signature: 3b05eb0074772bd7d3322e0a32ef8932dbafa2334ff51a75ed5159fcdfdb3558 573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc b7bdc3272a6daddf409dc519de6e06a4ee85407a14790996be7c5039a00358106285a8fc00084d9016587df529d7026f28108384976198789aa1fd60140a5738
main
Silberengel 3 weeks ago
parent
commit
ad758da8a9
  1. 1
      nostr/commit-signatures.jsonl
  2. 177
      scripts/sync-cli.sh
  3. 12
      src/routes/api/repos/[npub]/[repo]/settings/+server.ts
  4. 7
      src/routes/signup/+page.svelte

1
nostr/commit-signatures.jsonl

@ -83,3 +83,4 @@ @@ -83,3 +83,4 @@
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1772003001,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","fix local cloning"]],"content":"Signed commit: fix local cloning","id":"0e7b4f06276988a2caf1c8fa9f6ba4a1cb683033c0714cc88699e3a4bda67d68","sig":"3c46ff9412a72f3ca39d216d6bd2eee7b9f70331fe8c0d557ee8339be4c05d03fe949e3aaef6e29126d4174b9f6d10de9e605273918106b9d40bc81cfaa1d290"}
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1772004731,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","increase granularity of repo and event visbility"]],"content":"Signed commit: increase granularity of repo and event visbility","id":"1d96ac54006360066d403209f6893faffec0f8f389ea99af73447a017d5ff03a","sig":"44c53034e91ef444368a5034e3a12024bf893f3e518eef903aecbbb453e612f5f198601daf7b9d8da3bc48ca77ec4d18795f111211c3bc32ed4b6c0707a7a905"}
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1772005973,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","update the API"]],"content":"Signed commit: update the API","id":"09329cf7eb8c228e87e365b0d7a4d052ddb08b3cf7f75162b2e9b8dd77e917a0","sig":"1a1b40b18dbd744bd4043f0f18d5945ba7d1f738d36bb8457c4ec806832cd1b44ed36417c24d01511fa7fddfa33c376bf24c2fdf478bf1ab015cf4c524aac7e8"}
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1772008194,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","revamp tutoral and ReadMe documentation\nupdate API docs"]],"content":"Signed commit: revamp tutoral and ReadMe documentation\nupdate API docs","id":"9d1fb9db75e26a5fcdcab54253ef1c6126ea1e01e98728554435e655354f6238","sig":"0cfde0ac8a7083479c982c7f212a91eee7e8ed33b43b30291677fe3a126638ae4fde03893aa5d492f8f6fc8e066b7c46bd6f07246376a5d9e56becc73e4e48d8"}

177
scripts/sync-cli.sh

@ -50,112 +50,117 @@ git add -A @@ -50,112 +50,117 @@ git add -A
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected, committing..."
COMMIT_MSG="Sync from gitrepublic-web monorepo - $(date '+%Y-%m-%d %H:%M:%S')"
git commit -m "$COMMIT_MSG"
echo "✅ Committed changes"
else
echo "✅ No changes to commit (files are up to date)"
fi
# Get all remotes and push to each one
REMOTES="$(git remote)"
CURRENT_BRANCH="$(git branch --show-current || echo 'master')"
if [ -z "$REMOTES" ]; then
echo "ℹ No remotes configured"
exit 0
fi
echo ""
echo "Pushing to remotes..."
# Check if GitRepublic commit-msg hook is installed
HOOK_INSTALLED=false
HOOK_PATH=""
# Fetch from all remotes first
for remote in $REMOTES; do
echo "Fetching from $remote..."
git fetch "$remote" 2>/dev/null || true
done
# Check if remotes have commits local doesn't have (diverged history)
echo ""
echo "Checking for diverged history..."
for remote in $REMOTES; do
REMOTE_BRANCH="${remote}/${CURRENT_BRANCH}"
if git rev-parse --verify "$REMOTE_BRANCH" >/dev/null 2>&1; then
BEHIND=$(git rev-list --count HEAD.."$REMOTE_BRANCH" 2>/dev/null || echo "0")
AHEAD=$(git rev-list --count "$REMOTE_BRANCH"..HEAD 2>/dev/null || echo "0")
if [ "$BEHIND" -gt 0 ]; then
echo " $remote has $BEHIND commit(s) that local doesn't have"
echo " Local has $AHEAD commit(s) that $remote doesn't have"
echo " Histories have diverged - need to merge or rebase"
# Check for local hook
if [ -f ".git/hooks/commit-msg" ]; then
# Check if it's the GitRepublic hook
if grep -q "git-commit-msg-hook\|gitrepublic" .git/hooks/commit-msg 2>/dev/null; then
HOOK_INSTALLED=true
HOOK_PATH=".git/hooks/commit-msg"
fi
fi
done
# Push to all remotes
for remote in $REMOTES; do
echo ""
echo "Pushing to $remote ($CURRENT_BRANCH)..."
# Check if local is ahead of remote
REMOTE_BRANCH="${remote}/${CURRENT_BRANCH}"
if git rev-parse --verify "$REMOTE_BRANCH" >/dev/null 2>&1; then
AHEAD=$(git rev-list --count "$REMOTE_BRANCH"..HEAD 2>/dev/null || echo "0")
if [ "$AHEAD" -gt 0 ]; then
echo " Local is $AHEAD commit(s) ahead of $remote"
# Check for global hook
if [ "$HOOK_INSTALLED" = false ]; then
GLOBAL_HOOKS_PATH="$(git config --global --get core.hooksPath 2>/dev/null || echo "$HOME/.git-hooks")"
if [ -f "$GLOBAL_HOOKS_PATH/commit-msg" ]; then
if grep -q "git-commit-msg-hook\|gitrepublic" "$GLOBAL_HOOKS_PATH/commit-msg" 2>/dev/null; then
HOOK_INSTALLED=true
HOOK_PATH="$GLOBAL_HOOKS_PATH/commit-msg"
fi
fi
fi
# Try to push current branch (master) - don't use timeout as it might interfere with SSH
PUSH_OUTPUT=$(git push "$remote" "$CURRENT_BRANCH" 2>&1)
PUSH_EXIT=$?
# Try to find and install the hook if not installed
if [ "$HOOK_INSTALLED" = false ]; then
# Look for gitrepublic-cli hook script
POSSIBLE_HOOK_PATHS=(
"$CLI_DIR/scripts/git-commit-msg-hook.js"
"$REPO_ROOT/gitrepublic-cli/scripts/git-commit-msg-hook.js"
"$(dirname "$(command -v gitrep 2>/dev/null || command -v gitrepublic 2>/dev/null || echo '')")/../scripts/git-commit-msg-hook.js"
)
for hook_script in "${POSSIBLE_HOOK_PATHS[@]}"; do
if [ -f "$hook_script" ]; then
echo "Installing GitRepublic commit signing hook..."
mkdir -p .git/hooks
# Create symlink to the hook script
if ln -sf "$hook_script" .git/hooks/commit-msg 2>/dev/null; then
HOOK_INSTALLED=true
HOOK_PATH=".git/hooks/commit-msg"
echo "✅ Commit signing hook installed"
break
fi
fi
done
fi
if [ $PUSH_EXIT -eq 0 ]; then
# Check if output says "already up to date"
if echo "$PUSH_OUTPUT" | grep -qi "already up to date\|Everything up-to-date"; then
echo " $remote is already up to date"
# Make commit (hook will be called automatically by git if installed)
if [ "$HOOK_INSTALLED" = true ]; then
echo "Committing with GitRepublic Nostr signing..."
git commit -m "$COMMIT_MSG"
else
echo "✅ Successfully pushed to $remote"
echo "$PUSH_OUTPUT" | grep -v "^$" | head -3
echo "⚠ Warning: GitRepublic commit signing hook not found"
echo " Commits will not be signed with Nostr keys"
echo " Install gitrepublic-cli and run 'gitrep setup' to enable commit signing"
git commit -m "$COMMIT_MSG"
fi
else
# Push failed - show the full error
echo " Push to $remote failed:"
echo "$PUSH_OUTPUT" | sed 's/^/ /'
echo "✅ Committed changes"
else
echo "✅ No changes to commit (files are up to date)"
fi
# Check if it's a non-fast-forward (diverged history)
if echo "$PUSH_OUTPUT" | grep -qi "non-fast-forward\|behind.*remote\|diverged"; then
REMOTE_BRANCH="${remote}/${CURRENT_BRANCH}"
BEHIND=$(git rev-list --count HEAD.."$REMOTE_BRANCH" 2>/dev/null || echo "0")
AHEAD=$(git rev-list --count "$REMOTE_BRANCH"..HEAD 2>/dev/null || echo "0")
# Get current branch
CURRENT_BRANCH="$(git branch --show-current || echo 'master')"
if [ "$BEHIND" -gt 0 ]; then
echo ""
echo " Histories have diverged:"
echo " - Remote has $BEHIND commit(s) you don't have"
echo " - You have $AHEAD commit(s) remote doesn't have"
# Check if gitrep is available
if ! command -v gitrep >/dev/null 2>&1 && ! command -v gitrepublic >/dev/null 2>&1; then
echo "⚠ Warning: gitrep command not found. Falling back to git push."
echo " Install gitrepublic-cli to use 'gitrep push-all' for better multi-remote support."
echo ""
echo " For sync script, attempting force push to overwrite remote with local..."
echo " (This makes remote match the monorepo - monorepo is source of truth)"
# Force push to make remote match local (monorepo is source of truth)
if FORCE_PUSH_OUTPUT=$(git push -f "$remote" "$CURRENT_BRANCH" 2>&1); then
echo "✅ Successfully force-pushed to $remote"
echo "$FORCE_PUSH_OUTPUT" | grep -v "^$" | head -2 | sed 's/^/ /'
else
echo "⚠ Force push also failed:"
echo "$FORCE_PUSH_OUTPUT" | sed 's/^/ /'
fi
# Fallback to old behavior
REMOTES="$(git remote)"
if [ -z "$REMOTES" ]; then
echo "ℹ No remotes configured"
exit 0
fi
elif echo "$PUSH_OUTPUT" | grep -qi "refspec\|branch.*not found\|no such branch"; then
# Branch doesn't exist on remote - set upstream
echo " Attempting to set upstream and push..."
if git push -u "$remote" "$CURRENT_BRANCH" 2>&1; then
echo "✅ Successfully pushed to $remote (with upstream set)"
echo "Pushing to remotes using git push..."
for remote in $REMOTES; do
echo "Pushing to $remote ($CURRENT_BRANCH)..."
if git push "$remote" "$CURRENT_BRANCH" 2>&1; then
echo "✅ Successfully pushed to $remote"
else
echo " Still failed after setting upstream"
echo " Failed to push to $remote"
fi
done
else
# Use gitrep push-all
GITREP_CMD=""
if command -v gitrep >/dev/null 2>&1; then
GITREP_CMD="gitrep"
elif command -v gitrepublic >/dev/null 2>&1; then
GITREP_CMD="gitrepublic"
fi
echo ""
echo "Pushing to all remotes using $GITREP_CMD push-all..."
# Use gitrep push-all to push to all remotes
# This handles reachability checks, error handling, and provides better output
if $GITREP_CMD push-all "$CURRENT_BRANCH" 2>&1; then
echo "✅ Successfully pushed to all remotes"
else
PUSH_EXIT=$?
echo " Push to some remotes may have failed (exit code: $PUSH_EXIT)"
# Don't exit with error - gitrep push-all may have succeeded for some remotes
fi
done
fi
echo ""
echo "✅ Sync complete!"

12
src/routes/api/repos/[npub]/[repo]/settings/+server.ts

@ -209,7 +209,9 @@ export const POST: RequestHandler = createRepoPostHandler( @@ -209,7 +209,9 @@ export const POST: RequestHandler = createRepoPostHandler(
// Determine which relays to publish to based on visibility
const { getRelaysForEventPublishing } = await import('$lib/utils/repo-visibility.js');
const relaysToPublish = getRelaysForEventPublishing(signedEvent, userRelays);
const visibilityRelays = getRelaysForEventPublishing(signedEvent);
// Combine visibility relays with user relays
const relaysToPublish = visibilityRelays.length > 0 ? combineRelays([...visibilityRelays, ...userRelays]) : [];
// Publish to relays (if not private)
if (relaysToPublish.length > 0) {
@ -221,10 +223,12 @@ export const POST: RequestHandler = createRepoPostHandler( @@ -221,10 +223,12 @@ export const POST: RequestHandler = createRepoPostHandler(
}
// Save to repository (via announcement manager)
const { announcementManager } = await import('$lib/services/git/announcement-manager.js');
const repoPath = `${process.env.GIT_REPO_ROOT || '/repos'}/${context.npub}/${context.repo}.git`;
const { AnnouncementManager } = await import('$lib/services/git/announcement-manager.js');
const repoRoot = process.env.GIT_REPO_ROOT || '/repos';
const repoPath = `${repoRoot}/${context.npub}/${context.repo}.git`;
const announcementManager = new AnnouncementManager(repoRoot);
try {
await announcementManager.saveEvent(signedEvent, repoPath);
await announcementManager.ensureAnnouncementInRepo(repoPath, signedEvent);
} catch (err) {
logger.error({ error: err, npub: context.npub, repo: context.repo }, 'Failed to save settings update to repository');
// Don't fail the request - event was published to relays

7
src/routes/signup/+page.svelte

@ -1026,7 +1026,8 @@ @@ -1026,7 +1026,8 @@
}
// Public and unlisted repos are always visible
if (repoVisibility === 'public' || repoVisibility === 'unlisted') return event;
// Use array includes to avoid TypeScript narrowing issues
if (['public', 'unlisted'].includes(repoVisibility)) return event;
// Restricted and private repos: only show if user is owner
if (userPubkeyHex && event.pubkey === userPubkeyHex) {
@ -2970,7 +2971,7 @@ @@ -2970,7 +2971,7 @@
{#if visibility === 'unlisted' || visibility === 'restricted' || visibility === 'private'}
<div class="form-group">
<label>
<div class="label">
Project Relay(s) {#if visibility === 'unlisted' || visibility === 'restricted'}*{/if}
<small>
{#if visibility === 'unlisted' || visibility === 'restricted'}
@ -2979,7 +2980,7 @@ @@ -2979,7 +2980,7 @@
Optional for private repositories. If provided, events will be published to these relays (otherwise git-only).
{/if}
</small>
</label>
</div>
{#each projectRelays as projectRelay, index}
<div class="input-group">
<input

Loading…
Cancel
Save