mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix Nostr git URL format and npub decoding
- Change URL format from `nostr://<npub>/<domain>/<repo>` to `nostr://<hex-pubkey>/<repo-id>` - Auto-convert npub to hex pubkey in URL parsing - Fix hanging issue caused by invalid pubkey format in repository queries - Update parseRepoUrl in types.ts to handle npub decoding - Update PullRequestDialog to decode npub before querying - Update NOSTR_GIT.md with correct URL format examples The correct format is: - `nostr://<hex-pubkey>/<repo-id>` (preferred) - `nostr://<npub>/<repo-id>` (auto-converted to hex) Fixes the issue where patch publishing would hang indefinitely when trying to query repositories with npub-formatted URLs.
This commit is contained in:
1 parent
c364b3f796
commit
5047d95cf4
4 files changed
+52
-9
No files matched your search
@@ -424,7 +424,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
});
|
||||
|
||||
// Set origin remote to Nostr URL
|
||||
const nostrUrl = `nostr://${nip19.npubEncode(user.pubkey)}/git.shakespeare.diy/${projectId}`;
|
||||
// Format: nostr://<hex-pubkey>/<repo-id>
|
||||
const nostrUrl = `nostr://${user.pubkey}/${projectId}`;
|
||||
|
||||
try {
|
||||
// Remove existing origin if it exists
|
||||
|
||||
@@ -38,6 +38,7 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useNostr } from '@/hooks/useNostr';
|
||||
import { findCredentialsForRepo } from '@/lib/gitCredentials';
|
||||
import { createGitHostProvider, detectGitHost, parseRepoUrl } from '@/lib/git-hosts';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
interface PullRequestDialogProps {
|
||||
projectId: string;
|
||||
@@ -207,8 +208,27 @@ export function PullRequestDialog({
|
||||
if (url.startsWith('nostr://')) {
|
||||
match = url.match(/^nostr:\/\/([^/]+)\/(.+)$/);
|
||||
if (match) {
|
||||
owner = match[1]; // pubkey in hex
|
||||
let pubkeyOrNpub = match[1];
|
||||
repo = match[2]; // repo-id (d tag)
|
||||
|
||||
// Convert npub to hex if needed
|
||||
if (pubkeyOrNpub.startsWith('npub1')) {
|
||||
try {
|
||||
const decoded = nip19.decode(pubkeyOrNpub);
|
||||
if (decoded.type === 'npub') {
|
||||
owner = decoded.data; // hex pubkey
|
||||
} else {
|
||||
throw new Error('Invalid npub');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to decode npub:', err);
|
||||
setError('Invalid npub in Nostr URL');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
owner = pubkeyOrNpub; // Already in hex format
|
||||
}
|
||||
|
||||
platform = 'nostr';
|
||||
apiUrl = ''; // Not applicable for Nostr
|
||||
console.log('Detected Nostr git:', { owner, repo });
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
/**
|
||||
* Git host provider abstraction for PR/MR operations
|
||||
*/
|
||||
@@ -131,9 +133,25 @@ export function parseRepoUrl(url: string): { owner: string; repo: string } | nul
|
||||
if (url.startsWith('nostr://')) {
|
||||
const match = url.match(/^nostr:\/\/([^/]+)\/(.+)$/);
|
||||
if (match) {
|
||||
let owner = match[1]; // pubkey in hex or npub
|
||||
const repo = match[2]; // repo-id (d tag)
|
||||
|
||||
// Convert npub to hex if needed
|
||||
if (owner.startsWith('npub1')) {
|
||||
try {
|
||||
const decoded = nip19.decode(owner);
|
||||
if (decoded.type === 'npub') {
|
||||
owner = decoded.data;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to decode npub:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
owner: match[1], // pubkey in hex
|
||||
repo: match[2], // repo-id (d tag)
|
||||
owner, // pubkey in hex
|
||||
repo, // repo-id (d tag)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user