mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-10-08 14:40:49 +02:00
F3: Forgejo driver and CLI
user, topic, project, label, milestone, repository, pull_request, release, asset, comment, reaction, review providers Signed-off-by: Earl Warren <contact@earl-warren.org> Preserve file size when creating attachments Introduced inc6f5029708
repoList.LoadAttributes has a ctx argument now Rename `repo.GetOwner` to `repo.LoadOwner`bd66fa586a
upgrade to the latest gof3
This commit is contained in:
parent
0312983dcb
commit
c770713656
|
@ -100,6 +100,9 @@ issues:
|
|||
- gosec
|
||||
- unparam
|
||||
- staticcheck
|
||||
- path: services/f3/driver/driver.go
|
||||
linters:
|
||||
- typecheck
|
||||
- path: models/migrations/v
|
||||
linters:
|
||||
- gocyclo
|
||||
|
|
15
assets/go-licenses.json
generated
15
assets/go-licenses.json
generated
|
@ -494,6 +494,11 @@
|
|||
"path": "github.com/golang/snappy/LICENSE",
|
||||
"licenseText": "Copyright (c) 2011 The Snappy-Go Authors. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n * Neither the name of Google Inc. nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
},
|
||||
{
|
||||
"name": "github.com/google/go-cmp/cmp",
|
||||
"path": "github.com/google/go-cmp/cmp/LICENSE",
|
||||
"licenseText": "Copyright (c) 2017 The Go Authors. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n * Neither the name of Google Inc. nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
},
|
||||
{
|
||||
"name": "github.com/google/go-github/v51/github",
|
||||
"path": "github.com/google/go-github/v51/github/LICENSE",
|
||||
|
@ -1004,6 +1009,11 @@
|
|||
"path": "golang.org/x/crypto/LICENSE",
|
||||
"licenseText": "Copyright (c) 2009 The Go Authors. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n * Neither the name of Google Inc. nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
},
|
||||
{
|
||||
"name": "golang.org/x/exp",
|
||||
"path": "golang.org/x/exp/LICENSE",
|
||||
"licenseText": "Copyright (c) 2009 The Go Authors. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n * Neither the name of Google Inc. nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
},
|
||||
{
|
||||
"name": "golang.org/x/image",
|
||||
"path": "golang.org/x/image/LICENSE",
|
||||
|
@ -1084,6 +1094,11 @@
|
|||
"path": "gopkg.in/yaml.v3/LICENSE",
|
||||
"licenseText": "\nThis project is covered by two different licenses: MIT and Apache.\n\n#### MIT License ####\n\nThe following files were ported to Go from C files of libyaml, and thus\nare still covered by their original MIT license, with the additional\ncopyright staring in 2011 when the project was ported over:\n\n apic.go emitterc.go parserc.go readerc.go scannerc.go\n writerc.go yamlh.go yamlprivateh.go\n\nCopyright (c) 2006-2010 Kirill Simonov\nCopyright (c) 2006-2011 Kirill Simonov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n### Apache License ###\n\nAll the remaining project files are covered by the Apache license:\n\nCopyright (c) 2011-2019 Canonical Ltd\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n"
|
||||
},
|
||||
{
|
||||
"name": "lab.forgefriends.org/friendlyforgeformat/gof3",
|
||||
"path": "lab.forgefriends.org/friendlyforgeformat/gof3/LICENSE",
|
||||
"licenseText": "Permission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
|
||||
},
|
||||
{
|
||||
"name": "mvdan.cc/xurls/v2",
|
||||
"path": "mvdan.cc/xurls/v2/LICENSE",
|
||||
|
|
109
cmd/f3.go
Normal file
109
cmd/f3.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/services/f3/util"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3"
|
||||
f3_common "lab.forgefriends.org/friendlyforgeformat/gof3/forges/common"
|
||||
f3_format "lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
)
|
||||
|
||||
var CmdF3 = cli.Command{
|
||||
Name: "f3",
|
||||
Usage: "Friendly Forge Format (F3) format export/import.",
|
||||
Description: "Import or export a repository from or to the Friendly Forge Format (F3) format.",
|
||||
Action: runF3,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "directory",
|
||||
Value: "./f3",
|
||||
Usage: "Path of the directory where the F3 dump is stored",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "user",
|
||||
Value: "",
|
||||
Usage: "The name of the user who owns the repository",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repository",
|
||||
Value: "",
|
||||
Usage: "The name of the repository",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "no-pull-request",
|
||||
Usage: "Do not dump pull requests",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "import",
|
||||
Usage: "Import from the directory",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "export",
|
||||
Usage: "Export to the directory",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func runF3(ctx *cli.Context) error {
|
||||
stdCtx, cancel := installSignals()
|
||||
defer cancel()
|
||||
|
||||
if err := initDB(stdCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := git.InitSimple(stdCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return RunF3(stdCtx, ctx)
|
||||
}
|
||||
|
||||
func RunF3(stdCtx context.Context, ctx *cli.Context) error {
|
||||
doer, err := user_model.GetAdminUser()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
features := gof3.AllFeatures
|
||||
if ctx.Bool("no-pull-request") {
|
||||
features.PullRequests = false
|
||||
}
|
||||
|
||||
forgejo := util.ForgejoForgeRoot(features, doer)
|
||||
f3 := util.F3ForgeRoot(features, ctx.String("directory"))
|
||||
|
||||
if ctx.Bool("export") {
|
||||
forgejo.Forge.Users.List(stdCtx)
|
||||
user := forgejo.Forge.Users.GetFromFormat(stdCtx, &f3_format.User{UserName: ctx.String("user")})
|
||||
if user.IsNil() {
|
||||
return fmt.Errorf("%s is not a known user", ctx.String("user"))
|
||||
}
|
||||
|
||||
user.Projects.List(stdCtx)
|
||||
project := user.Projects.GetFromFormat(stdCtx, &f3_format.Project{Name: ctx.String("repository")})
|
||||
if project.IsNil() {
|
||||
return fmt.Errorf("%s/%s is not a known repository", ctx.String("user"), ctx.String("repository"))
|
||||
}
|
||||
|
||||
options := f3_common.NewMirrorOptionsRecurse(user, project)
|
||||
f3.Forge.Mirror(stdCtx, forgejo.Forge, options)
|
||||
fmt.Println("exported")
|
||||
} else if ctx.Bool("import") {
|
||||
options := f3_common.NewMirrorOptionsRecurse()
|
||||
forgejo.Forge.Mirror(stdCtx, f3.Forge, options)
|
||||
fmt.Println("imported")
|
||||
} else {
|
||||
return fmt.Errorf("either --import or --export must be specified")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -2439,6 +2439,15 @@ ROUTER = console
|
|||
;; If a domain is allowed by ALLOWED_DOMAINS, this option will be ignored.
|
||||
;ALLOW_LOCALNETWORKS = false
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;[F3]
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Enable/Disable Friendly Forge Format (F3)
|
||||
;ENABLED = true
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;[federation]
|
||||
|
|
6
go.mod
6
go.mod
|
@ -5,7 +5,7 @@ go 1.19
|
|||
require (
|
||||
code.gitea.io/actions-proto-go v0.2.1
|
||||
code.gitea.io/gitea-vet v0.2.2
|
||||
code.gitea.io/sdk/gitea v0.15.1
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20230419161926-24a404e5610c
|
||||
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
|
||||
gitea.com/go-chi/binding v0.0.0-20221013104517-b29891619681
|
||||
gitea.com/go-chi/cache v0.2.0
|
||||
|
@ -115,6 +115,7 @@ require (
|
|||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/ini.v1 v1.67.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
lab.forgefriends.org/friendlyforgeformat/gof3 v0.0.0-20230427084437-fabab01062d0
|
||||
mvdan.cc/xurls/v2 v2.4.0
|
||||
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
|
||||
xorm.io/builder v0.3.12
|
||||
|
@ -165,6 +166,7 @@ require (
|
|||
github.com/couchbase/goutils v0.0.0-20210118111533-e33d3ffb5401 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/davidmz/go-pageant v1.0.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dlclark/regexp2 v1.8.1 // indirect
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect
|
||||
|
@ -193,6 +195,7 @@ require (
|
|||
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/go-tpm v0.3.3 // indirect
|
||||
github.com/gorilla/css v1.0.0 // indirect
|
||||
|
@ -275,6 +278,7 @@ require (
|
|||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20220516143420-24438e51023a // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
|
|
13
go.sum
13
go.sum
|
@ -42,11 +42,10 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
|
|||
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
||||
code.gitea.io/actions-proto-go v0.2.1 h1:ToMN/8thz2q10TuCq8dL2d8mI+/pWpJcHCvG+TELwa0=
|
||||
code.gitea.io/actions-proto-go v0.2.1/go.mod h1:00ys5QDo1iHN1tHNvvddAcy2W/g+425hQya1cCSvq9A=
|
||||
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||
code.gitea.io/gitea-vet v0.2.2 h1:TEOV/Glf38iGmKzKP0EB++Z5OSL4zGg3RrAvlwaMuvk=
|
||||
code.gitea.io/gitea-vet v0.2.2/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||
code.gitea.io/sdk/gitea v0.15.1 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M=
|
||||
code.gitea.io/sdk/gitea v0.15.1/go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20230419161926-24a404e5610c h1:Fii6iLyyhq49iJqzudOUgE1OfrhYTH+8/tD4ykNf35U=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20230419161926-24a404e5610c/go.mod h1:ndkDk99BnfiUCCYEUhpNzi0lpmApXlwRFqClBlOlEBg=
|
||||
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570 h1:TXbikPqa7YRtfU9vS6QJBg77pUvbEb6StRdZO8t1bEY=
|
||||
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570/go.mod h1:IIAjsijsd8q1isWX8MACefDEgTQslQ4stk2AeeTt3kM=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
|
@ -279,6 +278,8 @@ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGii
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
|
||||
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d/go.mod h1:tmAIfUFEirG/Y8jhZ9M+h36obRZAk/1fcSpXwAVlfqE=
|
||||
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
|
@ -374,6 +375,7 @@ github.com/go-enry/go-enry/v2 v2.8.3 h1:BwvNrN58JqBJhyyVdZSl5QD3xoxEEGYUrRyPh31F
|
|||
github.com/go-enry/go-enry/v2 v2.8.3/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
|
||||
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
|
||||
github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
|
||||
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
||||
github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e h1:oRq/fiirun5HqlEWMLIcDmLpIELlG4iGbd0s8iqgPi8=
|
||||
github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
||||
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||
|
@ -1309,6 +1311,7 @@ golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPh
|
|||
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
|
@ -1329,6 +1332,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
|
|||
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
||||
golang.org/x/exp v0.0.0-20220516143420-24438e51023a h1:tiLLxEjKNE6Hrah/Dp/cyHvsyjDLcMFSocOHO5XDmOM=
|
||||
golang.org/x/exp v0.0.0-20220516143420-24438e51023a/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
||||
|
@ -1797,6 +1802,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
lab.forgefriends.org/friendlyforgeformat/gof3 v0.0.0-20230427084437-fabab01062d0 h1:5y3hSNZGWNUpyRpEGWAQVc1Y9BdHzMh9HSkklnXTAgM=
|
||||
lab.forgefriends.org/friendlyforgeformat/gof3 v0.0.0-20230427084437-fabab01062d0/go.mod h1:hHO78jzN6POY88iXr2+kJFl7IHOaBsVS22bBbRCBwRQ=
|
||||
lukechampine.com/uint128 v1.1.1 h1:pnxCASz787iMf+02ssImqk6OLt+Z5QHMoZyUXR4z6JU=
|
||||
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.33.6/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
|
|
1
main.go
1
main.go
|
@ -76,6 +76,7 @@ arguments - which can alternatively be run by running the subcommand web.`
|
|||
cmd.CmdDumpRepository,
|
||||
cmd.CmdRestoreRepository,
|
||||
cmd.CmdActions,
|
||||
cmd.CmdF3,
|
||||
}
|
||||
// Now adjust these commands to add our global configuration options
|
||||
|
||||
|
|
|
@ -230,6 +230,21 @@ func GetRepoTopicByName(ctx context.Context, repoID int64, topicName string) (*T
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// GetRepoTopicByID retrieves topic from ID for a repo if it exist
|
||||
func GetRepoTopicByID(ctx context.Context, repoID, topicID int64) (*Topic, error) {
|
||||
cond := builder.NewCond()
|
||||
var topic Topic
|
||||
cond = cond.And(builder.Eq{"repo_topic.repo_id": repoID}).And(builder.Eq{"topic.id": topicID})
|
||||
sess := db.GetEngine(ctx).Table("topic").Where(cond)
|
||||
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
|
||||
if has, err := sess.Select("topic.*").Get(&topic); err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrTopicNotExist{""}
|
||||
}
|
||||
return &topic, nil
|
||||
}
|
||||
|
||||
// AddTopic adds a topic name to a repository (if it does not already have it)
|
||||
func AddTopic(repoID int64, topicName string) (*Topic, error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
|
|
22
modules/setting/f3.go
Normal file
22
modules/setting/f3.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package setting
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
// Friendly Forge Format (F3) settings
|
||||
var (
|
||||
F3 = struct {
|
||||
Enabled bool
|
||||
}{
|
||||
Enabled: true,
|
||||
}
|
||||
)
|
||||
|
||||
func loadF3From(rootCfg ConfigProvider) {
|
||||
if err := rootCfg.Section("F3").MapTo(&F3); err != nil {
|
||||
log.Fatal("Failed to map F3 settings: %v", err)
|
||||
}
|
||||
}
|
|
@ -326,6 +326,7 @@ func LoadSettings() {
|
|||
loadProjectFrom(CfgProvider)
|
||||
loadMimeTypeMapFrom(CfgProvider)
|
||||
loadFederationFrom(CfgProvider)
|
||||
loadF3From(CfgProvider)
|
||||
}
|
||||
|
||||
// LoadSettingsForInstall initializes the settings for install
|
||||
|
|
|
@ -101,7 +101,7 @@ func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, d
|
|||
Path: comment.TreePath,
|
||||
CommitID: comment.CommitSHA,
|
||||
OrigCommitID: comment.OldRef,
|
||||
DiffHunk: patch2diff(comment.Patch),
|
||||
DiffHunk: Patch2diff(comment.Patch),
|
||||
HTMLURL: comment.HTMLURL(),
|
||||
HTMLPullURL: review.Issue.HTMLURL(),
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, d
|
|||
return apiComments, nil
|
||||
}
|
||||
|
||||
func patch2diff(patch string) string {
|
||||
func Patch2diff(patch string) string {
|
||||
split := strings.Split(patch, "\n@@")
|
||||
if len(split) == 2 {
|
||||
return "@@" + split[1]
|
||||
|
|
157
services/f3/driver/asset.go
Normal file
157
services/f3/driver/asset.go
Normal file
|
@ -0,0 +1,157 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/services/attachment"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||
)
|
||||
|
||||
type Asset struct {
|
||||
repo_model.Attachment
|
||||
DownloadFunc func() io.ReadCloser
|
||||
}
|
||||
|
||||
func AssetConverter(f *repo_model.Attachment) *Asset {
|
||||
return &Asset{
|
||||
Attachment: *f,
|
||||
}
|
||||
}
|
||||
|
||||
func (o Asset) GetID() int64 {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Asset) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
func (o *Asset) IsNil() bool {
|
||||
return o.ID == 0
|
||||
}
|
||||
|
||||
func (o *Asset) Equals(other *Asset) bool {
|
||||
return o.Name == other.Name
|
||||
}
|
||||
|
||||
func (o *Asset) ToFormat() *format.ReleaseAsset {
|
||||
return &format.ReleaseAsset{
|
||||
Common: format.NewCommon(o.ID),
|
||||
Name: o.Name,
|
||||
Size: int(o.Size),
|
||||
DownloadCount: int(o.DownloadCount),
|
||||
Created: o.CreatedUnix.AsTime(),
|
||||
DownloadURL: o.DownloadURL(),
|
||||
DownloadFunc: o.DownloadFunc,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Asset) FromFormat(asset *format.ReleaseAsset) {
|
||||
*o = Asset{
|
||||
Attachment: repo_model.Attachment{
|
||||
ID: asset.GetID(),
|
||||
Name: asset.Name,
|
||||
Size: int64(asset.Size),
|
||||
DownloadCount: int64(asset.DownloadCount),
|
||||
CreatedUnix: timeutil.TimeStamp(asset.Created.Unix()),
|
||||
},
|
||||
DownloadFunc: asset.DownloadFunc,
|
||||
}
|
||||
}
|
||||
|
||||
type AssetProvider struct {
|
||||
g *Forgejo
|
||||
}
|
||||
|
||||
func (o *AssetProvider) ToFormat(ctx context.Context, asset *Asset) *format.ReleaseAsset {
|
||||
httpClient := o.g.GetNewMigrationHTTPClient()()
|
||||
a := asset.ToFormat()
|
||||
a.DownloadFunc = func() io.ReadCloser {
|
||||
o.g.GetLogger().Debug("download from %s", asset.DownloadURL())
|
||||
req, err := http.NewRequest("GET", asset.DownloadURL(), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("while downloading %s %w", asset.DownloadURL(), err))
|
||||
}
|
||||
|
||||
// resp.Body is closed by the consumer
|
||||
return resp.Body
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (o *AssetProvider) FromFormat(ctx context.Context, p *format.ReleaseAsset) *Asset {
|
||||
var asset Asset
|
||||
asset.FromFormat(p)
|
||||
return &asset
|
||||
}
|
||||
|
||||
func (o *AssetProvider) ProcessObject(ctx context.Context, user *User, project *Project, release *Release, asset *Asset) {
|
||||
}
|
||||
|
||||
func (o *AssetProvider) GetObjects(ctx context.Context, user *User, project *Project, release *Release, page int) []*Asset {
|
||||
if page > 1 {
|
||||
return []*Asset{}
|
||||
}
|
||||
r, err := repo_model.GetReleaseByID(ctx, release.GetID())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := r.LoadAttributes(ctx); err != nil {
|
||||
panic(fmt.Errorf("error while listing assets: %v", err))
|
||||
}
|
||||
|
||||
return util.ConvertMap[*repo_model.Attachment, *Asset](r.Attachments, AssetConverter)
|
||||
}
|
||||
|
||||
func (o *AssetProvider) Get(ctx context.Context, user *User, project *Project, release *Release, exemplar *Asset) *Asset {
|
||||
id := exemplar.GetID()
|
||||
asset, err := repo_model.GetAttachmentByID(ctx, id)
|
||||
if repo_model.IsErrAttachmentNotExist(err) {
|
||||
return &Asset{}
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return AssetConverter(asset)
|
||||
}
|
||||
|
||||
func (o *AssetProvider) Put(ctx context.Context, user *User, project *Project, release *Release, asset *Asset) *Asset {
|
||||
asset.ID = 0
|
||||
asset.UploaderID = user.GetID()
|
||||
asset.RepoID = project.GetID()
|
||||
asset.ReleaseID = release.GetID()
|
||||
asset.UUID = uuid.New().String()
|
||||
|
||||
download := asset.DownloadFunc()
|
||||
defer download.Close()
|
||||
a, err := attachment.NewAttachment(&asset.Attachment, download, asset.Size)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return o.Get(ctx, user, project, release, AssetConverter(a))
|
||||
}
|
||||
|
||||
func (o *AssetProvider) Delete(ctx context.Context, user *User, project *Project, release *Release, asset *Asset) *Asset {
|
||||
a := o.Get(ctx, user, project, release, asset)
|
||||
if !a.IsNil() {
|
||||
err := repo_model.DeleteAttachment(&a.Attachment, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return a
|
||||
}
|
150
services/f3/driver/comment.go
Normal file
150
services/f3/driver/comment.go
Normal file
|
@ -0,0 +1,150 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/forges/common"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||
)
|
||||
|
||||
type Comment struct {
|
||||
issues_model.Comment
|
||||
}
|
||||
|
||||
func CommentConverter(f *issues_model.Comment) *Comment {
|
||||
return &Comment{
|
||||
Comment: *f,
|
||||
}
|
||||
}
|
||||
|
||||
func (o Comment) GetID() int64 {
|
||||
return o.Comment.ID
|
||||
}
|
||||
|
||||
func (o *Comment) SetID(id int64) {
|
||||
o.Comment.ID = id
|
||||
}
|
||||
|
||||
func (o *Comment) IsNil() bool {
|
||||
return o.ID == 0
|
||||
}
|
||||
|
||||
func (o *Comment) Equals(other *Comment) bool {
|
||||
return o.Comment.ID == other.Comment.ID
|
||||
}
|
||||
|
||||
func (o *Comment) ToFormat() *format.Comment {
|
||||
return &format.Comment{
|
||||
IssueIndex: o.Comment.IssueID,
|
||||
Common: format.NewCommon(o.Comment.ID),
|
||||
PosterID: format.NewUserReference(o.Comment.Poster.ID),
|
||||
Content: o.Comment.Content,
|
||||
Created: o.Comment.CreatedUnix.AsTime(),
|
||||
Updated: o.Comment.UpdatedUnix.AsTime(),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Comment) FromFormat(comment *format.Comment) {
|
||||
*o = Comment{
|
||||
Comment: issues_model.Comment{
|
||||
ID: comment.GetID(),
|
||||
PosterID: comment.PosterID.GetID(),
|
||||
Poster: &user_model.User{
|
||||
ID: comment.PosterID.GetID(),
|
||||
},
|
||||
Content: comment.Content,
|
||||
CreatedUnix: timeutil.TimeStamp(comment.Created.Unix()),
|
||||
UpdatedUnix: timeutil.TimeStamp(comment.Updated.Unix()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type CommentProvider struct {
|
||||
g *Forgejo
|
||||
}
|
||||
|
||||
func (o *CommentProvider) ToFormat(ctx context.Context, comment *Comment) *format.Comment {
|
||||
return comment.ToFormat()
|
||||
}
|
||||
|
||||
func (o *CommentProvider) FromFormat(ctx context.Context, f *format.Comment) *Comment {
|
||||
var comment Comment
|
||||
comment.FromFormat(f)
|
||||
return &comment
|
||||
}
|
||||
|
||||
func (o *CommentProvider) GetObjects(ctx context.Context, user *User, project *Project, commentable common.ContainerObjectInterface, page int) []*Comment {
|
||||
comments, err := issues_model.FindComments(ctx, &issues_model.FindCommentsOptions{
|
||||
ListOptions: db.ListOptions{Page: page, PageSize: o.g.perPage},
|
||||
RepoID: project.GetID(),
|
||||
IssueID: commentable.GetID(),
|
||||
Type: issues_model.CommentTypeComment,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error while listing comment: %v", err))
|
||||
}
|
||||
|
||||
return util.ConvertMap[*issues_model.Comment, *Comment](comments, CommentConverter)
|
||||
}
|
||||
|
||||
func (o *CommentProvider) ProcessObject(ctx context.Context, user *User, project *Project, commentable common.ContainerObjectInterface, comment *Comment) {
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := comment.LoadPoster(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *CommentProvider) Get(ctx context.Context, user *User, project *Project, commentable common.ContainerObjectInterface, comment *Comment) *Comment {
|
||||
id := comment.GetID()
|
||||
c, err := issues_model.GetCommentByID(ctx, id)
|
||||
if issues_model.IsErrCommentNotExist(err) {
|
||||
return &Comment{}
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
co := CommentConverter(c)
|
||||
o.ProcessObject(ctx, user, project, commentable, co)
|
||||
return co
|
||||
}
|
||||
|
||||
func (o *CommentProvider) Put(ctx context.Context, user *User, project *Project, commentable common.ContainerObjectInterface, comment *Comment) *Comment {
|
||||
var issue *issues_model.Issue
|
||||
switch c := commentable.(type) {
|
||||
case *PullRequest:
|
||||
issue = c.PullRequest.Issue
|
||||
case *Issue:
|
||||
issue = &c.Issue
|
||||
default:
|
||||
panic(fmt.Errorf("unexpected type %T", commentable))
|
||||
}
|
||||
c, err := issue_service.CreateIssueComment(ctx, o.g.GetDoer(), &project.Repository, issue, comment.Content, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return o.Get(ctx, user, project, commentable, CommentConverter(c))
|
||||
}
|
||||
|
||||
func (o *CommentProvider) Delete(ctx context.Context, user *User, project *Project, commentable common.ContainerObjectInterface, comment *Comment) *Comment {
|
||||
c := o.Get(ctx, user, project, commentable, comment)
|
||||
if !c.IsNil() {
|
||||
err := issues_model.DeleteComment(ctx, &c.Comment)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
108
services/f3/driver/driver.go
Normal file
108
services/f3/driver/driver.go
Normal file
|
@ -0,0 +1,108 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/services/migrations"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/forges/common"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/forges/driver"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
gof3.Options
|
||||
|
||||
Doer *user_model.User
|
||||
}
|
||||
|
||||
type Forgejo struct {
|
||||
perPage int
|
||||
options *Options
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetPerPage() int {
|
||||
return o.perPage
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetOptions() gof3.OptionsInterface {
|
||||
return o.options
|
||||
}
|
||||
|
||||
func (o *Forgejo) SetOptions(options gof3.OptionsInterface) {
|
||||
var ok bool
|
||||
o.options, ok = options.(*Options)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("unexpected type %T", options))
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetLogger() *gof3.Logger {
|
||||
return o.GetOptions().GetLogger()
|
||||
}
|
||||
|
||||
func (o *Forgejo) Init(options gof3.OptionsInterface) {
|
||||
o.SetOptions(options)
|
||||
o.perPage = setting.ItemsPerPage
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetDirectory() string {
|
||||
return o.options.GetDirectory()
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetDoer() *user_model.User {
|
||||
return o.options.Doer
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetNewMigrationHTTPClient() gof3.NewMigrationHTTPClientFun {
|
||||
return migrations.NewMigrationHTTPClient
|
||||
}
|
||||
|
||||
func (o *Forgejo) SupportGetRepoComments() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (o *Forgejo) GetProvider(name string, parent common.ProviderInterface) common.ProviderInterface {
|
||||
var parentImpl any
|
||||
if parent != nil {
|
||||
parentImpl = parent.GetImplementation()
|
||||
}
|
||||
switch name {
|
||||
case driver.ProviderUser:
|
||||
return driver.NewProvider[UserProvider, *UserProvider, User, *User, format.User, *format.User](driver.ProviderUser, &UserProvider{g: o})
|
||||
case driver.ProviderProject:
|
||||
return driver.NewProviderWithParentOne[ProjectProvider, *ProjectProvider, Project, *Project, format.Project, *format.Project, User, *User](driver.ProviderProject, &ProjectProvider{g: o})
|
||||
case driver.ProviderMilestone:
|
||||
return driver.NewProviderWithParentOneTwo[MilestoneProvider, *MilestoneProvider, Milestone, *Milestone, format.Milestone, *format.Milestone, User, *User, Project, *Project](driver.ProviderMilestone, &MilestoneProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
case driver.ProviderIssue:
|
||||
return driver.NewProviderWithParentOneTwo[IssueProvider, *IssueProvider, Issue, *Issue, format.Issue, *format.Issue, User, *User, Project, *Project](driver.ProviderIssue, &IssueProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
case driver.ProviderPullRequest:
|
||||
return driver.NewProviderWithParentOneTwo[PullRequestProvider, *PullRequestProvider, PullRequest, *PullRequest, format.PullRequest, *format.PullRequest, User, *User, Project, *Project](driver.ProviderPullRequest, &PullRequestProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
case driver.ProviderReview:
|
||||
return driver.NewProviderWithParentOneTwoThree[ReviewProvider, *ReviewProvider, Review, *Review, format.Review, *format.Review, User, *User, Project, *Project, PullRequest, *PullRequest](driver.ProviderReview, &ReviewProvider{g: o})
|
||||
case driver.ProviderRepository:
|
||||
return driver.NewProviderWithParentOneTwo[RepositoryProvider, *RepositoryProvider, Repository, *Repository, format.Repository, *format.Repository, User, *User, Project, *Project](driver.ProviderRepository, &RepositoryProvider{g: o})
|
||||
case driver.ProviderTopic:
|
||||
return driver.NewProviderWithParentOneTwo[TopicProvider, *TopicProvider, Topic, *Topic, format.Topic, *format.Topic, User, *User, Project, *Project](driver.ProviderTopic, &TopicProvider{g: o})
|
||||
case driver.ProviderLabel:
|
||||
return driver.NewProviderWithParentOneTwo[LabelProvider, *LabelProvider, Label, *Label, format.Label, *format.Label, User, *User, Project, *Project](driver.ProviderLabel, &LabelProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
case driver.ProviderRelease:
|
||||
return driver.NewProviderWithParentOneTwo[ReleaseProvider, *ReleaseProvider, Release, *Release, format.Release, *format.Release, User, *User, Project, *Project](driver.ProviderRelease, &ReleaseProvider{g: o})
|
||||
case driver.ProviderAsset:
|
||||
return driver.NewProviderWithParentOneTwoThree[AssetProvider, *AssetProvider, Asset, *Asset, format.ReleaseAsset, *format.ReleaseAsset, User, *User, Project, *Project, Release, *Release](driver.ProviderAsset, &AssetProvider{g: o})
|
||||
case driver.ProviderComment:
|
||||
return driver.NewProviderWithParentOneTwoThreeInterface[CommentProvider, *CommentProvider, Comment, *Comment, format.Comment, *format.Comment, User, *User, Project, *Project](driver.ProviderComment, &CommentProvider{g: o})
|
||||
case driver.ProviderReaction:
|
||||
return driver.NewProviderWithParentOneTwoRest[ReactionProvider, *ReactionProvider, Reaction, *Reaction, format.Reaction, *format.Reaction, User, *User, Project, *Project](driver.ProviderReaction, &ReactionProvider{g: o})
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown provider name %s", name))
|
||||
}
|
||||
}
|
||||
|
||||
func (o Forgejo) Finish() {
|
||||
}
|
196
services/f3/driver/issue.go
Normal file
196
services/f3/driver/issue.go
Normal file
|
@ -0,0 +1,196 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||
)
|
||||
|
||||
type Issue struct {
|
||||
issues_model.Issue
|
||||
}
|
||||
|
||||
func IssueConverter(f *issues_model.Issue) *Issue {
|
||||
return &Issue{
|
||||
Issue: *f,
|
||||
}
|
||||
}
|
||||
|
||||
func (o Issue) GetID() int64 {
|
||||
return o.Index
|
||||
}
|
||||
|
||||
func (o *Issue) SetID(id int64) {
|
||||
o.Index = id
|
||||
}
|
||||
|
||||
func (o *Issue) IsNil() bool {
|
||||
return o.Index == 0
|
||||
}
|
||||
|
||||
func (o *Issue) Equals(other *Issue) bool {
|
||||
return o.Index == other.Index
|
||||
}
|
||||
|
||||
func (o *Issue) ToFormat() *format.Issue {
|
||||
var milestone string
|
||||
if o.Milestone != nil {
|
||||
milestone = o.Milestone.Name
|
||||
}
|
||||
|
||||
labels := make([]string, 0, len(o.Labels))
|
||||
for _, label := range o.Labels {
|
||||
labels = append(labels, label.Name)
|
||||
}
|
||||
|
||||
var assignees []string
|
||||
for i := range o.Assignees {
|
||||
assignees = append(assignees, o.Assignees[i].Name)
|
||||
}
|
||||
|
||||
return &format.Issue{
|
||||
Common: format.NewCommon(o.Index),
|
||||
Title: o.Title,
|
||||
PosterID: format.NewUserReference(o.Poster.ID),
|
||||
Content: o.Content,
|
||||
Milestone: milestone,
|
||||
State: string(o.State()),
|
||||
Created: o.CreatedUnix.AsTime(),
|
||||
Updated: o.UpdatedUnix.AsTime(),
|
||||
Closed: o.ClosedUnix.AsTimePtr(),
|
||||
IsLocked: o.IsLocked,
|
||||
Labels: labels,
|
||||
Assignees: assignees,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Issue) FromFormat(issue *format.Issue) {
|
||||
labels := make([]*issues_model.Label, 0, len(issue.Labels))
|
||||
for _, label := range issue.Labels {
|
||||
labels = append(labels, &issues_model.Label{Name: label})
|
||||
}
|
||||
|
||||
assignees := make([]*user_model.User, 0, len(issue.Assignees))
|
||||
for _, a := range issue.Assignees {
|
||||
assignees = append(assignees, &user_model.User{
|
||||
Name: a,
|
||||
})
|
||||
}
|
||||
|
||||
*o = Issue{
|
||||
Issue: issues_model.Issue{
|
||||
Title: issue.Title,
|
||||
Index: issue.GetID(),
|
||||
PosterID: issue.PosterID.GetID(),
|
||||
Poster: &user_model.User{
|
||||
ID: issue.PosterID.GetID(),
|
||||
},
|
||||
Content: issue.Content,
|
||||
Milestone: &issues_model.Milestone{
|
||||
Name: issue.Milestone,
|
||||
},
|
||||
IsClosed: issue.State == "closed",
|
||||
CreatedUnix: timeutil.TimeStamp(issue.Created.Unix()),
|
||||
UpdatedUnix: timeutil.TimeStamp(issue.Updated.Unix()),
|
||||
ClosedUnix: timeutil.TimeStamp(issue.Closed.Unix()),
|
||||
IsLocked: issue.IsLocked,
|
||||
Labels: labels,
|
||||
Assignees: assignees,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type IssueProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
}
|
||||
|
||||
func (o *IssueProvider) ToFormat(ctx context.Context, issue *Issue) *format.Issue {
|
||||
return issue.ToFormat()
|
||||
}
|
||||
|
||||
func (o *IssueProvider) FromFormat(ctx context.Context, i *format.Issue) *Issue {
|
||||
var issue Issue
|
||||
issue.FromFormat(i)
|
||||
if i.Milestone != "" {
|
||||
issue.Milestone.ID = o.project.milestones.GetID(issue.Milestone.Name)
|
||||
}
|
||||
for _, label := range issue.Labels {
|
||||
label.ID = o.project.labels.GetID(label.Name)
|
||||
}
|
||||
return &issue
|
||||
}
|
||||
|
||||
func (o *IssueProvider) GetObjects(ctx context.Context, user *User, project *Project, page int) []*Issue {
|
||||
issues, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
|
||||
ListOptions: db.ListOptions{Page: page, PageSize: o.g.perPage},
|
||||
RepoID: project.GetID(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error while listing issues: %v", err))
|
||||
}
|
||||
|
||||
return util.ConvertMap[*issues_model.Issue, *Issue](issues, IssueConverter)
|
||||
}
|
||||
|
||||
func (o *IssueProvider) ProcessObject(ctx context.Context, user *User, project *Project, issue *Issue) {
|
||||
if err := (&issue.Issue).LoadAttributes(ctx); err != nil {
|
||||
panic(true)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *IssueProvider) Get(ctx context.Context, user *User, project *Project, exemplar *Issue) *Issue {
|
||||
id := exemplar.GetID()
|
||||
issue, err := issues_model.GetIssueByIndex(project.GetID(), id)
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
return &Issue{}
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
i := IssueConverter(issue)
|
||||
o.ProcessObject(ctx, user, project, i)
|
||||
return i
|
||||
}
|
||||
|
||||
func (o *IssueProvider) Put(ctx context.Context, user *User, project *Project, issue *Issue) *Issue {
|
||||
i := issue.Issue
|
||||
i.RepoID = project.GetID()
|
||||
labels := make([]int64, 0, len(i.Labels))
|
||||
for _, label := range i.Labels {
|
||||
labels = append(labels, label.ID)
|
||||
}
|
||||
|
||||
if err := issues_model.NewIssue(&project.Repository, &i, labels, []string{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return o.Get(ctx, user, project, IssueConverter(&i))
|
||||
}
|
||||
|
||||
func (o *IssueProvider) Delete(ctx context.Context, user *User, project *Project, issue *Issue) *Issue {
|
||||
m := o.Get(ctx, user, project, issue)
|
||||
if !m.IsNil() {
|
||||
repoPath := repo_model.RepoPath(user.Name, project.Name)
|
||||
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
if err := issue_service.DeleteIssue(ctx, o.g.GetDoer(), gitRepo, &issue.Issue); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
126
services/f3/driver/label.go
Normal file
126
services/f3/driver/label.go
Normal file
|
@ -0,0 +1,126 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||
)
|
||||
|
||||
type Label struct {
|
||||
issues_model.Label
|
||||
}
|
||||
|
||||
func LabelConverter(f *issues_model.Label) *Label {
|
||||
return &Label{
|
||||
Label: *f,
|
||||
}
|
||||
}
|
||||
|
||||
func (o Label) GetID() int64 {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o Label) GetName() string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (o *Label) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
func (o *Label) IsNil() bool {
|
||||
return o.ID == 0
|
||||
}
|
||||
|
||||
func (o *Label) Equals(other *Label) bool {
|
||||
return o.Name == other.Name
|
||||
}
|
||||
|
||||
func (o *Label) ToFormat() *format.Label {
|
||||
return &format.Label{
|
||||
Common: format.NewCommon(o.ID),
|
||||
Name: o.Name,
|
||||
Color: o.Color,
|
||||
Description: o.Description,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Label) FromFormat(label *format.Label) {
|
||||
*o = Label{
|
||||
Label: issues_model.Label{
|
||||
ID: label.GetID(),
|
||||
Name: label.Name,
|
||||
Description: label.Description,
|
||||
Color: label.Color,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type LabelProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
}
|
||||
|
||||
func (o *LabelProvider) ToFormat(ctx context.Context, label *Label) *format.Label {
|
||||
return label.ToFormat()
|
||||
}
|
||||
|
||||
func (o *LabelProvider) FromFormat(ctx context.Context, m *format.Label) *Label {
|
||||
var label Label
|
||||
label.FromFormat(m)
|
||||
return &label
|
||||
}
|
||||
|
||||
func (o *LabelProvider) GetObjects(ctx context.Context, user *User, project *Project, page int) []*Label {
|
||||
labels, err := issues_model.GetLabelsByRepoID(ctx, project.GetID(), "", db.ListOptions{Page: page, PageSize: o.g.perPage})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error while listing labels: %v", err))
|
||||
}
|
||||
|
||||
r := util.ConvertMap[*issues_model.Label, *Label](labels, LabelConverter)
|
||||
if o.project != nil {
|
||||
o.project.labels = util.NewNameIDMap[*Label](r)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (o *LabelProvider) ProcessObject(ctx context.Context, user *User, project *Project, label *Label) {
|
||||
}
|
||||
|
||||
func (o *LabelProvider) Get(ctx context.Context, user *User, project *Project, exemplar *Label) *Label {
|
||||
id := exemplar.GetID()
|
||||
label, err := issues_model.GetLabelInRepoByID(ctx, project.GetID(), id)
|
||||
if issues_model.IsErrRepoLabelNotExist(err) {
|
||||
return &Label{}
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return LabelConverter(label)
|
||||
}
|
||||
|
||||
func (o *LabelProvider) Put(ctx context.Context, user *User, project *Project, label *Label) *Label {
|
||||
l := label.Label
|
||||
l.RepoID = project.GetID()
|
||||
if err := issues_model.NewLabel(ctx, &l); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return o.Get(ctx, user, project, LabelConverter(&l))
|
||||
}
|
||||
|
||||
func (o *LabelProvider) Delete(ctx context.Context, user *User, project *Project, label *Label) *Label {
|
||||
l := o.Get(ctx, user, project, label)
|
||||
if !l.IsNil() {
|
||||
if err := issues_model.DeleteLabel(project.GetID(), l.GetID()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
173
services/f3/driver/milestone.go
Normal file
173
services/f3/driver/milestone.go
Normal file
|
@ -0,0 +1,173 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||
)
|
||||
|
||||
type Milestone struct {
|
||||
issues_model.Milestone
|
||||
}
|
||||
|
||||
func MilestoneConverter(f *issues_model.Milestone) *Milestone {
|
||||
return &Milestone{
|
||||
Milestone: *f,
|
||||
}
|
||||
}
|
||||
|
||||
func (o Milestone) GetID() int64 {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o Milestone) GetName() string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (o *Milestone) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
func (o *Milestone) IsNil() bool {
|
||||
return o.ID == 0
|
||||
}
|
||||
|
||||
func (o *Milestone) Equals(other *Milestone) bool {
|
||||
return o.Name == other.Name
|
||||
}
|
||||
|
||||
func (o *Milestone) ToFormat() *format.Milestone {
|
||||
milestone := &format.Milestone{
|
||||
Common: format.NewCommon(o.ID),
|
||||
Title: o.Name,
|
||||
Description: o.Content,
|
||||
Created: o.CreatedUnix.AsTime(),
|
||||
Updated: o.UpdatedUnix.AsTimePtr(),
|
||||
State: string(o.State()),
|
||||
}
|
||||
if o.IsClosed {
|
||||
milestone.Closed = o.ClosedDateUnix.AsTimePtr()
|
||||
}
|
||||
if o.DeadlineUnix.Year() < 9999 {
|
||||
milestone.Deadline = o.DeadlineUnix.AsTimePtr()
|
||||
}
|
||||
return milestone
|
||||
}
|
||||
|
||||
func (o *Milestone) FromFormat(milestone *format.Milestone) {
|
||||
var deadline timeutil.TimeStamp
|
||||
if milestone.Deadline != nil {
|
||||
deadline = timeutil.TimeStamp(milestone.Deadline.Unix())
|
||||
}
|
||||
if deadline == 0 {
|
||||
deadline = timeutil.TimeStamp(time.Date(9999, 1, 1, 0, 0, 0, 0, setting.DefaultUILocation).Unix())
|
||||
}
|
||||
|
||||
var closed timeutil.TimeStamp
|
||||
if milestone.Closed != nil {
|
||||
closed = timeutil.TimeStamp(milestone.Closed.Unix())
|
||||
}
|
||||
|
||||
if milestone.Created.IsZero() {
|
||||
if milestone.Updated != nil {
|
||||
milestone.Created = *milestone.Updated
|
||||
} else if milestone.Deadline != nil {
|
||||
milestone.Created = *milestone.Deadline
|
||||
} else {
|
||||
milestone.Created = time.Now()
|
||||
}
|
||||
}
|
||||
if milestone.Updated == nil || milestone.Updated.IsZero() {
|
||||
milestone.Updated = &milestone.Created
|
||||
}
|
||||
|
||||
*o = Milestone{
|
||||
issues_model.Milestone{
|
||||
ID: milestone.GetID(),
|
||||
Name: milestone.Title,
|
||||
Content: milestone.Description,
|
||||
IsClosed: milestone.State == "closed",
|
||||
CreatedUnix: timeutil.TimeStamp(milestone.Created.Unix()),
|
||||
UpdatedUnix: timeutil.TimeStamp(milestone.Updated.Unix()),
|
||||
ClosedDateUnix: closed,
|
||||
DeadlineUnix: deadline,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type MilestoneProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) ToFormat(ctx context.Context, milestone *Milestone) *format.Milestone {
|
||||
return milestone.ToFormat()
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) FromFormat(ctx context.Context, m *format.Milestone) *Milestone {
|
||||
var milestone Milestone
|
||||
milestone.FromFormat(m)
|
||||
return &milestone
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) GetObjects(ctx context.Context, user *User, project *Project, page int) []*Milestone {
|
||||
milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||
ListOptions: db.ListOptions{Page: page, PageSize: o.g.perPage},
|
||||
RepoID: project.GetID(),
|
||||
State: api.StateAll,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error while listing milestones: %v", err))
|
||||
}
|
||||
|
||||
r := util.ConvertMap[*issues_model.Milestone, *Milestone](([]*issues_model.Milestone)(milestones), MilestoneConverter)
|
||||
if o.project != nil {
|
||||
o.project.milestones = util.NewNameIDMap[*Milestone](r)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) ProcessObject(ctx context.Context, user *User, project *Project, milestone *Milestone) {
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) Get(ctx context.Context, user *User, project *Project, exemplar *Milestone) *Milestone {
|
||||
id := exemplar.GetID()
|
||||
milestone, err := issues_model.GetMilestoneByRepoID(ctx, project.GetID(), id)
|
||||
if issues_model.IsErrMilestoneNotExist(err) {
|
||||
return &Milestone{}
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return MilestoneConverter(milestone)
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) Put(ctx context.Context, user *User, project *Project, milestone *Milestone) *Milestone {
|
||||
m := milestone.Milestone
|
||||
m.RepoID = project.GetID()
|
||||
if err := issues_model.NewMilestone(&m); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return o.Get(ctx, user, project, MilestoneConverter(&m))
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) Delete(ctx context.Context, user *User, project *Project, milestone *Milestone) *Milestone {
|
||||
m := o.Get(ctx, user, project, milestone)
|
||||
if !m.IsNil() {
|
||||
if err := issues_model.DeleteMilestoneByRepoID(project.GetID(), m.GetID()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
157
services/f3/driver/project.go
Normal file
157
services/f3/driver/project.go
Normal file
|
@ -0,0 +1,157 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
f3_util "lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
repo_model.Repository
|
||||
}
|
||||
|
||||
func ProjectConverter(f *repo_model.Repository) *Project {
|
||||
return &Project{
|
||||
Repository: *f,
|
||||
}
|
||||
}
|
||||
|
||||
func (o Project) GetID() int64 {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Project) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
func (o *Project) IsNil() bool {
|
||||
return o.ID == 0
|
||||
}
|
||||
|
||||
func (o *Project) Equals(other *Project) bool {
|
||||
return (o.Name == other.Name)
|
||||
}
|
||||
|
||||
func (o *Project) ToFormat() *format.Project {
|
||||
return &format.Project{
|
||||
Common: format.NewCommon(o.ID),
|
||||
Name: o.Name,
|
||||
Owner: o.Owner.Name,
|
||||
IsPrivate: o.IsPrivate,
|
||||
Description: o.Description,
|
||||
CloneURL: repo_model.ComposeHTTPSCloneURL(o.Owner.Name, o.Name),
|
||||
OriginalURL: o.OriginalURL,
|
||||
DefaultBranch: o.DefaultBranch,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Project) FromFormat(project *format.Project) {
|
||||
*o = Project{
|
||||
Repository: repo_model.Repository{
|
||||
ID: project.GetID(),
|
||||
Name: project.Name,
|
||||
Owner: &user_model.User{
|
||||
Name: project.Owner,
|
||||
},
|
||||
IsPrivate: project.IsPrivate,
|
||||
Description: project.Description,
|
||||
OriginalURL: project.OriginalURL,
|
||||
DefaultBranch: project.DefaultBranch,
|
||||
},
|
||||
}
|