@@ -12,6 +12,7 @@ import (
1212 "github.com/carabiner-dev/vcslocator"
1313 "github.com/spf13/cobra"
1414
15+ "github.com/slsa-framework/slsa-source-poc/pkg/auth"
1516 "github.com/slsa-framework/slsa-source-poc/pkg/ghcontrol"
1617 "github.com/slsa-framework/slsa-source-poc/pkg/sourcetool/models"
1718)
@@ -122,7 +123,16 @@ func (bo *branchOptions) EnsureDefaults() error {
122123 return nil
123124 }
124125
125- gcx := ghcontrol .NewGhConnection (bo .owner , bo .repository , "" ).WithAuthToken (githubToken )
126+ t := githubToken
127+ var err error
128+ if t == "" {
129+ t , err = auth .New ().ReadToken ()
130+ if err != nil {
131+ return err
132+ }
133+ }
134+
135+ gcx := ghcontrol .NewGhConnection (bo .owner , bo .repository , "" ).WithAuthToken (t )
126136 branch , err := gcx .GetDefaultBranch (context .Background ())
127137 if err != nil {
128138 return fmt .Errorf ("reading repository default branch: %w" , err )
@@ -181,7 +191,16 @@ func (co *commitOptions) EnsureDefaults() error {
181191 }
182192
183193 if co .commit == "" {
184- gcx := ghcontrol .NewGhConnection (co .owner , co .repository , "" ).WithAuthToken (githubToken )
194+ t := githubToken
195+ var err error
196+ if t == "" {
197+ t , err = auth .New ().ReadToken ()
198+ if err != nil {
199+ return err
200+ }
201+ }
202+
203+ gcx := ghcontrol .NewGhConnection (co .owner , co .repository , "" ).WithAuthToken (t )
185204 digest , err := gcx .GetLatestCommit (context .Background (), co .branch )
186205 if err != nil {
187206 return fmt .Errorf ("fetching last commit from %q: %w" , co .branch , err )
0 commit comments