Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions server/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions server/api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions server/router/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down