Critical/Major:
- Remove dead functions syncRepoNameFromArg and repoNameFromArg (used url pkg without import, would cause compile error)
- Migrate forge.lthn.ai/core/config → dappco.re/go/core/config in forge/config.go and gitea/config.go
- Propagate ListIssueCommentsIter errors in forge/meta.go and gitea/meta.go (was silently returning truncated count)
- Add RedactedToken() to gitea/client.go to avoid exposing raw API tokens
- Add 30s timeout to http.DefaultClient usage in gitea/prs.go via package-level httpClient
- Fix stringsx.Fields (bufio 64KiB limit), Repeat (wrong for negative/zero), Replace (ignored n param) to match stdlib
- Fix fmtx.Println to use fmt.Sprintln so spaces appear between operands
- Fix filepathx.Abs to use path/filepath for OS-aware path handling; wrap Getwd error
- Fix stdio.Write to return io.ErrShortWrite on partial writes
- Add mutex lock to jobrunner.Journal.Query to prevent data race with Append
- Add sync.RWMutex to ScmProvider; protect p.index reads/writes in pkg/api/provider.go
- Fix cmd/scm/cmd_index.go: append dir to repoPaths only after ReadDir confirms existence
- Fix manifest/compile.go: copy manifest before applying version override to avoid mutating caller
- Fix forge/labels.go: use ListOrgLabelsIter/ListRepoLabelsIter names in iterator error logs
- Wrap single-segment validation error in syncutil.ParseRepoName with function context
Minor:
- Fix import ordering (stdlib → forge.lthn.ai → third-party) in cmd/forge, cmd/collect, repos, cmd/gitea files
- Add t.Setenv("HOME", t.TempDir()) to gitea testhelpers and forge/labels_test.go
- Add iterator yield guard in forge/orgs_test.go
- Convert syncutil/repo_name_test.go to table-driven tests
- Use json.Marshal in pkg/api/provider_test.go instead of string concatenation
- Fix test naming (redundant/conflicting _Good/_Bad suffixes) across 10 test files
Co-Authored-By: Virgil <virgil@lethean.io>
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package forge
|
|
|
|
import (
|
|
"forge.lthn.ai/core/cli/pkg/cli"
|
|
|
|
fg "dappco.re/go/core/scm/forge"
|
|
fmt "dappco.re/go/core/scm/internal/ax/fmtx"
|
|
)
|
|
|
|
// Auth command flags.
|
|
var (
|
|
authURL string
|
|
authToken string
|
|
)
|
|
|
|
// addAuthCommand adds the 'auth' subcommand for authentication status and login.
|
|
func addAuthCommand(parent *cli.Command) {
|
|
cmd := &cli.Command{
|
|
Use: "auth",
|
|
Short: "Show authentication status",
|
|
Long: "Show the current Forgejo authentication status, or log in with a new token.",
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
return runAuth()
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&authURL, "url", "", "Forgejo instance URL")
|
|
cmd.Flags().StringVar(&authToken, "token", "", "API token (create at <url>/user/settings/applications)")
|
|
|
|
parent.AddCommand(cmd)
|
|
}
|
|
|
|
func runAuth() error {
|
|
// If credentials provided, save them first
|
|
if authURL != "" || authToken != "" {
|
|
if err := fg.SaveConfig(authURL, authToken); err != nil {
|
|
return err
|
|
}
|
|
if authURL != "" {
|
|
cli.Success(fmt.Sprintf("URL set to %s", authURL))
|
|
}
|
|
if authToken != "" {
|
|
cli.Success("Token saved")
|
|
}
|
|
}
|
|
|
|
// Always show current auth status
|
|
url, token, err := fg.ResolveConfig(authURL, authToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if token == "" {
|
|
cli.Blank()
|
|
cli.Print(" %s %s\n", dimStyle.Render("URL:"), valueStyle.Render(url))
|
|
cli.Print(" %s %s\n", dimStyle.Render("Auth:"), warningStyle.Render("not authenticated"))
|
|
cli.Print(" %s %s\n", dimStyle.Render("Hint:"), dimStyle.Render(fmt.Sprintf("core forge auth --token TOKEN (create at %s/user/settings/applications)", url)))
|
|
cli.Blank()
|
|
return nil
|
|
}
|
|
|
|
client, err := fg.NewFromConfig(authURL, authToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user, _, err := client.API().GetMyUserInfo()
|
|
if err != nil {
|
|
cli.Blank()
|
|
cli.Print(" %s %s\n", dimStyle.Render("URL:"), valueStyle.Render(url))
|
|
cli.Print(" %s %s\n", dimStyle.Render("Auth:"), errorStyle.Render("token invalid or expired"))
|
|
cli.Blank()
|
|
return nil
|
|
}
|
|
|
|
cli.Blank()
|
|
cli.Success(fmt.Sprintf("Authenticated to %s", client.URL()))
|
|
cli.Print(" %s %s\n", dimStyle.Render("User:"), valueStyle.Render(user.UserName))
|
|
cli.Print(" %s %s\n", dimStyle.Render("Email:"), valueStyle.Render(user.Email))
|
|
if user.IsAdmin {
|
|
cli.Print(" %s %s\n", dimStyle.Render("Role:"), infoStyle.Render("admin"))
|
|
}
|
|
cli.Blank()
|
|
|
|
return nil
|
|
}
|