Move hook and events-stream routes to use /api prefix (#2212)

- move hook and events-stream routes to use `/api` prefix
- rename build to pipeline
This commit is contained in:
Anbraten 2023-08-16 02:42:37 +02:00 committed by GitHub
parent 1f95675365
commit 479e500b1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 11 deletions

View file

@ -108,7 +108,7 @@ func PostHook(c *gin.Context) {
_store := store.FromContext(c)
forge := server.Config.Services.Forge
tmpRepo, tmpBuild, err := forge.Hook(c, c.Request)
tmpRepo, tmpPipeline, err := forge.Hook(c, c.Request)
if err != nil {
if errors.Is(err, &types.ErrIgnoreEvent{}) {
msg := fmt.Sprintf("forge driver: %s", err)
@ -123,7 +123,7 @@ func PostHook(c *gin.Context) {
return
}
if tmpBuild == nil {
if tmpPipeline == nil {
msg := "ignoring hook: hook parsing resulted in empty pipeline"
log.Debug().Msg(msg)
c.String(http.StatusOK, msg)
@ -136,11 +136,11 @@ func PostHook(c *gin.Context) {
return
}
// skip the tmpBuild if any case-insensitive combination of the words "skip" and "ci"
// skip the tmpPipeline if any case-insensitive combination of the words "skip" and "ci"
// wrapped in square brackets appear in the commit message
skipMatch := skipRe.FindString(tmpBuild.Message)
skipMatch := skipRe.FindString(tmpPipeline.Message)
if len(skipMatch) > 0 {
msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, tmpBuild.Commit)
msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, tmpPipeline.Commit)
log.Debug().Msg(msg)
c.String(http.StatusNoContent, msg)
return
@ -212,14 +212,14 @@ func PostHook(c *gin.Context) {
return
}
if tmpBuild.Event == model.EventPull && !repo.AllowPull {
if tmpPipeline.Event == model.EventPull && !repo.AllowPull {
msg := "ignoring hook: pull requests are disabled for this repo in woodpecker"
log.Debug().Str("repo", repo.FullName).Msg(msg)
c.String(http.StatusNoContent, msg)
return
}
pl, err := pipeline.Create(c, _store, repo, tmpBuild)
pl, err := pipeline.Create(c, _store, repo, tmpPipeline)
if err != nil {
handlePipelineErr(c, err)
} else {

View file

@ -114,7 +114,7 @@ func PostRepo(c *gin.Context) {
}
link := fmt.Sprintf(
"%s/hook?access_token=%s",
"%s/api/hook?access_token=%s",
server.Config.Server.WebhookHost,
sig,
)
@ -437,7 +437,7 @@ func RepairRepo(c *gin.Context) {
// reconstruct the link
host := server.Config.Server.Host
link := fmt.Sprintf(
"%s/hook?access_token=%s",
"%s/api/hook?access_token=%s",
host,
sig,
)
@ -551,7 +551,7 @@ func MoveRepo(c *gin.Context) {
// reconstruct the link
host := server.Config.Server.Host
link := fmt.Sprintf(
"%s/hook?access_token=%s",
"%s/api/hook?access_token=%s",
host,
sig,
)

View file

@ -194,6 +194,7 @@ func apiRoutes(e *gin.RouterGroup) {
session.SetPerm(),
session.MustPull,
api.LogStreamSSE)
stream.GET("/events", api.EventStreamSSE)
}
if zerolog.GlobalLevel() <= zerolog.DebugLevel {

View file

@ -305,7 +305,7 @@ export default class WoodpeckerClient extends ApiClient {
// eslint-disable-next-line promise/prefer-await-to-callbacks
on(callback: (data: { pipeline?: Pipeline; repo?: Repo; step?: PipelineWorkflow }) => void): EventSource {
return this._subscribe('/stream/events', callback, {
return this._subscribe('/api/stream/events', callback, {
reconnect: true,
});
}