porting all github actions from bluesky-social/indigo to tangled CI
at main 1.5 kB view raw
1package main 2 3import ( 4 "context" 5 "fmt" 6 7 comatproto "github.com/bluesky-social/indigo/api/atproto" 8 appbsky "github.com/bluesky-social/indigo/api/bsky" 9 "github.com/bluesky-social/indigo/atproto/syntax" 10 lexutil "github.com/bluesky-social/indigo/lex/util" 11 12 "github.com/urfave/cli/v2" 13) 14 15var cmdBsky = &cli.Command{ 16 Name: "bsky", 17 Usage: "sub-commands for bsky app", 18 Flags: []cli.Flag{}, 19 Subcommands: []*cli.Command{ 20 &cli.Command{ 21 Name: "post", 22 Usage: "create a post", 23 ArgsUsage: `<text>`, 24 Action: runBskyPost, 25 }, 26 cmdBskyPrefs, 27 }, 28} 29 30func runBskyPost(cctx *cli.Context) error { 31 ctx := context.Background() 32 text := cctx.Args().First() 33 if text == "" { 34 return fmt.Errorf("need to provide post text as argument") 35 } 36 37 xrpcc, err := loadAuthClient(ctx) 38 if err == ErrNoAuthSession { 39 return fmt.Errorf("auth required, but not logged in") 40 } else if err != nil { 41 return err 42 } 43 44 post := appbsky.FeedPost{ 45 Text: text, 46 CreatedAt: syntax.DatetimeNow().String(), 47 } 48 resp, err := comatproto.RepoCreateRecord(ctx, xrpcc, &comatproto.RepoCreateRecord_Input{ 49 Collection: "app.bsky.feed.post", 50 Repo: xrpcc.Auth.Did, 51 Record: &lexutil.LexiconTypeDecoder{Val: &post}, 52 }) 53 if err != nil { 54 return err 55 } 56 57 fmt.Printf("%s\t%s\n", resp.Uri, resp.Cid) 58 aturi, err := syntax.ParseATURI(resp.Uri) 59 if err != nil { 60 return err 61 } 62 fmt.Printf("view post at: https://bsky.app/profile/%s/post/%s\n", aturi.Authority(), aturi.RecordKey()) 63 return nil 64}