| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines |
| 14 | 14 | "strings" |
| 15 | 15 | |
| 16 | 16 | "charm.land/huh/v2" |
| 17 | + "git.sr.ht/~xenrox/hut/srht/gitsrht" |
| 17 | 18 | "git.sr.ht/~xenrox/hut/srht/hubsrht" |
| 18 | 19 | "git.sr.ht/~xenrox/hut/srht/todosrht" |
| 19 | 20 | "git.sr.ht/~xenrox/hut/termfmt" |
| @@ -2223,17 +2224,50 @@ func getTrackerName(ctx context.Context, cmd *cobra.Command) (c *Client, r resou · 2203 unmodified lines |
| 2223 | 2224 | return nil, resource{}, err |
| 2224 | 2225 | } |
| 2225 | 2226 | |
| 2226 | | − c = createClientWithInstance("hub", cmd, r.instance) |
| 2227 | + gitClient := createClientWithInstance("git", cmd, r.instance) |
| 2228 | + c = gitClient |
| 2227 | 2229 | username := strings.TrimLeft(r.owner, ownerPrefixes) |
| 2228 | 2230 | |
| 2229 | | − // TODO: Don't assume repo name == project name |
| 2230 | | − user, err := hubsrht.TrackersByUser(c.Client, ctx, username, r.name) |
| 2231 | | − if err == nil && user != nil && user.Project != nil { |
| 2232 | | − if len(user.Project.Trackers.Results) == 1 { |
| 2233 | | − r.name = user.Project.Trackers.Results[0].Name |
| 2231 | + user, err := gitsrht.RepositoryIDByUser(gitClient.Client, ctx, username, r.name) |
| 2232 | + if err != nil || user == nil || user.Repository == nil { |
| 2233 | + return nil, resource{}, errors.New("failed to retrieve RID for repository") |
| 2234 | + } |
| 2235 | + |
| 2236 | + hubClient := gitClient.withService(cmd, "hub", r.instance) |
| 2237 | + source, err := hubsrht.ProjectsBySource(hubClient.Client, ctx, user.Repository.Rid) |
| 2238 | + if err != nil { |
| 2239 | + return nil, resource{}, err |
| 2240 | + } else if source == nil { |
| 2241 | + return nil, resource{}, errors.New("this repository has no associated project") |
| 2242 | + } |
| 2243 | + |
| 2244 | + var projectName string |
| 2245 | + if len(source.Projects.Results) == 1 { |
| 2246 | + projectName = source.Projects.Results[0].Name |
| 2247 | + } else { |
| 2248 | + options := make([]huh.Option[string], 0, len(source.Projects.Results)) |
| 2249 | + for _, p := range source.Projects.Results { |
| 2250 | + options = append(options, huh.NewOption(p.Name, p.Name)) |
| 2251 | + } |
| 2252 | + |
| 2253 | + err := huh.NewSelect[string](). |
| 2254 | + Title("Choose a project from which you want to select a tracker"). |
| 2255 | + Options(options...). |
| 2256 | + Value(&projectName). |
| 2257 | + Run() |
| 2258 | + |
| 2259 | + if err != nil { |
| 2260 | + return nil, resource{}, err |
| 2261 | + } |
| 2262 | + } |
| 2263 | + |
| 2264 | + hubUser, err := hubsrht.TrackersByUser(hubClient.Client, ctx, username, projectName) |
| 2265 | + if err == nil && hubUser != nil && hubUser.Project != nil { |
| 2266 | + if len(hubUser.Project.Trackers.Results) == 1 { |
| 2267 | + r.name = hubUser.Project.Trackers.Results[0].Name |
| 2234 | 2268 | } else { |
| 2235 | 2269 | var trackers []string |
| 2236 | | − for _, t := range user.Project.Trackers.Results { |
| 2270 | + for _, t := range hubUser.Project.Trackers.Results { |
| 2237 | 2271 | trackers = append(trackers, t.Name) |
| 2238 | 2272 | } |
| 2239 | 2273 | |
| @@ -2267,7 +2301,6 @@ func getTrackerName(ctx context.Context, cmd *cobra.Command) (c *Client, r resou · 27 unmodified lines |
| 2267 | 2301 | } |
| 2268 | 2302 | |
| 2269 | 2303 | // TODO: if no tracker could be determined, ask the user for input |
| 2270 | | − // fallback to git |
| 2271 | 2304 | return c, r, nil |
| 2272 | 2305 | } |
| 2273 | 2306 | |