~emersion/hut

7c5b5e5aee0a033c4d4815449746de123caedcd8 — Thorben Günther 1 year, 3 months ago 8b7a0e1
git/completeArtifacts: Handle owner
1 files changed, 10 insertions(+), 3 deletions(-)

M git.go
M git.go => git.go +10 -3
@@ 946,16 946,23 @@ var completeAccessMode = cobra.FixedCompletions([]string{"RO", "RW"}, cobra.Shel

func completeArtifacts(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	ctx := cmd.Context()
	repoName, _, instance, err := getRepoName(ctx, cmd)
	repoName, owner, instance, err := getRepoName(ctx, cmd)
	if err != nil {
		return nil, cobra.ShellCompDirectiveNoFileComp
	}

	c := createClientWithInstance("git", cmd, instance)
	var user *gitsrht.User
	var artifactList []string

	user, err := gitsrht.ListArtifacts(c.Client, ctx, repoName)
	if err != nil || user.Repository == nil {
	if owner != "" {
		username := strings.TrimLeft(owner, ownerPrefixes)
		user, err = gitsrht.ListArtifactsByUser(c.Client, ctx, username, repoName)
	} else {
		user, err = gitsrht.ListArtifacts(c.Client, ctx, repoName)
	}

	if err != nil || user == nil || user.Repository == nil {
		return nil, cobra.ShellCompDirectiveNoFileComp
	}