Skip to content

Commit

Permalink
Merge pull request #60 from VILJkid/fix/interface-to-any-and-code-cle…
Browse files Browse the repository at this point in the history
…anup

[Fix] Code Cleanup
  • Loading branch information
canack authored Jun 19, 2024
2 parents 2b71af6 + df7a3d1 commit 31cd0c4
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 87 deletions.
5 changes: 3 additions & 2 deletions internal/github/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/termkit/gama/internal/config"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"

"github.com/termkit/gama/internal/config"

"github.com/termkit/gama/internal/github/domain"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -479,7 +480,7 @@ type githubWorkflow struct {
}

type workflowFile struct {
On map[string]interface{} `yaml:"on"`
On map[string]any `yaml:"on"`
}

type githubFile struct {
Expand Down
5 changes: 3 additions & 2 deletions internal/github/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package repository

import (
"context"
"github.com/termkit/gama/internal/config"
"reflect"
"testing"

"github.com/termkit/gama/internal/config"

"github.com/termkit/gama/internal/github/domain"
)

func newRepo(ctx context.Context) *Repo {
func newRepo(_ context.Context) *Repo {
cfg, err := config.LoadConfig()
if err != nil {
panic(err)
Expand Down
70 changes: 35 additions & 35 deletions internal/github/repository/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ type InitializeOptions struct {
}

type GithubRepository struct {
Id int `json:"id"`
NodeId string `json:"node_id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Description string `json:"description"`
Language interface{} `json:"language"`
ForksCount int `json:"forks_count"`
StargazersCount int `json:"stargazers_count"`
WatchersCount int `json:"watchers_count"`
Size int `json:"size"`
DefaultBranch string `json:"default_branch"`
OpenIssuesCount int `json:"open_issues_count"`
IsTemplate bool `json:"is_template"`
Topics []string `json:"topics"`
HasIssues bool `json:"has_issues"`
HasProjects bool `json:"has_projects"`
HasWiki bool `json:"has_wiki"`
HasPages bool `json:"has_pages"`
HasDownloads bool `json:"has_downloads"`
Archived bool `json:"archived"`
Disabled bool `json:"disabled"`
Visibility string `json:"visibility"`
PushedAt time.Time `json:"pushed_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id int `json:"id"`
NodeId string `json:"node_id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Description string `json:"description"`
Language any `json:"language"`
ForksCount int `json:"forks_count"`
StargazersCount int `json:"stargazers_count"`
WatchersCount int `json:"watchers_count"`
Size int `json:"size"`
DefaultBranch string `json:"default_branch"`
OpenIssuesCount int `json:"open_issues_count"`
IsTemplate bool `json:"is_template"`
Topics []string `json:"topics"`
HasIssues bool `json:"has_issues"`
HasProjects bool `json:"has_projects"`
HasWiki bool `json:"has_wiki"`
HasPages bool `json:"has_pages"`
HasDownloads bool `json:"has_downloads"`
Archived bool `json:"archived"`
Disabled bool `json:"disabled"`
Visibility string `json:"visibility"`
PushedAt time.Time `json:"pushed_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Permissions struct {
Admin bool `json:"admin"`
Push bool `json:"push"`
Pull bool `json:"pull"`
} `json:"permissions"`
AllowRebaseMerge bool `json:"allow_rebase_merge"`
TemplateRepository interface{} `json:"template_repository"`
TempCloneToken string `json:"temp_clone_token"`
AllowSquashMerge bool `json:"allow_squash_merge"`
AllowAutoMerge bool `json:"allow_auto_merge"`
DeleteBranchOnMerge bool `json:"delete_branch_on_merge"`
AllowMergeCommit bool `json:"allow_merge_commit"`
SubscribersCount int `json:"subscribers_count"`
NetworkCount int `json:"network_count"`
AllowRebaseMerge bool `json:"allow_rebase_merge"`
TemplateRepository any `json:"template_repository"`
TempCloneToken string `json:"temp_clone_token"`
AllowSquashMerge bool `json:"allow_squash_merge"`
AllowAutoMerge bool `json:"allow_auto_merge"`
DeleteBranchOnMerge bool `json:"delete_branch_on_merge"`
AllowMergeCommit bool `json:"allow_merge_commit"`
SubscribersCount int `json:"subscribers_count"`
NetworkCount int `json:"network_count"`
License struct {
Key string `json:"key"`
Name string `json:"name"`
Expand Down
6 changes: 5 additions & 1 deletion internal/github/usecase/usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package usecase

import (
"context"
"github.com/termkit/gama/internal/config"
"testing"

"github.com/termkit/gama/internal/config"

"github.com/termkit/gama/internal/github/domain"
"github.com/termkit/gama/internal/github/repository"
)
Expand Down Expand Up @@ -68,6 +69,9 @@ func TestUseCase_TriggerWorkflow(t *testing.T) {
Repository: "canack/tc",
WorkflowFile: ".github/workflows/dispatch_test.yaml",
})
if err != nil {
t.Error(err)
}

for i, w := range workflow.Workflow.Inputs {
if w.Key == "go-version" {
Expand Down
13 changes: 6 additions & 7 deletions internal/terminal/handler/ghrepository/ghrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (m *ModelGithubRepository) Init() tea.Cmd {
go m.syncRepositories(m.syncRepositoriesContext)

openInBrowser := func() {
m.modelError.SetProgressMessage(fmt.Sprintf("Opening in browser..."))
m.modelError.SetProgressMessage("Opening in browser...")

err := browser.OpenInBrowser(fmt.Sprintf("https://github.com/%s", m.SelectedRepository.RepositoryName))
if err != nil {
Expand All @@ -141,7 +141,7 @@ func (m *ModelGithubRepository) Init() tea.Cmd {
return
}

m.modelError.SetSuccessMessage(fmt.Sprintf("Opened in browser"))
m.modelError.SetSuccessMessage("Opened in browser")
}

m.actualModelTabOptions.AddOption("Open in browser", openInBrowser)
Expand Down Expand Up @@ -198,7 +198,7 @@ func (m *ModelGithubRepository) syncRepositories(ctx context.Context) {
go m.Update(m) // update model
}

func (m *ModelGithubRepository) handleTableInputs(ctx context.Context) {
func (m *ModelGithubRepository) handleTableInputs(_ context.Context) {
if !m.tableReady {
return
}
Expand Down Expand Up @@ -329,12 +329,11 @@ func (m *ModelGithubRepository) updateTableRowsBySearchBar() {
}

func (m *ModelGithubRepository) isNumber(s string) bool {
_, err := strconv.Atoi(s)
if err != nil {
return false
if _, err := strconv.Atoi(s); err == nil {
return true
}

return true
return false
}

func (m *ModelGithubRepository) isCharAndSymbol(r []rune) bool {
Expand Down
1 change: 1 addition & 0 deletions internal/terminal/handler/ghrepository/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ghrepository

import (
"fmt"

"github.com/termkit/gama/internal/config"

teakey "github.com/charmbracelet/bubbles/key"
Expand Down
4 changes: 2 additions & 2 deletions internal/terminal/handler/ghtrigger/ghtrigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (m *ModelGithubTrigger) inputController(_ context.Context) {
}
}
m.optionValues = optionValues
if m.optionInit == false {
if !m.optionInit {
for i, option := range m.optionValues {
if option == selectedRow[4] {
m.optionCursor = i
Expand All @@ -234,7 +234,7 @@ func (m *ModelGithubTrigger) inputController(_ context.Context) {
}
}
m.optionValues = optionValues
if m.optionInit == false {
if !m.optionInit {
for i, option := range m.optionValues {
if option == selectedRow[4] {
m.optionCursor = i
Expand Down
3 changes: 2 additions & 1 deletion internal/terminal/handler/ghtrigger/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ghtrigger

import (
"fmt"

"github.com/termkit/gama/internal/config"

teakey "github.com/charmbracelet/bubbles/key"
Expand Down Expand Up @@ -33,7 +34,7 @@ var keys = func() keyMap {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var previousTab = fmt.Sprintf("%s", cfg.Shortcuts.SwitchTabLeft)
previousTab := cfg.Shortcuts.SwitchTabLeft

return keyMap{
SwitchTabLeft: teakey.NewBinding(
Expand Down
2 changes: 1 addition & 1 deletion internal/terminal/handler/ghworkflow/ghworkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (m *ModelGithubWorkflow) syncTriggerableWorkflows(ctx context.Context) {
go m.Update(m) // update model
}

func (m *ModelGithubWorkflow) handleTableInputs(ctx context.Context) {
func (m *ModelGithubWorkflow) handleTableInputs(_ context.Context) {
if !m.tableReady {
return
}
Expand Down
1 change: 1 addition & 0 deletions internal/terminal/handler/ghworkflow/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ghworkflow

import (
"fmt"

"github.com/termkit/gama/internal/config"

teakey "github.com/charmbracelet/bubbles/key"
Expand Down
24 changes: 12 additions & 12 deletions internal/terminal/handler/ghworkflowhistory/ghworkflowhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ func SetupModelGithubWorkflowHistory(githubUseCase gu.UseCase, selectedRepositor

func (m *ModelGithubWorkflowHistory) Init() tea.Cmd {
openInBrowser := func() {
m.modelError.SetProgressMessage(fmt.Sprintf("Opening in browser..."))
m.modelError.SetProgressMessage("Opening in browser...")

var selectedWorkflow = fmt.Sprintf("https://github.com/%s/actions/runs/%d", m.SelectedRepository.RepositoryName, m.selectedWorkflowID)

err := browser.OpenInBrowser(selectedWorkflow)
if err != nil {
m.modelError.SetError(err)
m.modelError.SetErrorMessage(fmt.Sprintf("Failed to open in browser"))
m.modelError.SetErrorMessage("Failed to open in browser")
return
}
m.modelError.SetSuccessMessage(fmt.Sprintf("Opened in browser"))
m.modelError.SetSuccessMessage("Opened in browser")
}

reRunFailedJobs := func() {
m.modelError.SetProgressMessage(fmt.Sprintf("Re-running failed jobs..."))
m.modelError.SetProgressMessage("Re-running failed jobs...")

_, err := m.github.ReRunFailedJobs(context.Background(), gu.ReRunFailedJobsInput{
Repository: m.SelectedRepository.RepositoryName,
Expand All @@ -119,15 +119,15 @@ func (m *ModelGithubWorkflowHistory) Init() tea.Cmd {

if err != nil {
m.modelError.SetError(err)
m.modelError.SetErrorMessage(fmt.Sprintf("Failed to re-run failed jobs"))
m.modelError.SetErrorMessage("Failed to re-run failed jobs")
return
}

m.modelError.SetSuccessMessage(fmt.Sprintf("Re-ran failed jobs"))
m.modelError.SetSuccessMessage("Re-ran failed jobs")
}

reRunWorkflow := func() {
m.modelError.SetProgressMessage(fmt.Sprintf("Re-running workflow..."))
m.modelError.SetProgressMessage("Re-running workflow...")

_, err := m.github.ReRunWorkflow(context.Background(), gu.ReRunWorkflowInput{
Repository: m.SelectedRepository.RepositoryName,
Expand All @@ -136,15 +136,15 @@ func (m *ModelGithubWorkflowHistory) Init() tea.Cmd {

if err != nil {
m.modelError.SetError(err)
m.modelError.SetErrorMessage(fmt.Sprintf("Failed to re-run workflow"))
m.modelError.SetErrorMessage("Failed to re-run workflow")
return
}

m.modelError.SetSuccessMessage(fmt.Sprintf("Re-ran workflow"))
m.modelError.SetSuccessMessage("Re-ran workflow")
}

cancelWorkflow := func() {
m.modelError.SetProgressMessage(fmt.Sprintf("Canceling workflow..."))
m.modelError.SetProgressMessage("Canceling workflow...")

_, err := m.github.CancelWorkflow(context.Background(), gu.CancelWorkflowInput{
Repository: m.SelectedRepository.RepositoryName,
Expand All @@ -153,11 +153,11 @@ func (m *ModelGithubWorkflowHistory) Init() tea.Cmd {

if err != nil {
m.modelError.SetError(err)
m.modelError.SetErrorMessage(fmt.Sprintf("Failed to cancel workflow"))
m.modelError.SetErrorMessage("Failed to cancel workflow")
return
}

m.modelError.SetSuccessMessage(fmt.Sprintf("Canceled workflow"))
m.modelError.SetSuccessMessage("Canceled workflow")
}
m.actualModelTabOptions.AddOption("Open in browser", openInBrowser)
m.actualModelTabOptions.AddOption("Rerun failed jobs", reRunFailedJobs)
Expand Down
1 change: 1 addition & 0 deletions internal/terminal/handler/ghworkflowhistory/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ghworkflowhistory

import (
"fmt"

"github.com/termkit/gama/internal/config"

teakey "github.com/charmbracelet/bubbles/key"
Expand Down
3 changes: 2 additions & 1 deletion internal/terminal/handler/information/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package information

import (
"fmt"

"github.com/termkit/gama/internal/config"

teakey "github.com/charmbracelet/bubbles/key"
Expand Down Expand Up @@ -29,7 +30,7 @@ var keys = func() keyMap {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var switchTabRight = fmt.Sprintf("%s", cfg.Shortcuts.SwitchTabRight)
switchTabRight := cfg.Shortcuts.SwitchTabRight

return keyMap{
SwitchTabRight: teakey.NewBinding(
Expand Down
Loading

0 comments on commit 31cd0c4

Please sign in to comment.