Skip to content
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

Add lint workflow #10

Merged
merged 21 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
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/[email protected]
with:
strict: true
go-version: ${{ vars.GOVERSION }}
goproxy-token: ${{secrets.GOPROXY_TOKEN}}
Fixed Show fixed Hide fixed
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Use the GitHub Models service from the CLI!

### Prerequisites

The extension requires the `gh` CLI to be installed and in the PATH. The extension also requires the user have authenticated via `gh auth`.
The extension requires the [`gh` CLI](https://cli.github.com/) to be installed and in the `PATH`. The extension also requires the user have authenticated via `gh auth`.

### Installing

Expand Down Expand Up @@ -73,4 +73,4 @@ git tag v0.0.x main
git push origin tag v0.0.x
```

This will trigger the `release` action that runs the actual production build.
This will trigger the `release` action that runs the actual production build.
31 changes: 22 additions & 9 deletions cmd/list/list.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Package list provides a gh command to list available models.
Copy link
Member Author

Choose a reason for hiding this comment

The 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"
Copy link
Member Author

Choose a reason for hiding this comment

The 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"
)
Expand All @@ -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",
Expand All @@ -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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved io.WriteString calls to a new function that handles the returned error.

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()
Expand All @@ -75,3 +78,13 @@ func NewListCommand() *cobra.Command {

return cmd
}

func filterToChatModels(models []*azuremodels.ModelSummary) []*azuremodels.ModelSummary {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from the ux package because it was only used here.

var chatModels []*azuremodels.ModelSummary
for _, model := range models {
if ux.IsChatModel(model) {
chatModels = append(chatModels, model)
}
}
return chatModels
}
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Package cmd represents the base command when called without any subcommands.
package cmd

import (
"strings"

"github.com/github/gh-models/cmd/list"
"github.com/github/gh-models/cmd/run"
"github.com/github/gh-models/cmd/view"
"github.com/spf13/cobra"
"strings"
)

// NewRootCommand returns a new root command for the gh-models extension.
func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "models",
Expand Down
Loading
Loading