mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
chore(deps): fold in the dependency and action updates of #1104; import long non-ASCII descriptions
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
7 files changed
+71
-30
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.dev/tea/internal/clierr"
|
||||
"gitea.dev/tea/internal/services"
|
||||
@@ -186,8 +187,8 @@ func validateMigrationFlags(cmd *cobra.Command, opts services.RepositoryMigratio
|
||||
return clierr.Wrap(clierr.Usage, errors.New("server path imports use --service git without remote credentials"))
|
||||
case opts.Timeout <= 0:
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--timeout must be positive"))
|
||||
case len(opts.Description) > 2048:
|
||||
return clierr.Wrap(clierr.Usage, errors.New("description cannot exceed 2048 bytes"))
|
||||
case utf8.RuneCountInString(opts.Description) > 2048:
|
||||
return clierr.Wrap(clierr.Usage, errors.New("description cannot exceed 2048 characters"))
|
||||
case opts.LFSEndpoint != "" && !opts.LFS:
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--lfs-endpoint requires --lfs"))
|
||||
case opts.Mirror && metadata:
|
||||
|
||||
@@ -6,6 +6,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -101,6 +102,13 @@ func (s Repositories) Migrate(ctx context.Context, opts RepositoryMigrationOptio
|
||||
defer cancel()
|
||||
s.Client = s.Client.WithTimeout(opts.Timeout)
|
||||
}
|
||||
// TODO(sdk): MigrateRepoOption.Validate counts the description in bytes, but Gitea allows 2048
|
||||
// characters; a longer one is set by an edit once the (synchronous) migration is done.
|
||||
description := opts.Description
|
||||
later := len(description) > sdkDescriptionLimit
|
||||
if later {
|
||||
opts.Description = ""
|
||||
}
|
||||
item, _, err := call(ctx, s.Client, func(ctx context.Context, c *gitea.Client) (*gitea.Repository, *gitea.Response, error) {
|
||||
return c.Repositories.MigrateRepo(ctx, gitea.MigrateRepoOption{
|
||||
RepoName: opts.Name, RepoOwner: opts.Owner, CloneAddr: opts.CloneURL, Service: gitea.GitServiceType(opts.Service),
|
||||
@@ -117,5 +125,13 @@ func (s Repositories) Migrate(ctx context.Context, opts RepositoryMigrationOptio
|
||||
}
|
||||
return Repository{}, err
|
||||
}
|
||||
return repositoryFrom(item), nil
|
||||
migrated := repositoryFrom(item)
|
||||
if later {
|
||||
edited, err := s.Edit(ctx, migrated.FullName, RepositoryEdit{Description: &description})
|
||||
if err != nil {
|
||||
return migrated, fmt.Errorf("repository %s was imported, but setting its description failed: %w", migrated.FullName, err)
|
||||
}
|
||||
return edited, nil
|
||||
}
|
||||
return migrated, nil
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -89,3 +90,25 @@ func TestRepositoryMigrationKeepsMessageWithoutCredentials(t *testing.T) {
|
||||
_, err := (Repositories{Client: client}).Migrate(context.Background(), RepositoryMigrationOptions{Name: "imported", CloneURL: "https://source.test/repo", Service: "git"})
|
||||
require.ErrorContains(t, err, "repository already exists")
|
||||
}
|
||||
|
||||
func TestRepositoryMigrateSetsADescriptionBeyondTheSDKByteLimitByEdit(t *testing.T) {
|
||||
description := strings.Repeat("日", 800) // 2400 bytes, 800 characters
|
||||
var methods []string
|
||||
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
methods = append(methods, r.Method)
|
||||
body := requestJSON(t, r)
|
||||
switch r.Method {
|
||||
case http.MethodPost:
|
||||
require.Empty(t, body["description"])
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
_, _ = w.Write([]byte(`{"id":2,"name":"imported","full_name":"alice/imported"}`))
|
||||
case http.MethodPatch:
|
||||
require.Equal(t, description, body["description"])
|
||||
_, _ = w.Write([]byte(`{"id":2,"name":"imported","full_name":"alice/imported","description":"` + description + `"}`))
|
||||
}
|
||||
}))
|
||||
migrated, err := (Repositories{Client: client}).Migrate(context.Background(), RepositoryMigrationOptions{Name: "imported", CloneURL: "https://source.test/repo", Service: "git", Description: description})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{http.MethodPost, http.MethodPatch}, methods)
|
||||
require.Equal(t, description, migrated.Description)
|
||||
}
|
||||
Reference in new issue
Block a user