@@ -5,11 +5,14 @@ import (
5
5
"context"
6
6
"encoding/json"
7
7
"errors"
8
+ "fmt"
8
9
"io"
9
10
"net/http"
10
11
"os/exec"
12
+ "strings"
11
13
12
14
"github.com/charmbracelet/log"
15
+ "github.com/cli/go-gh/v2"
13
16
"github.com/flexwie/ghs/pkg/executors"
14
17
"github.com/flexwie/ghs/pkg/github"
15
18
)
@@ -19,7 +22,7 @@ func SearchForGistFile(url string, gistName string, ctx context.Context) (*githu
19
22
20
23
req , err := http .NewRequest ("GET" , url , nil )
21
24
if token != "" {
22
- req .Header .Add ("Authorization" , token )
25
+ req .Header .Add ("Authorization" , fmt . Sprintf ( "Bearer %s" , token ) )
23
26
}
24
27
25
28
resp , err := http .DefaultClient .Do (req )
@@ -47,6 +50,13 @@ func SearchForGistFile(url string, gistName string, ctx context.Context) (*githu
47
50
}
48
51
49
52
func getGithubToken () string {
53
+ x , _ , err := gh .Exec ("auth" , "token" )
54
+ if err != nil {
55
+ log .Warn ("unauthorized" )
56
+ }
57
+
58
+ return strings .TrimSuffix (x .String (), "\n " )
59
+
50
60
cmd := exec .Command ("which" , "gh" )
51
61
if err := cmd .Run (); err != nil {
52
62
log .Warn ("GitHub cli is not installed. Your private gists will not be found." )
@@ -70,8 +80,6 @@ func getGithubToken() string {
70
80
71
81
func GetExecutor (file * github.File , ctx context.Context ) (executors.Executor , error ) {
72
82
for _ , e := range executors .ExecutorPipeline {
73
- file := ctx .Value ("file" ).(* github.File )
74
-
75
83
if e .Match (file ) {
76
84
return e , nil
77
85
}
0 commit comments