Only allow to deploy from push, tag and release (#3522)

This commit is contained in:
qwerty287 2024-03-20 21:04:51 +01:00 committed by GitHub
parent 00b1651f47
commit e00b2d4bd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View file

@ -409,12 +409,19 @@ func PostPipeline(c *gin.Context) {
// make Deploy overridable
pl.Deploy = c.DefaultQuery("deploy_to", pl.Deploy)
// make Event overridable
// make Event overridable to deploy
// TODO refactor to use own proper API for deploy
if event, ok := c.GetQuery("event"); ok {
// only allow deploy from push, tag and release
if pl.Event != model.EventPush && pl.Event != model.EventTag && pl.Event != model.EventRelease {
_ = c.AbortWithError(http.StatusBadRequest, fmt.Errorf("can only deploy push, tag and release pipelines"))
return
}
pl.Event = model.WebhookEvent(event)
if err := pl.Event.Validate(); err != nil {
_ = c.AbortWithError(http.StatusBadRequest, err)
if pl.Event != model.EventDeploy {
_ = c.AbortWithError(http.StatusBadRequest, model.ErrInvalidWebhookEvent)
return
}
}

View file

@ -45,7 +45,10 @@
@click="restartPipeline"
/>
<Button
v-if="pipeline.status === 'success'"
v-if="
pipeline.status === 'success' &&
(pipeline.event === 'push' || pipeline.event === 'tag' || pipeline.event === 'release')
"
class="flex-shrink-0"
:text="$t('repo.pipeline.actions.deploy')"
@click="showDeployPipelinePopup = true"