@@ -17,6 +17,7 @@ import (
17
17
"encoding/json"
18
18
"fmt"
19
19
"net/url"
20
+ "os"
20
21
"path"
21
22
"strings"
22
23
@@ -357,6 +358,7 @@ type EventParsing interface {
357
358
type EventParser struct {
358
359
GithubUser string
359
360
GithubToken string
361
+ GithubTokenFile string
360
362
GitlabUser string
361
363
GitlabToken string
362
364
GiteaUser string
@@ -372,7 +374,15 @@ type EventParser struct {
372
374
func (e * EventParser ) ParseAPIPlanRequest (vcsHostType models.VCSHostType , repoFullName string , cloneURL string ) (models.Repo , error ) {
373
375
switch vcsHostType {
374
376
case models .Github :
375
- return models .NewRepo (vcsHostType , repoFullName , cloneURL , e .GithubUser , e .GithubToken )
377
+ token := e .GithubToken
378
+ if e .GithubTokenFile != "" {
379
+ content , err := os .ReadFile (e .GithubTokenFile )
380
+ if err != nil {
381
+ return models.Repo {}, fmt .Errorf ("failed reading github token file: %w" , err )
382
+ }
383
+ token = string (content )
384
+ }
385
+ return models .NewRepo (vcsHostType , repoFullName , cloneURL , e .GithubUser , token )
376
386
case models .Gitea :
377
387
return models .NewRepo (vcsHostType , repoFullName , cloneURL , e .GiteaUser , e .GiteaToken )
378
388
case models .Gitlab :
@@ -626,7 +636,16 @@ func (e *EventParser) ParseGithubPull(logger logging.SimpleLogging, pull *github
626
636
// returns a repo into the Atlantis model.
627
637
// See EventParsing for return value docs.
628
638
func (e * EventParser ) ParseGithubRepo (ghRepo * github.Repository ) (models.Repo , error ) {
629
- return models .NewRepo (models .Github , ghRepo .GetFullName (), ghRepo .GetCloneURL (), e .GithubUser , e .GithubToken )
639
+ token := e .GithubToken
640
+ if e .GithubTokenFile != "" {
641
+ content , err := os .ReadFile (e .GithubTokenFile )
642
+ if err != nil {
643
+ return models.Repo {}, fmt .Errorf ("failed reading github token file: %w" , err )
644
+ }
645
+ token = string (content )
646
+ }
647
+
648
+ return models .NewRepo (models .Github , ghRepo .GetFullName (), ghRepo .GetCloneURL (), e .GithubUser , token )
630
649
}
631
650
632
651
// ParseGiteaRepo parses the response from the Gitea API endpoint that
0 commit comments