mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Validate migration files (#18203)
JSON Schema validation for data used by Gitea during migrations Discussion at https://forum.forgefriends.org/t/common-json-schema-for-repository-information/563 Co-authored-by: Loïc Dachary <loic@dachary.org>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							49dd906753
						
					
				
				
					commit
					3bb028cc46
				
			| @@ -604,13 +604,13 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) { | ||||
| } | ||||
|  | ||||
| // RestoreRepository restore a repository from the disk directory | ||||
| func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string, units []string) error { | ||||
| func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string, units []string, validation bool) error { | ||||
| 	doer, err := user_model.GetAdminUser() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	uploader := NewGiteaLocalUploader(ctx, doer, ownerName, repoName) | ||||
| 	downloader, err := NewRepositoryRestorer(ctx, baseDir, ownerName, repoName) | ||||
| 	downloader, err := NewRepositoryRestorer(ctx, baseDir, ownerName, repoName, validation) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|   | ||||
| @@ -19,23 +19,25 @@ import ( | ||||
| // RepositoryRestorer implements an Downloader from the local directory | ||||
| type RepositoryRestorer struct { | ||||
| 	base.NullDownloader | ||||
| 	ctx       context.Context | ||||
| 	baseDir   string | ||||
| 	repoOwner string | ||||
| 	repoName  string | ||||
| 	ctx        context.Context | ||||
| 	baseDir    string | ||||
| 	repoOwner  string | ||||
| 	repoName   string | ||||
| 	validation bool | ||||
| } | ||||
|  | ||||
| // NewRepositoryRestorer creates a repository restorer which could restore repository from a dumped folder | ||||
| func NewRepositoryRestorer(ctx context.Context, baseDir, owner, repoName string) (*RepositoryRestorer, error) { | ||||
| func NewRepositoryRestorer(ctx context.Context, baseDir, owner, repoName string, validation bool) (*RepositoryRestorer, error) { | ||||
| 	baseDir, err := filepath.Abs(baseDir) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &RepositoryRestorer{ | ||||
| 		ctx:       ctx, | ||||
| 		baseDir:   baseDir, | ||||
| 		repoOwner: owner, | ||||
| 		repoName:  repoName, | ||||
| 		ctx:        ctx, | ||||
| 		baseDir:    baseDir, | ||||
| 		repoOwner:  owner, | ||||
| 		repoName:   repoName, | ||||
| 		validation: validation, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| @@ -114,7 +116,7 @@ func (r *RepositoryRestorer) GetTopics() ([]string, error) { | ||||
| func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) { | ||||
| 	milestones := make([]*base.Milestone, 0, 10) | ||||
| 	p := filepath.Join(r.baseDir, "milestone.yml") | ||||
| 	_, err := os.Stat(p) | ||||
| 	err := base.Load(p, &milestones, r.validation) | ||||
| 	if err != nil { | ||||
| 		if os.IsNotExist(err) { | ||||
| 			return nil, nil | ||||
| @@ -122,15 +124,6 @@ func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	bs, err := os.ReadFile(p) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	err = yaml.Unmarshal(bs, &milestones) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return milestones, nil | ||||
| } | ||||
|  | ||||
| @@ -193,7 +186,7 @@ func (r *RepositoryRestorer) GetLabels() ([]*base.Label, error) { | ||||
| func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool, error) { | ||||
| 	issues := make([]*base.Issue, 0, 10) | ||||
| 	p := filepath.Join(r.baseDir, "issue.yml") | ||||
| 	_, err := os.Stat(p) | ||||
| 	err := base.Load(p, &issues, r.validation) | ||||
| 	if err != nil { | ||||
| 		if os.IsNotExist(err) { | ||||
| 			return nil, true, nil | ||||
| @@ -201,15 +194,6 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool, | ||||
| 		return nil, false, err | ||||
| 	} | ||||
|  | ||||
| 	bs, err := os.ReadFile(p) | ||||
| 	if err != nil { | ||||
| 		return nil, false, err | ||||
| 	} | ||||
|  | ||||
| 	err = yaml.Unmarshal(bs, &issues) | ||||
| 	if err != nil { | ||||
| 		return nil, false, err | ||||
| 	} | ||||
| 	for _, issue := range issues { | ||||
| 		issue.Context = base.BasicIssueContext(issue.Number) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user