Skip to content
New issue

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

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

Already on GitHub? # to your account

skip run with special commit #90

Merged
merged 1 commit into from
Sep 20, 2019
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
10 changes: 10 additions & 0 deletions internal/services/gateway/action/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"net/http"
"path"
"regexp"

"agola.io/agola/internal/config"
gitsource "agola.io/agola/internal/gitsources"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
71 changes: 67 additions & 4 deletions tests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -510,6 +510,7 @@ func TestPush(t *testing.T) {
config string
num int
annotations map[string]string
message string
}{
{
name: "test push",
Expand Down Expand Up @@ -544,6 +545,7 @@ func TestPush(t *testing.T) {
"ref": "refs/heads/master",
"ref_type": "branch",
},
message: "commit",
},
{
name: "test push with unmatched branch",
Expand Down Expand Up @@ -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",
},
}

Expand Down Expand Up @@ -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)
Expand Down