feat: add validation for object-format flag in repo create command (#741)

This PR adds validation for the `--object-format` flag in the `repo create` command. The flag now accepts only `sha1` or `sha256` as valid values, and returns an error for any other value.

Changes:
- Added validation in `runRepoCreate` to check for valid object format values
- Added unit tests to verify the validation logic
- Fixed the field name from `ObjectFormat` to `ObjectFormatName` to match the SDK

The changes ensure that users get clear error messages when using invalid object format values, improving the user experience.

Fix #727
Fix #660
Fix #767

Co-authored-by: techknowlogick <techknowlogick@noreply.gitea.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/741
Reviewed-by: TheFox0x7 <thefox0x7@noreply.gitea.com>
This commit is contained in:
Lunny Xiao
2025-09-12 16:51:43 +00:00
parent 2ca114e309
commit cc20b52ab3
5 changed files with 157 additions and 13 deletions

View File

@ -167,8 +167,12 @@ func generateToken(login config.Login, user, pass, otp, scopes string) (string,
}
var tokenScopes []gitea.AccessTokenScope
for _, scope := range strings.Split(scopes, ",") {
tokenScopes = append(tokenScopes, gitea.AccessTokenScope(strings.TrimSpace(scope)))
if len(scopes) == 0 {
tokenScopes = []gitea.AccessTokenScope{gitea.AccessTokenScopeAll}
} else {
for _, scope := range strings.Split(scopes, ",") {
tokenScopes = append(tokenScopes, gitea.AccessTokenScope(strings.TrimSpace(scope)))
}
}
t, _, err := client.CreateAccessToken(gitea.CreateAccessTokenOption{