8
8
"strings"
9
9
10
10
"github.com/google/go-cmp/cmp"
11
- "github.com/google/go-github/v43 /github"
11
+ "github.com/google/go-github/v61 /github"
12
12
"golang.org/x/mod/semver"
13
13
"golang.org/x/xerrors"
14
14
@@ -26,12 +26,19 @@ const (
26
26
func main () {
27
27
logger := slog .Make (sloghuman .Sink (os .Stderr )).Leveled (slog .LevelDebug )
28
28
29
+ var ghToken string
29
30
var dryRun bool
30
31
31
32
cmd := serpent.Command {
32
33
Use : "release <subcommand>" ,
33
34
Short : "Prepare, create and publish releases." ,
34
35
Options : serpent.OptionSet {
36
+ {
37
+ Flag : "gh-token" ,
38
+ Description : "GitHub personal access token." ,
39
+ Env : "GH_TOKEN" ,
40
+ Value : serpent .StringOf (& ghToken ),
41
+ },
35
42
{
36
43
Flag : "dry-run" ,
37
44
FlagShorthand : "n" ,
@@ -48,8 +55,11 @@ func main() {
48
55
if len (inv .Args ) == 0 {
49
56
return xerrors .New ("version argument missing" )
50
57
}
58
+ if ! dryRun && ghToken == "" {
59
+ return xerrors .New ("GitHub personal access token is required, use --gh-token or GH_TOKEN" )
60
+ }
51
61
52
- err := promoteVersionToStable (ctx , inv , logger , dryRun , inv .Args [0 ])
62
+ err := promoteVersionToStable (ctx , inv , logger , ghToken , dryRun , inv .Args [0 ])
53
63
if err != nil {
54
64
return err
55
65
}
@@ -71,8 +81,11 @@ func main() {
71
81
}
72
82
73
83
//nolint:revive // Allow dryRun control flag.
74
- func promoteVersionToStable (ctx context.Context , inv * serpent.Invocation , logger slog.Logger , dryRun bool , version string ) error {
84
+ func promoteVersionToStable (ctx context.Context , inv * serpent.Invocation , logger slog.Logger , ghToken string , dryRun bool , version string ) error {
75
85
client := github .NewClient (nil )
86
+ if ghToken != "" {
87
+ client = client .WithAuthToken (ghToken )
88
+ }
76
89
77
90
logger = logger .With (slog .F ("dry_run" , dryRun ), slog .F ("version" , version ))
78
91
0 commit comments