Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RepoEdit via API fails with "repo is not a mirror, can not change mirror interval" #30921

Closed
PulsarFX opened this issue May 9, 2024 · 9 comments · Fixed by #30963
Closed
Labels

Comments

@PulsarFX
Copy link

PulsarFX commented May 9, 2024

Description

When editing a repo with the GiteaAPI we get this error:

GiteaAPI.Client.ApiException
  HResult=0x80131500
  Message=Error calling RepoEdit: {"message":"repo is not a mirror, can not change mirror interval","url":"http://...:3000/api/swagger"}

  Source=GiteaAPI
  StackTrace:
   at GiteaAPI.Api.RepositoryApi.<RepoEditWithHttpInfoAsync>d__240.MoveNext()
   at GiteaAPI.Api.RepositoryApi.<RepoEditAsync>d__239.MoveNext()
   

when calling RepoEditAsync with some options and EditRepoOption { MirrorInterval=null } which should do nothing to the mirror interval, as stated in RepoEditAsync summary: "Edit a repository's properties. Only fields that are set will be changed"

This happens in 1.22-RC.1 and also 1.21.11 , but not in 1.21.1 (that's the versions we tested)

Gitea Version

1.22-RC.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

  • windows go git,
  • linux gitea in docker

Database

SQLite

@wxiaoguang

This comment was marked as outdated.

@wxiaoguang
Copy link
Contributor

Have you set EnablePrune? It seems that EnablePrune is also for mirror only.

If neither MirrorInterval nor EnablePrune is set, then I guess API won't report the error?

@PulsarFX
Copy link
Author

PulsarFX commented May 9, 2024

I have to dig some more. Hand crafted request via swagger Gui runs fine:

curl -X 'PATCH' \
  'http://localhost:3000/api/v1/repos/testdb/testdb' \
  -H 'accept: application/json' \
  -H 'authorization: Basic b.....z' \
  -H 'Content-Type: application/json' \
  -d '{
  "archived": false,
  "description": "repo description",
  "has_issues": false,
  "has_packages": true,
  "has_projects": false,
  "mirror_interval": null,
  "template": false
}'

Existing C# code, which is calling gitea via openApi generated c# client fails:

await _repositoryApi.RepoEditAsync(organizationName, organizationName, 
                 new EditRepoOption() { HasPullRequests = false });

This is the payload for this issue test:
grafik

@PulsarFX
Copy link
Author

PulsarFX commented May 9, 2024

quick check: openApi did not generate different code for class EditRepoOption between 1.21.3 and 1.21.11:

        /// <summary>
        /// set to a string like &#x60;8h30m0s&#x60; to set the mirror interval time
        /// </summary>
        /// <value>set to a string like &#x60;8h30m0s&#x60; to set the mirror interval time</value>
        [DataMember(Name = "mirror_interval", EmitDefaultValue = false)]
        public string MirrorInterval { get; set; }

Executing method RepositoryApi RepoEditWithHttpInfoAsync didn't change neither.

@wxiaoguang
Copy link
Contributor

Hmm yes, the problem is that EnablePrune = false makes the backend runs the "update mirror" logic ......

Maybe it could be fixed by fine-tuning the logic again.

@PulsarFX
Copy link
Author

maybe make EnablePrune nullable, like public bool? EnablePrune {get; set;} ?
Both states are valid for calling the api. So, to not use it, a third state is required. In swagger, the property can simply be left out, but not in EditRepoOption as it is just of type bool.

@wxiaoguang
Copy link
Contributor

Actually, the EnablePrune has the same definition as MirrorInterval. Ideally the SDKs should know that EnablePrune is optional and shouldn't send it to server, no idea why the SDK still sends it.

	// set to a string like `8h30m0s` to set the mirror interval time
	MirrorInterval *string `json:"mirror_interval,omitempty"`
	// enable prune - remove obsolete remote-tracking references when mirroring
	EnablePrune *bool `json:"enable_prune,omitempty"`

I think we can do this on Gitea side: " Simplify mirror repository API logic #30963 " and have simpler code.

GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue May 17, 2024
wxiaoguang added a commit that referenced this issue May 18, 2024
Backport #30963 by wxiaoguang

Fix #30921

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@wxiaoguang
Copy link
Contributor

1.22 nightly is ready, could you try it? https://dl.gitea.com/gitea/1.22/ or by docker "1.22-nightly"

@PulsarFX
Copy link
Author

works in the just released Gitea 1.22.
Thanks alot!

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants