mirror of
https://github.com/rsteube/carapace-bin.git
synced 2025-05-05 15:32:53 +00:00
added git-coauthor (#2539)
This commit is contained in:
parent
401c675bac
commit
20917b4bea
30
completers/git-coauthor_completer/cmd/root.go
Normal file
30
completers/git-coauthor_completer/cmd/root.go
Normal file
@ -0,0 +1,30 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gh"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "git-coauthor",
|
||||
Short: "Add a co-author to the last commit",
|
||||
Long: "https://github.com/tj/git-extras/blob/master/Commands.md#git-coauthor",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
func init() {
|
||||
carapace.Gen(rootCmd).Standalone()
|
||||
|
||||
rootCmd.Flags().Bool("help", false, "show help")
|
||||
|
||||
carapace.Gen(rootCmd).PositionalCompletion(
|
||||
gh.ActionUsers(gh.HostOpts{}),
|
||||
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
return gh.ActionUserEmails(gh.OwnerOpts{Owner: c.Args[0]})
|
||||
}),
|
||||
)
|
||||
}
|
7
completers/git-coauthor_completer/main.go
Normal file
7
completers/git-coauthor_completer/main.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/carapace-sh/carapace-bin/completers/git-coauthor_completer/cmd"
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
46
pkg/actions/tools/gh/email.go
Normal file
46
pkg/actions/tools/gh/email.go
Normal file
@ -0,0 +1,46 @@
|
||||
package gh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/carapace-sh/carapace"
|
||||
)
|
||||
|
||||
type emailQuery struct {
|
||||
Data struct {
|
||||
User struct {
|
||||
Name string
|
||||
Email string
|
||||
}
|
||||
Organization struct {
|
||||
Name string
|
||||
Email string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ActionUserEmails completes email for given user
|
||||
func ActionUserEmails(opts OwnerOpts) carapace.Action {
|
||||
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
var queryResult emailQuery
|
||||
return graphQlAction(opts.repo(), fmt.Sprintf(`user(login: %#v) { name email }`, opts.Owner), &queryResult, func() carapace.Action {
|
||||
if queryResult.Data.User.Email == "" {
|
||||
queryResult.Data.User.Email = fmt.Sprintf(`%v@users.noreply.github.com`, opts.Owner)
|
||||
}
|
||||
return carapace.ActionValuesDescribed(queryResult.Data.User.Email, queryResult.Data.User.Email)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// ActionOrganizationEmails completes email for given organization
|
||||
func ActionOrganizationEmails(opts OwnerOpts) carapace.Action {
|
||||
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
var queryResult emailQuery
|
||||
return graphQlAction(opts.repo(), fmt.Sprintf(`organization(login: %#v) { name email }`, opts.Owner), &queryResult, func() carapace.Action {
|
||||
if queryResult.Data.Organization.Email == "" {
|
||||
queryResult.Data.Organization.Email = fmt.Sprintf(`%v@organizations.noreply.github.com`, opts.Owner)
|
||||
}
|
||||
return carapace.ActionValuesDescribed(queryResult.Data.Organization.Email, queryResult.Data.Organization.Email)
|
||||
})
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user