-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]}) | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
} |