mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 17:00:30 +00:00
added routes and main entrypoint
This commit is contained in:
parent
89c95f4f00
commit
fad4fc64e6
1 changed files with 152 additions and 11 deletions
163
drone.go
163
drone.go
|
@ -1,20 +1,161 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/drone/drone/common"
|
||||
"github.com/drone/drone/datastore"
|
||||
"flag"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/drone/drone/datastore/bolt"
|
||||
"github.com/drone/drone/remote/github"
|
||||
"github.com/drone/drone/server"
|
||||
"github.com/drone/drone/server/session"
|
||||
"github.com/drone/drone/settings"
|
||||
)
|
||||
|
||||
var (
|
||||
revision string
|
||||
version string
|
||||
)
|
||||
|
||||
var ds datastore.Datastore
|
||||
var path = flag.String("config", "drone.toml", "")
|
||||
|
||||
func main() {
|
||||
ds, _ = bolt.New("drone.toml")
|
||||
println(revision)
|
||||
println(version)
|
||||
|
||||
settings, err := settings.Parse(*path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
remote := github.New(settings.Service)
|
||||
session := session.New(settings.Session)
|
||||
|
||||
ds := bolt.Must(settings.Database.Path)
|
||||
defer ds.Close()
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
api := r.Group("/api")
|
||||
api.Use(server.SetHeaders())
|
||||
api.Use(server.SetDatastore(ds))
|
||||
api.Use(server.SetRemote(remote))
|
||||
api.Use(server.SetSettings(settings))
|
||||
api.Use(server.SetUser(session))
|
||||
|
||||
user := api.Group("/user")
|
||||
{
|
||||
user.Use(server.MustUser())
|
||||
|
||||
user.GET("", server.GetUserCurr)
|
||||
user.PUT("", server.PutUserCurr)
|
||||
user.GET("/repos", server.GetUserRepos)
|
||||
}
|
||||
|
||||
users := api.Group("/users")
|
||||
{
|
||||
users.Use(server.MustAdmin())
|
||||
|
||||
users.GET("", server.GetUsers)
|
||||
users.GET("/:name", server.GetUser)
|
||||
users.PUT("/:name", server.PutUser)
|
||||
users.POST("/:name", server.PostUser)
|
||||
users.DELETE("/:name", server.DeleteUser)
|
||||
}
|
||||
|
||||
repos := api.Group("/repos/:owner/:name")
|
||||
{
|
||||
repos.POST("", server.PostRepo)
|
||||
|
||||
repo := repos.Group("")
|
||||
{
|
||||
repo.Use(server.SetRepo())
|
||||
repo.Use(server.SetPerm())
|
||||
repo.Use(server.CheckPull())
|
||||
repo.Use(server.CheckPush())
|
||||
|
||||
repo.GET("", server.GetRepo)
|
||||
repo.PUT("", server.PutRepo)
|
||||
repo.DELETE("", server.DeleteRepo)
|
||||
}
|
||||
}
|
||||
|
||||
subscribers := api.Group("/subscribers/:owner/:name")
|
||||
{
|
||||
subscribers.Use(server.SetRepo())
|
||||
subscribers.Use(server.SetPerm())
|
||||
subscribers.Use(server.CheckPull())
|
||||
|
||||
subscribers.GET("", server.GetSubscribers)
|
||||
subscribers.POST("", server.Subscribe)
|
||||
subscribers.DELETE("", server.Unsubscribe)
|
||||
}
|
||||
|
||||
builds := api.Group("/builds/:owner/:name")
|
||||
{
|
||||
builds.Use(server.SetRepo())
|
||||
builds.Use(server.SetPerm())
|
||||
builds.Use(server.CheckPull())
|
||||
builds.Use(server.CheckPush())
|
||||
|
||||
builds.GET("", server.GetBuilds)
|
||||
builds.GET("/:number", server.GetBuild)
|
||||
//TODO builds.POST("/:number", server.RestartBuild)
|
||||
//TODO builds.DELETE("/:number", server.CancelBuild)
|
||||
}
|
||||
|
||||
tasks := api.Group("/tasks/:owner/:name/:number")
|
||||
{
|
||||
tasks.Use(server.SetRepo())
|
||||
tasks.Use(server.SetPerm())
|
||||
tasks.Use(server.CheckPull())
|
||||
tasks.Use(server.CheckPush())
|
||||
|
||||
tasks.GET("", server.GetTasks)
|
||||
tasks.GET("/:task", server.GetTask)
|
||||
}
|
||||
|
||||
logs := api.Group("/logs/:owner/:name/:number/:task")
|
||||
{
|
||||
logs.Use(server.SetRepo())
|
||||
logs.Use(server.SetPerm())
|
||||
logs.Use(server.CheckPull())
|
||||
logs.Use(server.CheckPush())
|
||||
|
||||
logs.GET("", server.GetLogs)
|
||||
}
|
||||
|
||||
status := api.Group("/status/:owner/:name/:number")
|
||||
{
|
||||
status.Use(server.SetRepo())
|
||||
status.Use(server.SetPerm())
|
||||
status.Use(server.CheckPull())
|
||||
status.Use(server.CheckPush())
|
||||
|
||||
status.GET("/:context", server.GetStatus)
|
||||
status.GET("", server.GetStatusList)
|
||||
status.POST("", server.PostStatus)
|
||||
}
|
||||
|
||||
badges := api.Group("/badges/:owner/:name")
|
||||
{
|
||||
badges.Use(server.SetRepo())
|
||||
|
||||
badges.GET("/status.svg", server.GetBadge)
|
||||
badges.GET("/cc.xml", server.GetCC)
|
||||
}
|
||||
|
||||
hooks := api.Group("/hook")
|
||||
{
|
||||
hooks.POST("", server.PostHook)
|
||||
}
|
||||
|
||||
auth := r.Group("/authorize")
|
||||
{
|
||||
auth.Use(server.SetHeaders())
|
||||
auth.Use(server.SetDatastore(ds))
|
||||
auth.Use(server.SetRemote(remote))
|
||||
auth.Use(server.SetSettings(settings))
|
||||
auth.Use(server.SetSession(session))
|
||||
auth.GET("", server.GetLogin)
|
||||
auth.POST("", server.GetLogin)
|
||||
}
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.File("server/static/index.html")
|
||||
})
|
||||
r.Static("/static", "server/static")
|
||||
r.Run(settings.Server.Addr)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue