Skip to content

Commit b4acfcd

Browse files
committed
Don't apply for ACL on push
Closes #681 Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent 6564de7 commit b4acfcd

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

pkg/pipelineascode/match.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,28 @@ is that what you want? make sure you use -n when generating the secret, eg: echo
8989
}
9090

9191
// Check if the submitter is allowed to run this.
92-
allowed, err := p.vcx.IsAllowed(ctx, p.event)
93-
if err != nil {
94-
return nil, nil, err
95-
}
96-
97-
if !allowed {
98-
msg := fmt.Sprintf("User %s is not allowed to run CI on this repo.", p.event.Sender)
99-
p.logger.Info(msg)
100-
if p.event.AccountID != "" {
101-
msg = fmt.Sprintf("User: %s AccountID: %s is not allowed to run CI on this repo.", p.event.Sender, p.event.AccountID)
102-
}
103-
status := provider.StatusOpts{
104-
Status: "completed",
105-
Conclusion: "skipped",
106-
Text: msg,
107-
DetailsURL: "https://tenor.com/search/police-cat-gifs",
92+
if p.event.EventType != "push" {
93+
allowed, err := p.vcx.IsAllowed(ctx, p.event)
94+
if err != nil {
95+
return nil, nil, err
10896
}
109-
if err := p.vcx.CreateStatus(ctx, p.event, p.run.Info.Pac, status); err != nil {
110-
return nil, nil, fmt.Errorf("failed to run create status, user is not allowed to run: %w", err)
97+
if !allowed {
98+
msg := fmt.Sprintf("User %s is not allowed to run CI on this repo.", p.event.Sender)
99+
p.logger.Info(msg)
100+
if p.event.AccountID != "" {
101+
msg = fmt.Sprintf("User: %s AccountID: %s is not allowed to run CI on this repo.", p.event.Sender, p.event.AccountID)
102+
}
103+
status := provider.StatusOpts{
104+
Status: "completed",
105+
Conclusion: "skipped",
106+
Text: msg,
107+
DetailsURL: "https://tenor.com/search/police-cat-gifs",
108+
}
109+
if err := p.vcx.CreateStatus(ctx, p.event, p.run.Info.Pac, status); err != nil {
110+
return nil, nil, fmt.Errorf("failed to run create status, user is not allowed to run: %w", err)
111+
}
112+
return nil, nil, nil
111113
}
112-
return nil, nil, nil
113114
}
114115

115116
rawTemplates := p.getAllPipelineRuns(ctx)
@@ -146,7 +147,6 @@ is that what you want? make sure you use -n when generating the secret, eg: echo
146147
if err != nil {
147148
return nil, nil, err
148149
}
149-
150150
// Match the PipelineRun with annotation
151151
matchedPRs, err := matcher.MatchPipelinerunByAnnotation(ctx, p.logger, pipelineRuns, p.run, p.event)
152152
if err != nil {

pkg/pipelineascode/pipelinesascode_github_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,23 @@ func TestRun(t *testing.T) {
312312
finalStatusText: "is not allowed to run CI on this repo",
313313
skipReplyingOrgPublicMembers: true,
314314
},
315+
{
316+
name: "allowed/push event even from non allowed user",
317+
runevent: info.Event{
318+
SHA: "principale",
319+
Organization: "organizationes",
320+
Repository: "lagaffe",
321+
URL: "https://service/documentation",
322+
HeadBranch: "press",
323+
Sender: "evilbro",
324+
BaseBranch: "main",
325+
EventType: "push",
326+
TriggerTarget: "push",
327+
},
328+
tektondir: "testdata/push_branch",
329+
finalStatus: "skipped",
330+
skipReplyingOrgPublicMembers: true,
331+
},
315332
{
316333
name: "Keep max number of pipelineruns",
317334
runevent: info.Event{

0 commit comments

Comments
 (0)