aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-12-03 15:05:48 +0100
committerGitHub <noreply@github.com>2020-12-03 16:05:48 +0200
commit4353cf96c003cf55adfaf28b494a9d78c5226202 (patch)
tree15a80476df2ec0f0aefcca71385c9873752b96e1 /modules
parente306c292ac478c0f09b2c02908e485132669aacb (diff)
downloadgitea-4353cf96c003cf55adfaf28b494a9d78c5226202.tar.gz
gitea-4353cf96c003cf55adfaf28b494a9d78c5226202.zip
Move LFSLock APIFormat into convert package (#13808)
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/convert.go14
-rw-r--r--modules/lfs/locks.go15
2 files changed, 22 insertions, 7 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index 9b20c683be..4d4d9396fe 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -7,6 +7,8 @@ package convert
import (
"fmt"
+ "strconv"
+ "time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
@@ -365,3 +367,15 @@ func ToCommitStatus(status *models.CommitStatus) *api.Status {
return apiStatus
}
+
+// ToLFSLock convert a LFSLock to api.LFSLock
+func ToLFSLock(l *models.LFSLock) *api.LFSLock {
+ return &api.LFSLock{
+ ID: strconv.FormatInt(l.ID, 10),
+ Path: l.Path,
+ LockedAt: l.Created.Round(time.Second),
+ Owner: &api.LFSLockOwner{
+ Name: l.Owner.DisplayName(),
+ },
+ }
+}
diff --git a/modules/lfs/locks.go b/modules/lfs/locks.go
index ec9da40ec7..a529afe1b9 100644
--- a/modules/lfs/locks.go
+++ b/modules/lfs/locks.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -60,7 +61,7 @@ func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *mode
return
}
ctx.JSON(200, api.LFSLockList{
- Locks: []*api.LFSLock{lock.APIFormat()},
+ Locks: []*api.LFSLock{convert.ToLFSLock(lock)},
})
}
@@ -140,7 +141,7 @@ func GetListLockHandler(ctx *context.Context) {
lockListAPI := make([]*api.LFSLock, len(lockList))
next := ""
for i, l := range lockList {
- lockListAPI[i] = l.APIFormat()
+ lockListAPI[i] = convert.ToLFSLock(l)
}
if limit > 0 && len(lockList) == limit {
next = strconv.Itoa(cursor + 1)
@@ -198,7 +199,7 @@ func PostLockHandler(ctx *context.Context) {
if err != nil {
if models.IsErrLFSLockAlreadyExist(err) {
ctx.JSON(409, api.LFSLockError{
- Lock: lock.APIFormat(),
+ Lock: convert.ToLFSLock(lock),
Message: "already created lock",
})
return
@@ -216,7 +217,7 @@ func PostLockHandler(ctx *context.Context) {
})
return
}
- ctx.JSON(201, api.LFSLockResponse{Lock: lock.APIFormat()})
+ ctx.JSON(201, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
}
// VerifyLockHandler list locks for verification
@@ -274,9 +275,9 @@ func VerifyLockHandler(ctx *context.Context) {
lockTheirsListAPI := make([]*api.LFSLock, 0, len(lockList))
for _, l := range lockList {
if l.Owner.ID == ctx.User.ID {
- lockOursListAPI = append(lockOursListAPI, l.APIFormat())
+ lockOursListAPI = append(lockOursListAPI, convert.ToLFSLock(l))
} else {
- lockTheirsListAPI = append(lockTheirsListAPI, l.APIFormat())
+ lockTheirsListAPI = append(lockTheirsListAPI, convert.ToLFSLock(l))
}
}
ctx.JSON(200, api.LFSLockListVerify{
@@ -340,5 +341,5 @@ func UnLockHandler(ctx *context.Context) {
})
return
}
- ctx.JSON(200, api.LFSLockResponse{Lock: lock.APIFormat()})
+ ctx.JSON(200, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
}