-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[API] add new endpoints for push mirrors management #19841
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
Changes from 5 commits
cf10d77
015a57a
fb9ea68
a4b40bd
4a1fb91
5c5eef3
a79cd85
99f6a77
4141460
0742732
4fa4660
97204df
633095d
d507d47
179e935
37ba6cf
4560d3b
b4e0977
addd7f1
4071774
9206fc5
6950ff1
3e90998
0d39152
88f620c
b23979a
c775d3c
614d724
85eecf5
aabe5e9
4a54502
639268a
2645df8
61e493e
da57680
e50174c
d59a235
5cff07e
0884346
1886253
cadcfb7
c535692
8578582
1309dec
d9ddbcf
d1f2993
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,13 @@ func GetPushMirrorByID(ID int64) (*PushMirror, error) { | |
} | ||
|
||
// GetPushMirrorsByRepoID returns push-mirror information of a repository. | ||
func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) { | ||
func GetPushMirrorsByRepoID(repoID int64, listOptions db.ListOptions) ([]*PushMirror, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the other functions now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To summarize, currently we have 2 functions :
Should we merge also this one ? if soo all the calling functions should parse the response as a list and I don't think it's a good idea There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woops I'd missed that. |
||
mirrors := make([]*PushMirror, 0, 10) | ||
return mirrors, db.GetEngine(db.DefaultContext).Where("repo_id=?", repoID).Find(&mirrors) | ||
sess := db.GetEngine(db.DefaultContext).Where("repo_id = ?", repoID) | ||
if listOptions.Page != 0 { | ||
sess = db.SetSessionPagination(sess, &listOptions) | ||
} | ||
return mirrors, sess.Find(&mirrors) | ||
} | ||
|
||
// PushMirrorsIterate iterates all push-mirror repositories. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package convert | ||
|
||
import ( | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/git" | ||
api "code.gitea.io/gitea/modules/structs" | ||
) | ||
|
||
// ToPushMirror convert from repo_model.PushMirror and remoteAddress to api.TopicResponse | ||
func ToPushMirror(pm *repo_model.PushMirror, repo *repo_model.Repository) *api.PushMirror { | ||
remoteAddress, _ := getMirrorRemoteAddress(repo, pm.RemoteName) | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return &api.PushMirror{ | ||
ID: pm.ID, | ||
RepoName: repo.Name, | ||
RemoteName: pm.RemoteName, | ||
RemoteAddress: remoteAddress, | ||
CreatedUnix: pm.CreatedUnix.FormatLong(), | ||
LastUpdateUnix: pm.LastUpdateUnix.FormatLong(), | ||
LastError: pm.LastError, | ||
Interval: pm.Interval.String(), | ||
} | ||
} | ||
|
||
func getMirrorRemoteAddress(repo *repo_model.Repository, remoteName string) (string, error) { | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
u, err := git.GetRemoteAddress(git.DefaultContext, repo.RepoPath(), remoteName) | ||
if err != nil { | ||
return "", err | ||
} | ||
// remove confidential information | ||
u.User = nil | ||
return u.String(), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package structs | ||
|
||
// CreatePushMirrorOption represents need information to create a push mirror of a repository. | ||
type CreatePushMirrorOption struct { | ||
RemoteAddress string `json:"remoteAddress"` | ||
RemoteUsername string `json:"remoteUsername"` | ||
RemotePassword string `json:"remotePassword"` | ||
Interval string `json:"interval"` | ||
} | ||
|
||
// PushMirror represents information of a push mirror | ||
// swagger:model | ||
type PushMirror struct { | ||
ID int64 `json:"id"` | ||
RepoName string `json:"repoName"` | ||
RemoteName string `json:"remoteName"` | ||
RemoteAddress string `json:"remoteAddress"` | ||
CreatedUnix string `json:"created"` | ||
LastUpdateUnix string `json:"lastUpdate"` | ||
LastError string `json:"lastError"` | ||
Interval string `json:"interval"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.