Skip to content

Commit d01d86f

Browse files
authored
Merge branch 'main' into distributed-tracing
2 parents 06ab2d5 + e61bf66 commit d01d86f

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

.github/scripts/check-pr-permissions.js

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,6 @@ module.exports = async ({ github, context, core }) => {
2626
core.info(`📋 Repository: ${repoOwner}/${repoName}`);
2727
core.info(`🏢 Target organization: ${targetOrg}`);
2828

29-
// Security: On non-labeled events (opened, reopened, synchronize),
30-
// remove the ok-to-test label if present. This prevents an external
31-
// contributor from pushing malicious code after a maintainer approved via label.
32-
if (context.payload.action !== "labeled") {
33-
const currentLabels = context.payload.pull_request.labels.map(
34-
(l) => l.name,
35-
);
36-
if (currentLabels.includes("ok-to-test")) {
37-
core.info(
38-
`🔒 Removing ok-to-test label due to '${context.payload.action}' event — re-approval required.`,
39-
);
40-
try {
41-
await github.rest.issues.removeLabel({
42-
owner: repoOwner,
43-
repo: repoName,
44-
issue_number: context.payload.pull_request.number,
45-
name: "ok-to-test",
46-
});
47-
core.info(` Label removed successfully.`);
48-
} catch (err) {
49-
// 404 is expected when multiple matrix jobs race to remove the same label
50-
if (err.status === 404) {
51-
core.info(` Label already removed (likely by another matrix job).`);
52-
} else {
53-
core.warning(` Failed to remove ok-to-test label: ${err.message}`);
54-
}
55-
}
56-
}
57-
}
58-
5929
// Condition 1: Check if the user is a trusted bot.
6030
const trustedBots = ["dependabot[bot]", "renovate[bot]"];
6131
core.info(`🤖 Checking if @${actor} is a trusted bot...`);
@@ -207,8 +177,24 @@ module.exports = async ({ github, context, core }) => {
207177
context.payload.label.name === "ok-to-test"
208178
) {
209179
core.info(
210-
`✅ Condition met: ok-to-test label applied by @${context.actor}. Proceeding with tests.`,
180+
`✅ Condition met: ok-to-test label applied by @${context.actor}. Removing label and proceeding with tests.`,
211181
);
182+
try {
183+
await github.rest.issues.removeLabel({
184+
owner: repoOwner,
185+
repo: repoName,
186+
issue_number: context.payload.pull_request.number,
187+
name: "ok-to-test",
188+
});
189+
core.info(` ok-to-test label removed successfully.`);
190+
} catch (err) {
191+
// 404 is expected when multiple matrix jobs race to remove the same label
192+
if (err.status !== 404) {
193+
core.setFailed(` Failed to remove ok-to-test label: ${err.message}`);
194+
return;
195+
}
196+
core.info(` Label already removed (likely by another matrix job).`);
197+
}
212198
return;
213199
}
214200

.github/workflows/e2e.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ on:
2525
- ".github/workflows/**"
2626
- "test/testdata/**"
2727
- "vendor/**"
28+
- ".github/scripts/**"
2829

2930
jobs:
3031
e2e-tests:

test/github_pullrequest_retest_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"fmt"
88
"strings"
99
"testing"
10+
"time"
1011

1112
"github.com/google/go-github/v84/github"
1213
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/keys"
1314
tgithub "github.com/openshift-pipelines/pipelines-as-code/test/pkg/github"
1415
twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
16+
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
1517
"gotest.tools/v3/assert"
1618
corev1 "k8s.io/api/core/v1"
1719
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -98,21 +100,21 @@ func TestGithubGHEPullRequestGitopsCommentCancel(t *testing.T) {
98100
&github.IssueComment{Body: github.Ptr("/cancel pr-gitops-comment")})
99101
assert.NilError(t, err)
100102

101-
waitOpts = twait.Opts{
103+
cancelWaitOpts := twait.Opts{
102104
RepoName: g.TargetNamespace,
103105
Namespace: g.TargetNamespace,
104-
MinNumberStatus: 3,
105-
PollTimeout: twait.DefaultTimeout,
106+
MinNumberStatus: 1,
107+
PollTimeout: 90 * time.Second,
106108
TargetSHA: g.SHA,
107109
}
108-
g.Cnx.Clients.Log.Info("Waiting for Repository to be updated")
109-
_, err = twait.UntilRepositoryUpdated(ctx, g.Cnx.Clients, waitOpts)
110+
111+
g.Cnx.Clients.Log.Info("Waiting for PipelineRun to be cancelled")
112+
err = twait.UntilPipelineRunHasReason(ctx, g.Cnx.Clients, tektonv1.PipelineRunReasonCancelled, cancelWaitOpts)
110113
assert.NilError(t, err)
111114

112-
g.Cnx.Clients.Log.Infof("Check if we have the repository set as succeeded")
113-
repo, err := g.Cnx.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(g.TargetNamespace).Get(ctx, g.TargetNamespace, metav1.GetOptions{})
115+
g.Cnx.Clients.Log.Info("Waiting for Repository status to reflect cancellation")
116+
_, err = twait.UntilRepositoryHasStatusReason(ctx, g.Cnx.Clients, cancelWaitOpts, tektonv1.PipelineRunReasonCancelled.String())
114117
assert.NilError(t, err)
115-
assert.Equal(t, repo.Status[len(repo.Status)-1].Conditions[0].Status, corev1.ConditionFalse)
116118

117119
pruns, err = g.Cnx.Clients.Tekton.TektonV1().PipelineRuns(g.TargetNamespace).List(ctx, metav1.ListOptions{
118120
LabelSelector: fmt.Sprintf("%s=%s", keys.SHA, g.SHA),

0 commit comments

Comments
 (0)