mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Add RemoteAddress
to mirrors (#26952)
This PR adds a new field `RemoteAddress` to both mirror types which contains the sanitized remote address for easier (database) access to that information. Will be used in the audit PR if merged.
This commit is contained in:
@@ -5,21 +5,16 @@ 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) (*api.PushMirror, error) {
|
||||
repo := pm.GetRepository()
|
||||
remoteAddress, err := getRemoteAddress(repo, pm.RemoteName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &api.PushMirror{
|
||||
RepoName: repo.Name,
|
||||
RemoteName: pm.RemoteName,
|
||||
RemoteAddress: remoteAddress,
|
||||
RemoteAddress: pm.RemoteAddress,
|
||||
CreatedUnix: pm.CreatedUnix.FormatLong(),
|
||||
LastUpdateUnix: pm.LastUpdateUnix.FormatLong(),
|
||||
LastError: pm.LastError,
|
||||
@@ -27,13 +22,3 @@ func ToPushMirror(pm *repo_model.PushMirror) (*api.PushMirror, error) {
|
||||
SyncOnCommit: pm.SyncOnCommit,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getRemoteAddress(repo *repo_model.Repository, remoteName string) (string, error) {
|
||||
url, err := git.GetRemoteURL(git.DefaultContext, repo.RepoPath(), remoteName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// remove confidential information
|
||||
url.User = nil
|
||||
return url.String(), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user