Skip to content
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
6 changes: 3 additions & 3 deletions pkg/pipelineascode/cancel_pipelineruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (p *PacRun) cancelAllInProgressBelongingToClosedPullRequest(ctx context.Con
if len(prs.Items) == 0 {
msg := fmt.Sprintf("no pipelinerun found for repository: %v and pullRequest %v",
p.event.Repository, p.event.PullRequestNumber)
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "RepositoryPipelineRun", msg)
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "CancelInProgress", msg)
return nil
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func (p *PacRun) cancelPipelineRunsOpsComment(ctx context.Context, repo *v1alpha
if len(prs.Items) == 0 {
msg := fmt.Sprintf("no pipelinerun found for repository: %v , sha: %v and pulRequest %v",
p.event.Repository, p.event.SHA, p.event.PullRequestNumber)
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "RepositoryPipelineRun", msg)
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "CancelInProgress", msg)
return nil
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func (p *PacRun) cancelPipelineRuns(ctx context.Context, prs *tektonv1.PipelineR
defer wg.Done()
if _, err := action.PatchPipelineRun(ctx, p.logger, "cancel patch", p.run.Clients.Tekton, &pr, cancelMergePatch); err != nil {
errMsg := fmt.Sprintf("failed to cancel pipelineRun %s/%s: %s", pr.GetNamespace(), pr.GetName(), err.Error())
p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "RepositoryPipelineRun", errMsg)
p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "CancelInProgress", errMsg)
}
}(ctx, pr)
}
Expand Down
25 changes: 23 additions & 2 deletions test/pkg/gitea/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/names"
"gotest.tools/v3/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -72,6 +73,26 @@ func PostCommentOnPullRequest(t *testing.T, topt *TestOpts, body string) {
assert.NilError(t, err)
}

func checkEvents(t *testing.T, events *corev1.EventList, topts *TestOpts) {
t.Helper()
newEvents := make([]corev1.Event, 0)
// filter out events that are not related to the test like checking for cancelled pipelineruns
for i := len(events.Items) - 1; i >= 0; i-- {
topts.ParamsRun.Clients.Log.Infof("Reason is %s", events.Items[i].Reason)
if events.Items[i].Reason == "CancelInProgress" {
continue
}
newEvents = append(newEvents, events.Items[i])
}
if len(newEvents) > 0 {
topts.ParamsRun.Clients.Log.Infof("0 events expected in case of failure but got %d", len(newEvents))
for _, em := range newEvents {
topts.ParamsRun.Clients.Log.Infof("Event: Reason: %s Type: %s ReportingInstance: %s Message: %s", em.Reason, em.Type, em.ReportingInstance, em.Message)
}
t.FailNow()
}
}

func AddLabelToIssue(t *testing.T, topt *TestOpts, label string) {
var targetID int64
allLabels, _, err := topt.GiteaCNX.Client.ListRepoLabels(topt.Opts.Organization, topt.Opts.Repo, gitea.ListLabelsOptions{})
Expand Down Expand Up @@ -249,7 +270,7 @@ func TestPR(t *testing.T, topts *TestOpts) (context.Context, func()) {
}
assert.Assert(t, len(events.Items) != 0, "events expected in case of failure but got 0")
} else if !topts.SkipEventsCheck {
assert.Assert(t, len(events.Items) == 0, fmt.Sprintf("no events expected but got %v in %v ns, items: %+v", len(events.Items), topts.TargetNS, events.Items))
checkEvents(t, events, topts)
}
return ctx, cleanup
}
Expand Down Expand Up @@ -369,7 +390,7 @@ func NewPR(t *testing.T, topts *TestOpts) func() {
}
assert.Assert(t, len(events.Items) != 0, "events expected in case of failure but got 0")
} else if !topts.SkipEventsCheck {
assert.Assert(t, len(events.Items) == 0, fmt.Sprintf("no events expected but got %v in %v ns, items: %+v", len(events.Items), topts.TargetNS, events.Items))
checkEvents(t, events, topts)
}
return cleanup
}
Expand Down
Loading