-
Notifications
You must be signed in to change notification settings - Fork 17
Add lint workflow #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d5f38d8
0a57639
2de60dc
c0acf3f
b487253
4073652
7fbc049
2245c3f
22b2ae7
c7591b7
6ad6204
2920dee
312c548
b0832d2
88d2047
5baeb6b
aeaa668
166451c
24d70db
4b77a23
a0d2e2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: "go-linter" | ||
|
|
||
| on: | ||
| pull_request: | ||
| merge_group: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| lint: | ||
| strategy: | ||
| fail-fast: false | ||
| runs-on: ubuntu-latest-xl | ||
| env: | ||
| GOPROXY: https://goproxy.githubapp.com/mod,https://proxy.golang.org/,direct | ||
| GOPRIVATE: "" | ||
| GONOPROXY: "" | ||
| GONOSUMDB: github.com/github/* | ||
| steps: | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: ${{ vars.GOVERSION }} | ||
| check-latest: true | ||
| - uses: actions/checkout@v4 | ||
| - name: Configure Go private module access | ||
| run: | | ||
| echo "machine goproxy.githubapp.com login nobody password ${{ secrets.GOPROXY_TOKEN }}" >> $HOME/.netrc | ||
| - name: Lint | ||
| # This also does checkout, setup-go, and proxy setup. | ||
| uses: github/go-linter@v1.2.1 | ||
| with: | ||
| strict: true | ||
| go-version: ${{ vars.GOVERSION }} | ||
| goproxy-token: ${{secrets.GOPROXY_TOKEN}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| // Package list provides a gh command to list available models. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot helped with the package and function docs. cc @brannon for input on whether Copilot and I described things accurately. |
||
| package list | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
|
|
||
| "github.com/cli/go-gh/v2/pkg/auth" | ||
| "github.com/cli/go-gh/v2/pkg/tableprinter" | ||
| "github.com/cli/go-gh/v2/pkg/term" | ||
| "github.com/github/gh-models/internal/azure_models" | ||
| "github.com/github/gh-models/internal/azuremodels" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linter dislikes underscores in package names. |
||
| "github.com/github/gh-models/internal/ux" | ||
| "github.com/github/gh-models/pkg/util" | ||
| "github.com/mgutz/ansi" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
@@ -17,6 +18,7 @@ var ( | |
| lightGrayUnderline = ansi.ColorFunc("white+du") | ||
| ) | ||
|
|
||
| // NewListCommand returns a new command to list available GitHub models. | ||
| func NewListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
|
|
@@ -28,28 +30,29 @@ func NewListCommand() *cobra.Command { | |
|
|
||
| token, _ := auth.TokenForHost("github.com") | ||
| if token == "" { | ||
| io.WriteString(out, "No GitHub token found. Please run 'gh auth login' to authenticate.\n") | ||
| util.WriteToOut(out, "No GitHub token found. Please run 'gh auth login' to authenticate.\n") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved |
||
| return nil | ||
| } | ||
|
|
||
| client := azure_models.NewClient(token) | ||
| client := azuremodels.NewClient(token) | ||
| ctx := cmd.Context() | ||
|
|
||
| models, err := client.ListModels() | ||
| models, err := client.ListModels(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // For now, filter to just chat models. | ||
| // Once other tasks are supported (like embeddings), update the list to show all models, with the task as a column. | ||
| models = ux.FilterToChatModels(models) | ||
| models = filterToChatModels(models) | ||
| ux.SortModels(models) | ||
|
|
||
| isTTY := terminal.IsTerminalOutput() | ||
|
|
||
| if isTTY { | ||
| io.WriteString(out, "\n") | ||
| io.WriteString(out, fmt.Sprintf("Showing %d available chat models\n", len(models))) | ||
| io.WriteString(out, "\n") | ||
| util.WriteToOut(out, "\n") | ||
| util.WriteToOut(out, fmt.Sprintf("Showing %d available chat models\n", len(models))) | ||
| util.WriteToOut(out, "\n") | ||
| } | ||
|
|
||
| width, _, _ := terminal.Size() | ||
|
|
@@ -75,3 +78,13 @@ func NewListCommand() *cobra.Command { | |
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func filterToChatModels(models []*azuremodels.ModelSummary) []*azuremodels.ModelSummary { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved from the |
||
| var chatModels []*azuremodels.ModelSummary | ||
| for _, model := range models { | ||
| if ux.IsChatModel(model) { | ||
| chatModels = append(chatModels, model) | ||
| } | ||
| } | ||
| return chatModels | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.