Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added git-coauthor #2539

Merged
merged 1 commit into from
Sep 22, 2024
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
30 changes: 30 additions & 0 deletions completers/git-coauthor_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions completers/git-coauthor_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/carapace-sh/carapace-bin/completers/git-coauthor_completer/cmd"

func main() {
cmd.Execute()
}
46 changes: 46 additions & 0 deletions pkg/actions/tools/gh/email.go
Original file line number Diff line number Diff line change
@@ -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)
})
})
}