mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Add MirrorInterval to the API (#14163)
* Added MirrorInterval to the API * Remove MirrorInterval from CreateRepository * Removed Duplicate UpdateMirror Function * Updated Error Logging * Update Log Message for is not Mirror Co-authored-by: 6543 <6543@obermui.de> * Delete Debug Statement that snuck in Co-authored-by: zeripath <art27@cantab.net> * Add Check for If Interval is too small * Output to API Call * Add Error Object when time is Less than Min Interval * Frequency Error Message Co-authored-by: zeripath <art27@cantab.net> * Allow Zero Mirror Interval Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -141,6 +141,7 @@ func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
 | 
			
		||||
		PullRequests:   form.PullRequests,
 | 
			
		||||
		Releases:       form.Releases,
 | 
			
		||||
		GitServiceType: gitServiceType,
 | 
			
		||||
		MirrorInterval: form.MirrorInterval,
 | 
			
		||||
	}
 | 
			
		||||
	if opts.Mirror {
 | 
			
		||||
		opts.Issues = false
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/modules/context"
 | 
			
		||||
@@ -501,6 +502,12 @@ func Edit(ctx *context.APIContext, opts api.EditRepoOption) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if opts.MirrorInterval != nil {
 | 
			
		||||
		if err := updateMirrorInterval(ctx, opts); err != nil {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -783,6 +790,38 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// updateMirrorInterval updates the repo's mirror Interval
 | 
			
		||||
func updateMirrorInterval(ctx *context.APIContext, opts api.EditRepoOption) error {
 | 
			
		||||
	repo := ctx.Repo.Repository
 | 
			
		||||
 | 
			
		||||
	if opts.MirrorInterval != nil {
 | 
			
		||||
		if !repo.IsMirror {
 | 
			
		||||
			err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
 | 
			
		||||
			ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if err := repo.GetMirror(); err != nil {
 | 
			
		||||
			log.Error("Failed to get mirror: %s", err)
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "MirrorInterval", err)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if interval, err := time.ParseDuration(*opts.MirrorInterval); err == nil {
 | 
			
		||||
			repo.Mirror.Interval = interval
 | 
			
		||||
			if err := models.UpdateMirror(repo.Mirror); err != nil {
 | 
			
		||||
				log.Error("Failed to Set Mirror Interval: %s", err)
 | 
			
		||||
				ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			log.Trace("Repository %s/%s Mirror Interval was Updated to %s", ctx.Repo.Owner.Name, repo.Name, interval)
 | 
			
		||||
		} else {
 | 
			
		||||
			log.Error("Wrong format for MirrorInternal Sent: %s", err)
 | 
			
		||||
			ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete one repository
 | 
			
		||||
func Delete(ctx *context.APIContext) {
 | 
			
		||||
	// swagger:operation DELETE /repos/{owner}/{repo} repository repoDelete
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user