skip run with special commit

This commit is contained in:
Carlo Mandelli 2019-08-22 16:19:44 +02:00
parent eddb62b6e2
commit 436aa8f1de
2 changed files with 77 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import (
"encoding/json"
"net/http"
"path"
"regexp"
"agola.io/agola/internal/config"
gitsource "agola.io/agola/internal/gitsources"
@ -66,6 +67,10 @@ const (
AnnotationPullRequestLink = "pull_request_link"
)
var (
SkipRunMessage = regexp.MustCompile(`.*\[ci skip\].*`)
)
func (h *ActionHandler) GetRun(ctx context.Context, runID string) (*rsapitypes.RunResponse, error) {
runResp, resp, err := h.runserviceClient.GetRun(ctx, runID, nil)
if err != nil {
@ -483,6 +488,11 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
}
for _, run := range config.Runs {
if SkipRunMessage.MatchString(req.Message) {
h.log.Debugf("skipping run since special commit message")
continue
}
if match := types.MatchWhen(run.When.ToWhen(), req.Branch, req.Tag, req.Ref); !match {
h.log.Debugf("skipping run since when condition doesn't match")
continue

View File

@ -451,7 +451,7 @@ func createProject(ctx context.Context, t *testing.T, giteaClient *gitea.Client,
return giteaRepo, project
}
func push(t *testing.T, config, cloneURL, remoteToken string) {
func push(t *testing.T, config, cloneURL, remoteToken, message string) {
gitfs := memfs.New()
f, err := gitfs.Create(".agola/config.jsonnet")
if err != nil {
@ -480,7 +480,7 @@ func push(t *testing.T, config, cloneURL, remoteToken string) {
if _, err := wt.Add(".agola/config.jsonnet"); err != nil {
t.Fatalf("unexpected err: %v", err)
}
_, err = wt.Commit("commit", &git.CommitOptions{
_, err = wt.Commit(message, &git.CommitOptions{
Author: &object.Signature{
Name: "user01",
Email: "user01@example.com",
@ -510,6 +510,7 @@ func TestPush(t *testing.T) {
config string
num int
annotations map[string]string
message string
}{
{
name: "test push",
@ -544,6 +545,7 @@ func TestPush(t *testing.T) {
"ref": "refs/heads/master",
"ref_type": "branch",
},
message: "commit",
},
{
name: "test push with unmatched branch",
@ -575,7 +577,68 @@ func TestPush(t *testing.T) {
],
}
`,
num: 0,
num: 0,
message: "commit",
},
{
name: "test push with [ci skip] in subject",
config: `
{
runs: [
{
name: 'run01',
tasks: [
{
name: 'task01',
runtime: {
containers: [
{
image: 'alpine/git',
},
],
},
steps: [
{ type: 'clone' },
{ type: 'run', command: 'env' },
],
},
],
},
],
}
`,
num: 0,
message: "[ci skip] commit",
},
{
name: "test push with [ci skip] in body",
config: `
{
runs: [
{
name: 'run01',
tasks: [
{
name: 'task01',
runtime: {
containers: [
{
image: 'alpine/git',
},
],
},
steps: [
{ type: 'clone' },
{ type: 'run', command: 'env' },
],
},
],
},
],
}
`,
num: 0,
message: "commit\n\n[ci skip] body",
},
}
@ -604,7 +667,7 @@ func TestPush(t *testing.T) {
giteaRepo, project := createProject(ctx, t, giteaClient, gwClient)
push(t, tt.config, giteaRepo.CloneURL, giteaToken)
push(t, tt.config, giteaRepo.CloneURL, giteaToken, tt.message)
_ = testutil.Wait(30*time.Second, func() (bool, error) {
runs, _, err := gwClient.GetRuns(ctx, nil, nil, []string{path.Join("/project", project.ID)}, nil, "", 0, false)