Skip to content

Commit

Permalink
Merge pull request #2411 from carapace-sh/gh-updates-v2.51.0
Browse files Browse the repository at this point in the history
gh: updates from v2.51.0
  • Loading branch information
rsteube authored Jun 16, 2024
2 parents 44e723f + e74c48e commit 40b6731
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions completers/gh_completer/cmd/attestation_verify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
"path/filepath"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -29,6 +32,8 @@ func init() {
attestation_verifyCmd.Flags().StringP("owner", "o", "", "GitHub organization to scope attestation lookup by")
attestation_verifyCmd.Flags().String("predicate-type", "", "Filter attestations by provided predicate type")
attestation_verifyCmd.Flags().StringP("repo", "R", "", "Repository name in the format <owner>/<repo>")
attestation_verifyCmd.Flags().String("signer-repo", "", "Repository of reusable workflow that signed attestation in the format <owner>/<repo>")
attestation_verifyCmd.Flags().String("signer-workflow", "", "Workflow that signed attestation in the format [host/]<owner>/<repo>/<path>/<to>/<workflow>")
attestation_verifyCmd.Flags().StringP("template", "t", "", "Format JSON output using a Go template; see \"gh help formatting\"")
attestationCmd.AddCommand(attestation_verifyCmd)

Expand All @@ -39,6 +44,39 @@ func init() {
"format": carapace.ActionValues("json"),
"owner": gh.ActionOrganizations(gh.HostOpts{}),
"repo": gh.ActionHostOwnerRepositories(),
"signer-repo": gh.ActionHostOwnerRepositories(),
"signer-workflow": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
n := 3
if strings.Contains(strings.Split(c.Value, "/")[0], ".") {
n = 4
}

if count := strings.Count(c.Value, "/"); count < n-1 {
if count == n-2 {
return gh.ActionHostOwnerRepositories().NoSpace().Suffix("/")
}
return gh.ActionHostOwnerRepositories().NoSpace()
}

return carapace.ActionMultiPartsN("/", n, func(c carapace.Context) carapace.Action {
opts := gh.ContentOpts{
Owner: c.Parts[n-3],
Name: c.Parts[n-2],
}
if n == 4 {
opts.Host = c.Parts[0]
}
opts.Path = filepath.Dir(c.Value)
prefix := filepath.Dir(c.Value)
switch {
case prefix == ".":
prefix = ""
default:
prefix += "/"
}
return gh.ActionContents(opts).Prefix(prefix)
})
}),
})

carapace.Gen(attestation_verifyCmd).PositionalCompletion(
Expand Down

0 comments on commit 40b6731

Please sign in to comment.