-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package nip34 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package nip34 | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/bluekeyes/go-gitdiff/gitdiff" | ||
"github.com/nbd-wtf/go-nostr" | ||
) | ||
|
||
type Patch struct { | ||
nostr.Event | ||
|
||
Repository nostr.EntityPointer | ||
Subject string | ||
|
||
Files []*gitdiff.File | ||
Header *gitdiff.PatchHeader | ||
} | ||
|
||
func ParsePatch(event nostr.Event) Patch { | ||
patch := Patch{ | ||
Event: event, | ||
} | ||
|
||
for _, tag := range event.Tags { | ||
if len(tag) < 2 { | ||
continue | ||
} | ||
switch tag[0] { | ||
case "a": | ||
spl := strings.Split(tag[1], ":") | ||
if len(spl) != 3 { | ||
continue | ||
} | ||
if !nostr.IsValid32ByteHex(spl[1]) { | ||
continue | ||
} | ||
patch.Repository.Kind = nostr.KindRepositoryAnnouncement | ||
patch.Repository.PublicKey = spl[1] | ||
patch.Repository.Identifier = spl[2] | ||
if len(tag) >= 3 { | ||
patch.Repository.Relays = []string{tag[2]} | ||
} | ||
} | ||
} | ||
|
||
files, preamble, err := gitdiff.Parse(strings.NewReader(event.Content)) | ||
if err != nil { | ||
return patch | ||
} | ||
patch.Files = files | ||
|
||
header, err := gitdiff.ParsePatchHeader(preamble) | ||
if err != nil { | ||
return patch | ||
} | ||
patch.Header = header | ||
|
||
return patch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nip34 | ||
|
||
import "github.com/nbd-wtf/go-nostr" | ||
|
||
type Repository struct { | ||
nostr.Event | ||
|
||
ID string | ||
Name string | ||
Description string | ||
Web []string | ||
Clone []string | ||
Relays []string | ||
} | ||
|
||
func ParseRepository(event nostr.Event) Repository { | ||
repo := Repository{ | ||
Event: event, | ||
} | ||
|
||
for _, tag := range event.Tags { | ||
if len(tag) < 2 { | ||
continue | ||
} | ||
switch tag[0] { | ||
case "d": | ||
repo.ID = tag[1] | ||
case "name": | ||
repo.Name = tag[1] | ||
case "description": | ||
repo.Description = tag[1] | ||
case "web": | ||
repo.Web = append(repo.Web, tag[1]) | ||
case "clone": | ||
repo.Clone = append(repo.Clone, tag[1]) | ||
case "relays": | ||
repo.Relays = append(repo.Relays, tag[1]) | ||
} | ||
} | ||
|
||
return repo | ||
} |