Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Set up Go 1.23
uses: actions/setup-go@v3
with:
go-version: 1.23

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Restore Go modules cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: go-${{ runner.os }}-${{ hashFiles('go.mod') }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v6
- uses: actions/setup-go@v5
with:
go-version: '^1.19.0'
- uses: actions/checkout@v3
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v9
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
# Pin to a version that supports the targeted Go version from go.mod
version: v2.8.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cli/gh-extension-precompile@v1
- uses: actions/checkout@v6
- uses: cli/gh-extension-precompile@v2
with:
go_version_file: go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strconv"
"strings"

"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/go-gh/v2/pkg/api"
"github.com/cli/go-gh/v2/pkg/browser"
"github.com/cli/go-gh/v2/pkg/tableprinter"
Expand Down Expand Up @@ -53,7 +53,7 @@ func NewCmdAcceptedAssignments(f *cmdutil.Factory) *cobra.Command {

if web {
if term.IsTerminalOutput() {
fmt.Fprintln(cmd.ErrOrStderr(), "Opening in your browser.")
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), "Opening in your browser.")
}
browser := browser.New("", cmd.OutOrStdout(), cmd.OutOrStderr())
err := browser.Browse(assignment.Url())
Expand All @@ -68,8 +68,8 @@ func NewCmdAcceptedAssignments(f *cmdutil.Factory) *cobra.Command {
log.Fatal(err)
}

fmt.Fprintf(cmd.OutOrStdout(), "Assignment: %v \n", acceptedAssignments.Assignment.Title)
fmt.Fprintf(cmd.OutOrStdout(), "ID: %v \n\n", acceptedAssignments.Assignment.Id)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Assignment: %v \n", acceptedAssignments.Assignment.Title)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "ID: %v \n\n", acceptedAssignments.Assignment.Id)

t := tableprinter.New(cmd.OutOrStdout(), term.IsTerminalOutput(), 14)
t.AddField("ID", tableprinter.WithTruncate(nil))
Expand Down
4 changes: 2 additions & 2 deletions cmd/gh-classroom/assignment-grades/assignment_grades.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewCmdAssignmentGrades(f *cmdutil.Factory) *cobra.Command {

if web {
if term.IsTerminalOutput() {
fmt.Fprintln(cmd.ErrOrStderr(), "Opening in your browser.")
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), "Opening in your browser.")
}
browser := browser.New("", cmd.OutOrStdout(), cmd.OutOrStderr())
err := browser.Browse(assignment.Url())
Expand All @@ -75,7 +75,7 @@ func NewCmdAssignmentGrades(f *cmdutil.Factory) *cobra.Command {
if err != nil {
log.Fatalln("failed to open file", err)
}
defer f.Close()
defer func() { _ = f.Close() }()

w := csv.NewWriter(f)
defer w.Flush()
Expand Down
6 changes: 3 additions & 3 deletions cmd/gh-classroom/assignment/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewCmdAssignment(f *cmdutil.Factory) *cobra.Command {
Use: "assignment",
Example: `$ gh classroom assignment -a 4876`,
Short: "Show the details of an assignment",
Long: "Display the details of an assignment",
Long: "Display the details of an assignment",
Run: func(cmd *cobra.Command, args []string) {
client, err := api.DefaultRESTClient()

Expand Down Expand Up @@ -71,9 +71,9 @@ func NewCmdAssignment(f *cmdutil.Factory) *cobra.Command {
func OpenInBrowser(url string) {
term := term.FromEnv()
io := iostreams.System()
c := iostreams.NewColorScheme(true, true, true)
c := io.ColorScheme()
if term.IsTerminalOutput() {
fmt.Fprintln(io.ErrOut, c.Yellow("\nOpening assigment in your browser...\n"))
_, _ = fmt.Fprintln(io.ErrOut, c.Yellow("\nOpening assigment in your browser...\n"))
}

browser := browser.New("", io.Out, io.ErrOut)
Expand Down
32 changes: 16 additions & 16 deletions cmd/gh-classroom/assignment/print_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ func RenderModel(assignment classroom.Assignment, out io.Writer) {
}

func printClassroom(model classroom.Classroom, stdout io.Writer) {
c := iostreams.NewColorScheme(true, true, true)
fmt.Fprintln(stdout, c.Blue("CLASSROOM INFORMATION"))
fmt.Fprintln(stdout, c.Yellow("ID:"), c.Green(strconv.Itoa(model.Id)))
fmt.Fprintln(stdout, c.Yellow("Name:"), c.Green(model.Name))
fmt.Fprintln(stdout, c.Yellow("Classroom URL:"), c.Green(model.Url))
c := iostreams.System().ColorScheme()
_, _ = fmt.Fprintln(stdout, c.Blue("CLASSROOM INFORMATION"))
_, _ = fmt.Fprintln(stdout, c.Yellow("ID:"), c.Green(strconv.Itoa(model.Id)))
_, _ = fmt.Fprintln(stdout, c.Yellow("Name:"), c.Green(model.Name))
_, _ = fmt.Fprintln(stdout, c.Yellow("Classroom URL:"), c.Green(model.Url))
}

func printAssigment(assignment classroom.Assignment, out io.Writer) {
c := iostreams.NewColorScheme(true, true, true)
fmt.Fprintln(out, c.Blue("ASSIGNMENT INFORMATION"))
fmt.Fprintln(out, c.Yellow("ID:"), c.Green(strconv.Itoa(assignment.Id)))
fmt.Fprintln(out, c.Yellow("Title:"), c.Green(assignment.Title))
fmt.Fprintln(out, c.Yellow("Invite Link:"), c.Green(assignment.InviteLink))
fmt.Fprintln(out, c.Yellow("Starter Code Repo URL:"), c.Green(assignment.StarterCodeRepository.HtmlUrl))
fmt.Fprintln(out, c.Yellow("Type:"), c.Green(fmt.Sprintf("%v assignment", assignment.AssignmentType)))
fmt.Fprintln(out, c.Yellow("Deadline:"), c.Green(assignment.Deadline))
fmt.Fprintln(out, c.Yellow("Accepted:"), c.Green(strconv.Itoa(assignment.Accepted)))
fmt.Fprintln(out, c.Yellow("Submissions:"), c.Green(strconv.Itoa(assignment.Submissions)))
fmt.Fprintln(out, c.Yellow("Passing:"), c.Green(strconv.Itoa(assignment.Passing)))
c := iostreams.System().ColorScheme()
_, _ = fmt.Fprintln(out, c.Blue("ASSIGNMENT INFORMATION"))
_, _ = fmt.Fprintln(out, c.Yellow("ID:"), c.Green(strconv.Itoa(assignment.Id)))
_, _ = fmt.Fprintln(out, c.Yellow("Title:"), c.Green(assignment.Title))
_, _ = fmt.Fprintln(out, c.Yellow("Invite Link:"), c.Green(assignment.InviteLink))
_, _ = fmt.Fprintln(out, c.Yellow("Starter Code Repo URL:"), c.Green(assignment.StarterCodeRepository.HtmlUrl))
_, _ = fmt.Fprintln(out, c.Yellow("Type:"), c.Green(fmt.Sprintf("%v assignment", assignment.AssignmentType)))
_, _ = fmt.Fprintln(out, c.Yellow("Deadline:"), c.Green(assignment.Deadline))
_, _ = fmt.Fprintln(out, c.Yellow("Accepted:"), c.Green(strconv.Itoa(assignment.Accepted)))
_, _ = fmt.Fprintln(out, c.Yellow("Submissions:"), c.Green(strconv.Itoa(assignment.Submissions)))
_, _ = fmt.Fprintln(out, c.Yellow("Passing:"), c.Green(strconv.Itoa(assignment.Passing)))
}
7 changes: 3 additions & 4 deletions cmd/gh-classroom/assignments/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ func NewCmdAssignments(f *cmdutil.Factory) *cobra.Command {
}
}


assignmentList, err := classroom.ListAssignments(client, classroomId, page, perPage)

if err != nil {
log.Fatal(err)
}

fmt.Fprintln(cmd.OutOrStdout(), assignmentListSummary(cr, assignmentList, cs))
_, _ = fmt.Fprintln(cmd.OutOrStdout(), assignmentListSummary(cr, assignmentList, cs))

if web {
if term.IsTerminalOutput() {
fmt.Fprintln(io.ErrOut, "Opening in your browser.")
_, _ = fmt.Fprintln(io.ErrOut, "Opening in your browser.")
}
browser := browser.New("", cmd.OutOrStdout(), cmd.OutOrStderr())
err := browser.Browse(assignmentList.Url())
Expand All @@ -90,7 +89,7 @@ func NewCmdAssignments(f *cmdutil.Factory) *cobra.Command {
for _, assignment := range assignmentList.Assignments {
t.AddField(cs.Green(strconv.Itoa(assignment.Id)), tableprinter.WithTruncate(nil))
t.AddField(assignment.Title, tableprinter.WithTruncate(nil))
t.AddField(cs.Gray(strconv.FormatBool(assignment.PublicRepo)), tableprinter.WithTruncate(nil))
t.AddField(cs.Muted(strconv.FormatBool(assignment.PublicRepo)), tableprinter.WithTruncate(nil))
t.AddField(assignment.AssignmentType, tableprinter.WithTruncate(nil))
t.AddField(assignment.Deadline, tableprinter.WithTruncate(nil))
t.AddField(assignment.Editor, tableprinter.WithTruncate(nil))
Expand Down
146 changes: 72 additions & 74 deletions cmd/gh-classroom/clone/utils/clone-repository_test.go
Original file line number Diff line number Diff line change
@@ -1,83 +1,81 @@
package utils

import (
"os"
"testing"
"bytes"
"fmt"
"errors"
"path/filepath"
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
"testing"
)

func TestCloneRepository(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "cloneTest")
if err != nil {
t.Fatalf("Failed to create temp directory: %v", err)
}
defer os.RemoveAll(tmpDir) // clean up
// Test cases
tests := []struct {
name string
execMock GitHubExec
clonePath string
repoFullName string
wantErr bool
errMsg string
}{
{
name: "successful clone",
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
stdoutBuf.Write([]byte("your string here"))
return stdoutBuf, stderrBuf, nil
},
clonePath: "", // Will be set to a temp directory in the test
repoFullName: "example/repo",
wantErr: false,
},
{
name: "clone failure",
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
return stdoutBuf, stderrBuf, errors.New("clone error")
},
clonePath: filepath.Join(tmpDir, "repo"),
repoFullName: "example/repo",
wantErr: true,
errMsg: "error cloning example/repo: clone error",
},
{
name: "repository already exists",
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
return stdoutBuf, stderrBuf, nil
},
clonePath: "./repo", // Current directory always exists
repoFullName: "example/repo",
wantErr: true,
errMsg: "repository already exists: .",
},
}
tmpDir, err := os.MkdirTemp("", "cloneTest")
if err != nil {
t.Fatalf("Failed to create temp directory: %v", err)
}
defer func() { _ = os.RemoveAll(tmpDir) }() // clean up

tests := []struct {
name string
execMock GitHubExec
clonePath string
repoFullName string
wantErr bool
errMsg string
}{
{
name: "successful clone",
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
stdoutBuf.Write([]byte("your string here"))
return stdoutBuf, stderrBuf, nil
},
clonePath: "", // Will be set to a temp directory in the test
repoFullName: "example/repo",
wantErr: false,
},
{
name: "clone failure",
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
return stdoutBuf, stderrBuf, errors.New("clone error")
},
clonePath: filepath.Join(tmpDir, "repo"),
repoFullName: "example/repo",
wantErr: true,
errMsg: "error cloning example/repo: clone error",
},
{
name: "repository already exists",
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
return stdoutBuf, stderrBuf, nil
},
clonePath: "./repo", // Current directory always exists
repoFullName: "example/repo",
wantErr: true,
errMsg: "repository already exists: .",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.name == "successful clone" {
fmt.Println("Running successful clone test")
tmpDir, err := os.MkdirTemp("", "cloneTest")
if err != nil {
t.Fatalf("Failed to create temp directory: %v", err)
}
defer os.RemoveAll(tmpDir) // clean up
tt.clonePath = filepath.Join(tmpDir, "repo")
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.name == "successful clone" {
fmt.Println("Running successful clone test")
tmpDir, err := os.MkdirTemp("", "cloneTest")
if err != nil {
t.Fatalf("Failed to create temp directory: %v", err)
}
defer func() { _ = os.RemoveAll(tmpDir) }() // clean up
tt.clonePath = filepath.Join(tmpDir, "repo")
}


fmt.Println("Running test", tt.name, "with clonePath", tt.clonePath, "and repoFullName", tt.repoFullName)
err := CloneRepository(tt.clonePath, tt.repoFullName, tt.execMock)
if err != nil && err.Error() != tt.errMsg {
t.Errorf("CloneRepository() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
fmt.Println("Running test", tt.name, "with clonePath", tt.clonePath, "and repoFullName", tt.repoFullName)
err := CloneRepository(tt.clonePath, tt.repoFullName, tt.execMock)
if err != nil && err.Error() != tt.errMsg {
t.Errorf("CloneRepository() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
6 changes: 3 additions & 3 deletions cmd/gh-classroom/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
count := len(response)

if count == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "No classrooms found")
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "No classrooms found")
} else {
fmt.Fprintf(cmd.OutOrStdout(), "%v\n\n", text.Pluralize(count, "Classroom"))
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%v\n\n", text.Pluralize(count, "Classroom"))
}

t := tableprinter.New(cmd.OutOrStdout(), true, 14)

if web {
if term.IsTerminalOutput() {
fmt.Fprintln(cmd.ErrOrStderr(), "Opening in your browser.")
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), "Opening in your browser.")
}
browser := browser.New("", io.Out, io.ErrOut)
err := browser.Browse("https://classroom.github.com/classrooms")
Expand Down
4 changes: 2 additions & 2 deletions cmd/gh-classroom/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func PromptForClassroom(client *api.RESTClient) (classroomId classroom.Classroom
}

if len(classrooms) == 0 {
return classroom.Classroom{}, errors.New("No classrooms found.")
return classroom.Classroom{}, errors.New("no classrooms found")
}

optionMap := make(map[string]classroom.Classroom)
Expand Down Expand Up @@ -72,7 +72,7 @@ func PromptForAssignment(client *api.RESTClient, classroomId int) (assignment cl
}

if len(options) == 0 {
return classroom.Assignment{}, errors.New("No assignments found for this classroom.")
return classroom.Assignment{}, errors.New("no assignments found for this classroom")
}

var qs = []*survey.Question{
Expand Down
Loading
Loading