|
5 | 5 | "fmt"
|
6 | 6 | "io"
|
7 | 7 | stdlog "log"
|
| 8 | + "net/url" |
8 | 9 | "os"
|
9 | 10 | "os/signal"
|
10 | 11 | "syscall"
|
@@ -49,10 +50,12 @@ func init() {
|
49 | 50 | // Add global flags that will be shared by all commands
|
50 | 51 | rootCmd.PersistentFlags().String("log-file", "", "Path to log file")
|
51 | 52 | rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
|
| 53 | + rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)") |
52 | 54 |
|
53 | 55 | // Bind flag to viper
|
54 | 56 | viper.BindPFlag("log-file", rootCmd.PersistentFlags().Lookup("log-file"))
|
55 | 57 | viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging"))
|
| 58 | + viper.BindPFlag("gh-host", rootCmd.PersistentFlags().Lookup("gh-host")) |
56 | 59 |
|
57 | 60 | // Add subcommands
|
58 | 61 | rootCmd.AddCommand(stdioCmd)
|
@@ -92,6 +95,20 @@ func runStdioServer(logger *log.Logger, logCommands bool) error {
|
92 | 95 | logger.Fatal("GITHUB_PERSONAL_ACCESS_TOKEN not set")
|
93 | 96 | }
|
94 | 97 | ghClient := gogithub.NewClient(nil).WithAuthToken(token)
|
| 98 | + if host := viper.GetString("gh-host"); host != "" { |
| 99 | + url, err := url.Parse(fmt.Sprintf("https://api.%s/", host)) |
| 100 | + if err != nil { |
| 101 | + return fmt.Errorf("failed to parse provided GitHub host URL: %w", err) |
| 102 | + } |
| 103 | + |
| 104 | + uploadUrl, err := url.Parse(fmt.Sprintf("https://uploads.%s/", host)) |
| 105 | + if err != nil { |
| 106 | + return fmt.Errorf("failed to parse provided GitHub host URL: %w", err) |
| 107 | + } |
| 108 | + |
| 109 | + ghClient.BaseURL = url |
| 110 | + ghClient.UploadURL = uploadUrl |
| 111 | + } |
95 | 112 |
|
96 | 113 | // Create server
|
97 | 114 | ghServer := github.NewServer(ghClient)
|
|
0 commit comments