git-nostr-hook 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -17
- package/lib/hook.js +17 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# git-nostr-hook
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/git-nostr-hook)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
Git hook that automatically publishes your repository state to Nostr ([NIP-34](https://github.com/nostr-protocol/nips/blob/master/34.md)) on every commit.
|
|
7
|
+
|
|
8
|
+
## Why?
|
|
9
|
+
|
|
10
|
+
Decentralize your git repository announcements. Every commit publishes a Kind 30617 event to Nostr relays, making your repository discoverable across the Nostr network without relying solely on centralized platforms like GitHub.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- **Node.js** 18+
|
|
15
|
+
- **Git** 2.9+ (for `core.hooksPath` support)
|
|
4
16
|
|
|
5
17
|
## Install
|
|
6
18
|
|
|
@@ -17,7 +29,7 @@ Set your Nostr private key:
|
|
|
17
29
|
git config --global nostr.privkey <64-char-hex-key>
|
|
18
30
|
```
|
|
19
31
|
|
|
20
|
-
Generate a key if needed:
|
|
32
|
+
Generate a new key if needed:
|
|
21
33
|
|
|
22
34
|
```bash
|
|
23
35
|
npx noskey
|
|
@@ -25,34 +37,133 @@ npx noskey
|
|
|
25
37
|
|
|
26
38
|
## Usage
|
|
27
39
|
|
|
28
|
-
Once installed, every `git commit` automatically publishes a Kind 30617 event to Nostr relays
|
|
40
|
+
Once installed, every `git commit` automatically publishes a Kind 30617 event to Nostr relays.
|
|
29
41
|
|
|
30
|
-
|
|
31
|
-
- Branch refs (like `git ls-remote`)
|
|
32
|
-
- Clone/web URLs
|
|
33
|
-
- Latest commit message
|
|
42
|
+
### Manual Run
|
|
34
43
|
|
|
35
|
-
|
|
44
|
+
Test the hook without committing:
|
|
36
45
|
|
|
37
46
|
```bash
|
|
38
|
-
git-nostr-hook
|
|
39
|
-
git-nostr-hook uninstall # Remove global git hook
|
|
40
|
-
git-nostr-hook run # Run manually
|
|
47
|
+
git-nostr-hook run
|
|
41
48
|
```
|
|
42
49
|
|
|
50
|
+
### Example Output
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
📡 git-nostr-hook
|
|
54
|
+
|
|
55
|
+
Event ID: abc123...
|
|
56
|
+
Pubkey: def456...
|
|
57
|
+
|
|
58
|
+
✓ Published to wss://relay.damus.io
|
|
59
|
+
✓ Published to wss://nos.lol
|
|
60
|
+
✓ Published to wss://relay.nostr.band
|
|
61
|
+
|
|
62
|
+
✓ Published to 3/3 relays
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Published Event
|
|
66
|
+
|
|
67
|
+
The hook publishes a Kind 30617 (NIP-34 repository announcement) event containing:
|
|
68
|
+
|
|
69
|
+
| Tag | Description |
|
|
70
|
+
|-----|-------------|
|
|
71
|
+
| `d` | Repository identifier (repo name) |
|
|
72
|
+
| `name` | Repository name |
|
|
73
|
+
| `HEAD` | Current branch reference |
|
|
74
|
+
| `clone` | Git clone URL |
|
|
75
|
+
| `web` | Web URL (GitHub, etc.) |
|
|
76
|
+
| `refs/heads/*` | Branch refs with commit SHAs |
|
|
77
|
+
|
|
78
|
+
### Example Event
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"kind": 30617,
|
|
83
|
+
"tags": [
|
|
84
|
+
["d", "my-project"],
|
|
85
|
+
["name", "my-project"],
|
|
86
|
+
["HEAD", "ref: refs/heads/main"],
|
|
87
|
+
["clone", "git@github.com:user/my-project.git"],
|
|
88
|
+
["web", "https://github.com/user/my-project"],
|
|
89
|
+
["refs/heads/main", "abc123..."]
|
|
90
|
+
],
|
|
91
|
+
"content": "Latest commit: Add new feature"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Commands
|
|
96
|
+
|
|
97
|
+
| Command | Description |
|
|
98
|
+
|---------|-------------|
|
|
99
|
+
| `git-nostr-hook install` | Install global git hook |
|
|
100
|
+
| `git-nostr-hook uninstall` | Remove global git hook |
|
|
101
|
+
| `git-nostr-hook run` | Run manually (for testing) |
|
|
102
|
+
| `git-nostr-hook help` | Show help |
|
|
103
|
+
|
|
43
104
|
## How It Works
|
|
44
105
|
|
|
45
|
-
1.
|
|
46
|
-
2.
|
|
47
|
-
3.
|
|
48
|
-
|
|
49
|
-
|
|
106
|
+
1. Installs a post-commit hook to `~/.git-hooks/`
|
|
107
|
+
2. Sets `git config --global core.hooksPath ~/.git-hooks`
|
|
108
|
+
3. On every commit, the hook:
|
|
109
|
+
- Reads private key from `git config nostr.privkey`
|
|
110
|
+
- Builds a Kind 30617 repository announcement event
|
|
111
|
+
- Signs with Schnorr signature (secp256k1)
|
|
112
|
+
- Publishes to default relays
|
|
113
|
+
|
|
114
|
+
### Default Relays
|
|
115
|
+
|
|
116
|
+
- `wss://relay.damus.io`
|
|
117
|
+
- `wss://nos.lol`
|
|
118
|
+
- `wss://relay.nostr.band`
|
|
119
|
+
|
|
120
|
+
## Troubleshooting
|
|
121
|
+
|
|
122
|
+
### "No nostr.privkey configured"
|
|
123
|
+
|
|
124
|
+
Set your private key:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
git config --global nostr.privkey <your-64-char-hex-key>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Hook not running after commit
|
|
131
|
+
|
|
132
|
+
Verify the global hooks path is set:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
git config --global core.hooksPath
|
|
136
|
+
# Should output: ~/.git-hooks
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Re-run install if needed:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git-nostr-hook install
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### "Failed to publish" errors
|
|
146
|
+
|
|
147
|
+
Check your internet connection and verify the relays are online. The hook will continue even if some relays fail.
|
|
148
|
+
|
|
149
|
+
### Using with existing git hooks
|
|
150
|
+
|
|
151
|
+
If you have existing hooks in a repository's `.git/hooks/`, note that `core.hooksPath` takes precedence. You may need to manually call your other hooks from `~/.git-hooks/post-commit`.
|
|
152
|
+
|
|
153
|
+
## Verifying Events
|
|
154
|
+
|
|
155
|
+
View your published events on Nostr clients that support NIP-34, or query directly:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Using nak (Nostr Army Knife)
|
|
159
|
+
nak req -k 30617 -a <your-pubkey> wss://relay.damus.io
|
|
160
|
+
```
|
|
50
161
|
|
|
51
162
|
## NIP-34
|
|
52
163
|
|
|
53
164
|
This implements [NIP-34](https://github.com/nostr-protocol/nips/blob/master/34.md) - Git repositories on Nostr.
|
|
54
165
|
|
|
55
|
-
Kind 30617 is a replaceable event, so each commit updates the previous announcement.
|
|
166
|
+
Kind 30617 is a **replaceable event** (per NIP-01), so each commit updates the previous announcement rather than creating duplicates.
|
|
56
167
|
|
|
57
168
|
## License
|
|
58
169
|
|
package/lib/hook.js
CHANGED
|
@@ -54,8 +54,23 @@ function buildRepoEvent(secretKey) {
|
|
|
54
54
|
];
|
|
55
55
|
|
|
56
56
|
if (remoteUrl) {
|
|
57
|
-
|
|
58
|
-
const
|
|
57
|
+
// Convert SSH to HTTPS for broader accessibility
|
|
58
|
+
const httpsUrl = remoteUrl
|
|
59
|
+
.replace(/^git@github\.com:/, 'https://github.com/')
|
|
60
|
+
.replace(/^git@([^:]+):/, 'https://$1/');
|
|
61
|
+
|
|
62
|
+
// HTTPS clone first (accessible to everyone), SSH second (for power users)
|
|
63
|
+
if (httpsUrl.startsWith('https://')) {
|
|
64
|
+
tags.push(['clone', httpsUrl]);
|
|
65
|
+
if (remoteUrl !== httpsUrl) {
|
|
66
|
+
tags.push(['clone', remoteUrl]); // Original SSH URL
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
tags.push(['clone', remoteUrl]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Web URL (without .git)
|
|
73
|
+
const webUrl = httpsUrl.replace(/\.git$/, '');
|
|
59
74
|
if (webUrl.startsWith('https://')) {
|
|
60
75
|
tags.push(['web', webUrl]);
|
|
61
76
|
}
|