mirror of
https://github.com/harness/drone.git
synced 2025-05-17 09:30:00 +08:00
parent
ab81e18705
commit
b950e28dd3
@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
### Added
|
||||||
|
- endpoint point to execute a cron pipeline on-demand, by [@bradrydzewski](https://github.com/bradrydzewski). [#2781](https://github.com/drone/drone/issues/2781).
|
||||||
|
- ignore skip comments when cron event, by [@bradrydzewski](https://github.com/bradrydzewski). [#2835](https://github.com/drone/drone/issues/2835).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- fixed issue with missing cron job name in user interface, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||||
|
|
||||||
## [1.4.0] - 2019-09-12
|
## [1.4.0] - 2019-09-12
|
||||||
### Added
|
### Added
|
||||||
|
@ -236,6 +236,7 @@ func (s Server) Handler() http.Handler {
|
|||||||
r.Post("/", crons.HandleCreate(s.Repos, s.Cron))
|
r.Post("/", crons.HandleCreate(s.Repos, s.Cron))
|
||||||
r.Get("/", crons.HandleList(s.Repos, s.Cron))
|
r.Get("/", crons.HandleList(s.Repos, s.Cron))
|
||||||
r.Get("/{cron}", crons.HandleFind(s.Repos, s.Cron))
|
r.Get("/{cron}", crons.HandleFind(s.Repos, s.Cron))
|
||||||
|
r.Post("/{cron}", crons.HandleExec(s.Users, s.Repos, s.Cron, s.Commits, s.Triggerer))
|
||||||
r.Patch("/{cron}", crons.HandleUpdate(s.Repos, s.Cron))
|
r.Patch("/{cron}", crons.HandleUpdate(s.Repos, s.Cron))
|
||||||
r.Delete("/{cron}", crons.HandleDelete(s.Repos, s.Cron))
|
r.Delete("/{cron}", crons.HandleDelete(s.Repos, s.Cron))
|
||||||
})
|
})
|
||||||
|
101
handler/api/repos/crons/exec.go
Normal file
101
handler/api/repos/crons/exec.go
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Drone Non-Commercial License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build !oss
|
||||||
|
|
||||||
|
package crons
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/drone/drone/core"
|
||||||
|
"github.com/drone/drone/handler/api/render"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandleExec returns an http.HandlerFunc that processes http
|
||||||
|
// requests to execute a cronjob on-demand.
|
||||||
|
func HandleExec(
|
||||||
|
users core.UserStore,
|
||||||
|
repos core.RepositoryStore,
|
||||||
|
crons core.CronStore,
|
||||||
|
commits core.CommitService,
|
||||||
|
trigger core.Triggerer,
|
||||||
|
) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
|
ctx = r.Context()
|
||||||
|
namespace = chi.URLParam(r, "owner")
|
||||||
|
name = chi.URLParam(r, "name")
|
||||||
|
cron = chi.URLParam(r, "cron")
|
||||||
|
)
|
||||||
|
|
||||||
|
repo, err := repos.FindName(ctx, namespace, name)
|
||||||
|
if err != nil {
|
||||||
|
render.NotFound(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cronjob, err := crons.FindName(ctx, repo.ID, cron)
|
||||||
|
if err != nil {
|
||||||
|
render.NotFound(w, err)
|
||||||
|
logger := logrus.WithError(err)
|
||||||
|
logger.Debugln("api: cannot find cron")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := users.Find(ctx, repo.UserID)
|
||||||
|
if err != nil {
|
||||||
|
logger := logrus.WithError(err)
|
||||||
|
logger.Debugln("api: cannot find repository owner")
|
||||||
|
render.NotFound(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commit, err := commits.FindRef(ctx, user, repo.Slug, cronjob.Branch)
|
||||||
|
if err != nil {
|
||||||
|
logger := logrus.WithError(err).
|
||||||
|
WithField("namespace", repo.Namespace).
|
||||||
|
WithField("name", repo.Name).
|
||||||
|
WithField("cron", cronjob.Name)
|
||||||
|
logger.Debugln("api: cannot find commit")
|
||||||
|
render.NotFound(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hook := &core.Hook{
|
||||||
|
Trigger: core.TriggerCron,
|
||||||
|
Event: core.EventCron,
|
||||||
|
Link: commit.Link,
|
||||||
|
Timestamp: commit.Author.Date,
|
||||||
|
Message: commit.Message,
|
||||||
|
After: commit.Sha,
|
||||||
|
Ref: fmt.Sprintf("refs/heads/%s", cronjob.Branch),
|
||||||
|
Target: cronjob.Branch,
|
||||||
|
Author: commit.Author.Login,
|
||||||
|
AuthorName: commit.Author.Name,
|
||||||
|
AuthorEmail: commit.Author.Email,
|
||||||
|
AuthorAvatar: commit.Author.Avatar,
|
||||||
|
Cron: cronjob.Name,
|
||||||
|
Sender: commit.Author.Login,
|
||||||
|
}
|
||||||
|
|
||||||
|
build, err := trigger.Trigger(context.Background(), repo, hook)
|
||||||
|
if err != nil {
|
||||||
|
logger := logrus.WithError(err).
|
||||||
|
WithField("namespace", repo.Namespace).
|
||||||
|
WithField("name", repo.Name).
|
||||||
|
WithField("cron", cronjob.Name)
|
||||||
|
logger.Debugln("api: cannot trigger cron")
|
||||||
|
render.InternalError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
render.JSON(w, build, 200)
|
||||||
|
}
|
||||||
|
}
|
7
handler/api/repos/crons/exec_test.go
Normal file
7
handler/api/repos/crons/exec_test.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Drone Non-Commercial License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build !oss
|
||||||
|
|
||||||
|
package crons
|
@ -46,3 +46,8 @@ func HandleFind(core.RepositoryStore, core.CronStore) http.HandlerFunc {
|
|||||||
func HandleList(core.RepositoryStore, core.CronStore) http.HandlerFunc {
|
func HandleList(core.RepositoryStore, core.CronStore) http.HandlerFunc {
|
||||||
return notImplemented
|
return notImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandleExec(core.UserStore, core.RepositoryStore, core.CronStore,
|
||||||
|
core.CommitService, core.Triggerer) http.HandlerFunc {
|
||||||
|
return notImplemented
|
||||||
|
}
|
||||||
|
@ -57,6 +57,8 @@ func skipMessage(hook *core.Hook) bool {
|
|||||||
switch {
|
switch {
|
||||||
case hook.Event == core.EventTag:
|
case hook.Event == core.EventTag:
|
||||||
return false
|
return false
|
||||||
|
case hook.Event == core.EventCron:
|
||||||
|
return false
|
||||||
case skipMessageEval(hook.Message):
|
case skipMessageEval(hook.Message):
|
||||||
return true
|
return true
|
||||||
case skipMessageEval(hook.Title):
|
case skipMessageEval(hook.Title):
|
||||||
|
@ -180,6 +180,16 @@ func Test_skipMessage(t *testing.T) {
|
|||||||
title: "update readme [CI SKIP]",
|
title: "update readme [CI SKIP]",
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
event: "cron",
|
||||||
|
title: "update readme [CI SKIP]",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
event: "cron",
|
||||||
|
title: "update readme [CI SKIP]",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
hook := &core.Hook{
|
hook := &core.Hook{
|
||||||
|
@ -351,6 +351,7 @@ func (t *triggerer) Trigger(ctx context.Context, repo *core.Repository, base *co
|
|||||||
Deploy: base.Deployment,
|
Deploy: base.Deployment,
|
||||||
DeployID: base.DeploymentID,
|
DeployID: base.DeploymentID,
|
||||||
Sender: base.Sender,
|
Sender: base.Sender,
|
||||||
|
Cron: base.Cron,
|
||||||
Created: time.Now().Unix(),
|
Created: time.Now().Unix(),
|
||||||
Updated: time.Now().Unix(),
|
Updated: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user