Skip to content

Commit

Permalink
gh: add ActionHostOwnerRepositories
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 4, 2024
1 parent c7a70c4 commit b66cdc6
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 78 deletions.
47 changes: 0 additions & 47 deletions completers/gh_completer/cmd/action/repo_override.go

This file was deleted.

3 changes: 1 addition & 2 deletions completers/gh_completer/cmd/attestation_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)
Expand All @@ -25,7 +24,7 @@ func init() {
carapace.Gen(attestation_downloadCmd).FlagCompletion(carapace.ActionMap{
"digest-alg": carapace.ActionValues("sha256", "sha512"),
"owner": gh.ActionOrganizations(gh.HostOpts{}),
"repo": action.ActionRepoOverride(attestation_downloadCmd),
"repo": gh.ActionHostOwnerRepositories(),
})

carapace.Gen(attestation_downloadCmd).PositionalCompletion(
Expand Down
3 changes: 1 addition & 2 deletions completers/gh_completer/cmd/attestation_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers_release/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,7 +37,7 @@ func init() {
"digest-alg": carapace.ActionValues("sha256", "sha512"),
"format": carapace.ActionValues("json"),
"owner": gh.ActionOrganizations(gh.HostOpts{}),
"repo": action.ActionRepoOverride(attestation_verifyCmd),
"repo": gh.ActionHostOwnerRepositories(),
})

carapace.Gen(attestation_verifyCmd).PositionalCompletion(
Expand Down
3 changes: 2 additions & 1 deletion completers/gh_completer/cmd/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
_git "github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action/git"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/carapace-sh/carapace/pkg/util"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func init() {

carapace.Gen(browseCmd).FlagCompletion(carapace.ActionMap{
"branch": action.ActionBranches(browseCmd), // TODO merge with tags
"repo": action.ActionRepoOverride(browseCmd),
"repo": gh.ActionHostOwnerRepositories(),
})

carapace.Gen(browseCmd).PositionalCompletion(
Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
rootCmd.AddCommand(cacheCmd)

carapace.Gen(cacheCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(cacheCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -24,6 +24,6 @@ func init() {
rootCmd.AddCommand(issueCmd)

carapace.Gen(issueCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(issueCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -19,6 +19,6 @@ func init() {
rootCmd.AddCommand(labelCmd)

carapace.Gen(labelCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(labelCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -24,6 +24,6 @@ func init() {
rootCmd.AddCommand(prCmd)

carapace.Gen(prCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(prCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/project_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {

carapace.Gen(project_linkCmd).FlagCompletion(carapace.ActionMap{
"owner": gh.ActionOwners(gh.HostOpts{}),
"repo": action.ActionRepoOverride(project_linkCmd),
"repo": gh.ActionHostOwnerRepositories(),
"team": action.ActionTeams(project_linkCmd),
})

Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/project_unlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {

carapace.Gen(project_unlinkCmd).FlagCompletion(carapace.ActionMap{
"owner": gh.ActionOwners(gh.HostOpts{}),
"repo": action.ActionRepoOverride(project_linkCmd),
"repo": gh.ActionHostOwnerRepositories(),
"team": action.ActionTeams(project_linkCmd),
})

Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -24,6 +24,6 @@ func init() {
rootCmd.AddCommand(releaseCmd)

carapace.Gen(releaseCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(issueCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/repo_deployKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
repoCmd.AddCommand(repo_deployKeyCmd)

carapace.Gen(repo_deployKeyCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(repo_deployKeyCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/repo_rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -23,6 +23,6 @@ func init() {
repoCmd.AddCommand(repo_renameCmd)

carapace.Gen(repo_renameCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(repo_renameCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
rootCmd.AddCommand(rulesetCmd)

carapace.Gen(rulesetCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(rulesetCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
rootCmd.AddCommand(runCmd)

carapace.Gen(runCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(runCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -19,6 +19,6 @@ func init() {
rootCmd.AddCommand(secretCmd)

carapace.Gen(secretCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(secretCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -19,6 +19,6 @@ func init() {
rootCmd.AddCommand(variableCmd)

carapace.Gen(variableCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(variableCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gh_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
rootCmd.AddCommand(workflowCmd)

carapace.Gen(workflowCmd).FlagCompletion(carapace.ActionMap{
"repo": action.ActionRepoOverride(workflowCmd),
"repo": gh.ActionHostOwnerRepositories(),
})
}
27 changes: 27 additions & 0 deletions pkg/actions/tools/gh/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gh

import (
"fmt"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/styles"
Expand Down Expand Up @@ -77,3 +78,29 @@ func ActionOwnerRepositories(opts HostOpts) carapace.Action {
}
})
}

// ActionHostOwnerRepositories completes [host/]owner/repository
//
// carapace-sh/carapace
// github.com/carapace-sh/carapace
func ActionHostOwnerRepositories() carapace.Action {
return carapace.ActionMultiPartsN("/", 3, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return carapace.Batch(
ActionConfigHosts(),
ActionOwners(HostOpts{}),
).ToA().Suffix("/")
case 1:
if strings.Contains(c.Parts[0], ".") {
return ActionOwners(HostOpts{Host: c.Parts[0]}).Suffix("/")
}
return ActionRepositories(OwnerOpts{Owner: c.Parts[0]})
default:
if strings.Contains(c.Parts[0], ".") {
return ActionRepositories(OwnerOpts{Host: c.Parts[0], Owner: c.Parts[1]})
}
return carapace.ActionValues()
}
})
}

0 comments on commit b66cdc6

Please sign in to comment.