Skip to content

Commit 15f7ad1

Browse files
authored
Merge branch 'main' into fix-branch-delete-event-github
2 parents cfdfa82 + c2b17f0 commit 15f7ad1

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

.github/workflows/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
steps:
6464
- uses: actions/checkout@v4
6565
with:
66-
ref: ${{ github.sha }}
66+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
6767

6868
- uses: actions/setup-go@v5
6969
with:

docs/content/docs/guide/incoming_webhook.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ A PipelineRun is then annotated to target the incoming event and the main branch
6565
apiVersion: tekton.dev/v1
6666
kind: PipelineRun
6767
metadata:
68-
name: target_pipelinerun
68+
name: target-pipelinerun
6969
annotations:
7070
pipelinesascode.tekton.dev/on-event: "[incoming]"
7171
pipelinesascode.tekton.dev/on-target-branch: "[main]"
@@ -95,7 +95,7 @@ You can use the `generateName` field as the PipelineRun name but you will need t
9595
As an example here is a curl snippet starting the PipelineRun:
9696

9797
```shell
98-
curl -X POST 'https://control.pac.url/incoming?secret=very-secure-shared-secret&repository=repo&branch=main&pipelinerun=target_pipelinerun'
98+
curl -X POST 'https://control.pac.url/incoming?secret=very-secure-shared-secret&repository=repo&branch=main&pipelinerun=target-pipelinerun'
9999
```
100100

101101
in this snippet, note two things the `"/incoming"` path to the controller URL
@@ -144,7 +144,7 @@ spec:
144144
and here is a curl snippet passing the `pull_request_number` value:
145145

146146
```shell
147-
curl -H "Content-Type: application/json" -X POST "https://control.pac.url/incoming?repository=repo&branch=main&secret=very-secure-shared-secret&pipelinerun=target_pipelinerun" -d '{"params": {"pull_request_number": "12345"}}'
147+
curl -H "Content-Type: application/json" -X POST "https://control.pac.url/incoming?repository=repo&branch=main&secret=very-secure-shared-secret&pipelinerun=target-pipelinerun" -d '{"params": {"pull_request_number": "12345"}}'
148148
```
149149

150150
The parameter value of `pull_request_number` will be set to `12345` when using the variable `{{pull_request_number}}` in your PipelineRun.
@@ -156,7 +156,7 @@ specify the `X-GitHub-Enterprise-Host` header when making the incoming webhook
156156
request. For example when using curl:
157157

158158
```shell
159-
curl -H "X-GitHub-Enterprise-Host: github.example.com" -X POST "https://control.pac.url/incoming?repository=repo&branch=main&secret=very-secure-shared-secret&pipelinerun=target_pipelinerun"
159+
curl -H "X-GitHub-Enterprise-Host: github.example.com" -X POST "https://control.pac.url/incoming?repository=repo&branch=main&secret=very-secure-shared-secret&pipelinerun=target-pipelinerun"
160160
```
161161

162162
### Using incoming webhook with webhook based providers

pkg/pipelineascode/cancel_pipelineruns.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (p *PacRun) cancelAllInProgressBelongingToClosedPullRequest(ctx context.Con
4646
if len(prs.Items) == 0 {
4747
msg := fmt.Sprintf("no pipelinerun found for repository: %v and pullRequest %v",
4848
p.event.Repository, p.event.PullRequestNumber)
49-
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "RepositoryPipelineRun", msg)
49+
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "CancelInProgress", msg)
5050
return nil
5151
}
5252

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

@@ -183,7 +183,7 @@ func (p *PacRun) cancelPipelineRuns(ctx context.Context, prs *tektonv1.PipelineR
183183
defer wg.Done()
184184
if _, err := action.PatchPipelineRun(ctx, p.logger, "cancel patch", p.run.Clients.Tekton, &pr, cancelMergePatch); err != nil {
185185
errMsg := fmt.Sprintf("failed to cancel pipelineRun %s/%s: %s", pr.GetNamespace(), pr.GetName(), err.Error())
186-
p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "RepositoryPipelineRun", errMsg)
186+
p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "CancelInProgress", errMsg)
187187
}
188188
}(ctx, pr)
189189
}

test/pkg/gitea/test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
2828
"github.com/tektoncd/pipeline/pkg/names"
2929
"gotest.tools/v3/assert"
30+
corev1 "k8s.io/api/core/v1"
3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
)
3233

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

76+
func checkEvents(t *testing.T, events *corev1.EventList, topts *TestOpts) {
77+
t.Helper()
78+
newEvents := make([]corev1.Event, 0)
79+
// filter out events that are not related to the test like checking for cancelled pipelineruns
80+
for i := len(events.Items) - 1; i >= 0; i-- {
81+
topts.ParamsRun.Clients.Log.Infof("Reason is %s", events.Items[i].Reason)
82+
if events.Items[i].Reason == "CancelInProgress" {
83+
continue
84+
}
85+
newEvents = append(newEvents, events.Items[i])
86+
}
87+
if len(newEvents) > 0 {
88+
topts.ParamsRun.Clients.Log.Infof("0 events expected in case of failure but got %d", len(newEvents))
89+
for _, em := range newEvents {
90+
topts.ParamsRun.Clients.Log.Infof("Event: Reason: %s Type: %s ReportingInstance: %s Message: %s", em.Reason, em.Type, em.ReportingInstance, em.Message)
91+
}
92+
t.FailNow()
93+
}
94+
}
95+
7596
func AddLabelToIssue(t *testing.T, topt *TestOpts, label string) {
7697
var targetID int64
7798
allLabels, _, err := topt.GiteaCNX.Client.ListRepoLabels(topt.Opts.Organization, topt.Opts.Repo, gitea.ListLabelsOptions{})
@@ -249,7 +270,7 @@ func TestPR(t *testing.T, topts *TestOpts) (context.Context, func()) {
249270
}
250271
assert.Assert(t, len(events.Items) != 0, "events expected in case of failure but got 0")
251272
} else if !topts.SkipEventsCheck {
252-
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))
273+
checkEvents(t, events, topts)
253274
}
254275
return ctx, cleanup
255276
}
@@ -369,7 +390,7 @@ func NewPR(t *testing.T, topts *TestOpts) func() {
369390
}
370391
assert.Assert(t, len(events.Items) != 0, "events expected in case of failure but got 0")
371392
} else if !topts.SkipEventsCheck {
372-
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))
393+
checkEvents(t, events, topts)
373394
}
374395
return cleanup
375396
}

0 commit comments

Comments
 (0)