Skip to content

feat(matcher): skip ACL when .tekton dir absent#2699

Draft
theakshaypant wants to merge 1 commit into
tektoncd:mainfrom
theakshaypant:feat/skip-neutral-status-on-absent-tekton-dir
Draft

feat(matcher): skip ACL when .tekton dir absent#2699
theakshaypant wants to merge 1 commit into
tektoncd:mainfrom
theakshaypant:feat/skip-neutral-status-on-absent-tekton-dir

Conversation

@theakshaypant
Copy link
Copy Markdown
Member

@theakshaypant theakshaypant commented Apr 22, 2026

📝 Description of the Change

Reorder matchRepoPR to fetch .tekton templates before ACL checks. When the .tekton directory is missing, the flow returns early without triggering permission checks or posting unwarranted status updates to the Git provider.

Split verifyRepoAndUser into setupRepo and checkUserAccess, and extract fetchTektonTemplates from getPipelineRunsFromRepo. The existing verifyRepoAndUser is kept as a thin wrapper for flows that need setup + ACL without .tekton checks.

🔗 Linked GitHub Issue

Fixes #2692

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

No PaC check run on external contributor when .tekton dir is absent
no-pac-check-on-absent-tekton-dir

Neutral check still shows up if an admin comments /ok-to-test with .tekton dir absent
neutral-check-on-ok-to-test

Controller Logs {"level":"debug","ts":"2026-04-27T06:13:43.427Z","logger":"pipelinesascode","caller":"pipelineascode/logging.go:9","msg":"fetchTektonTemplates: fetched templates length=0","commit":"cb3975c-dirty","provider":"github","event-id":"3cb67620-4200-11f1-9135-e12bf898c03c","event-sha":"a85ee1193878a13898d1a24c64b1af91dda86ee1","event-type":"pull_request","source-repo-url":"https://ghe.pipelinesascode.com/akpant-test/ghe-app-test","target-branch":"main","source-branch":"nonadmin-patch-1","namespace":"default"} {"level":"info","ts":"2026-04-27T06:13:43.427Z","logger":"pipelinesascode","caller":"events/emit.go:51","msg":"cannot locate templates in .tekton/ directory for this repository in nonadmin-patch-1","commit":"cb3975c-dirty","provider":"github","event-id":"3cb67620-4200-11f1-9135-e12bf898c03c","event-sha":"a85ee1193878a13898d1a24c64b1af91dda86ee1","event-type":"pull_request","source-repo-url":"https://ghe.pipelinesascode.com/akpant-test/ghe-app-test","target-branch":"main","source-branch":"nonadmin-patch-1","namespace":"default"} {"level":"debug","ts":"2026-04-27T06:13:43.427Z","logger":"pipelinesascode","caller":"pipelineascode/logging.go:9","msg":"match results: matched=0 repo=default/akshay-pac-test-repo","commit":"cb3975c-dirty","provider":"github","event-id":"3cb67620-4200-11f1-9135-e12bf898c03c","event-sha":"a85ee1193878a13898d1a24c64b1af91dda86ee1","event-type":"pull_request","source-repo-url":"https://ghe.pipelinesascode.com/akpant-test/ghe-app-test","target-branch":"main","source-branch":"nonadmin-patch-1","namespace":"default"} {"level":"debug","ts":"2026-04-27T06:13:43.427Z","logger":"pipelinesascode","caller":"pipelineascode/logging.go:9","msg":"no pipelineruns matched; returning without starting any runs","commit":"cb3975c-dirty","provider":"github","event-id":"3cb67620-4200-11f1-9135-e12bf898c03c","event-sha":"a85ee1193878a13898d1a24c64b1af91dda86ee1","event-type":"pull_request","source-repo-url":"https://ghe.pipelinesascode.com/akpant-test/ghe-app-test","target-branch":"main","source-branch":"nonadmin-patch-1","namespace":"default"}

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the repository matching and ACL check logic in matchRepoPR by decomposing it into setupRepo, fetchTektonTemplates, and checkUserAccess. This change ensures that ACL checks and status updates are skipped if no .tekton templates are found. Feedback was provided regarding error handling: specifically, ensuring the Repository object is returned upon failure in matchRepoPR to assist in error reporting, and avoiding the suppression of errors in fetchTektonTemplates to prevent masking infrastructure or API issues.

Comment thread pkg/pipelineascode/match.go Outdated
p.debugf("matchRepoPR: starting repo setup for url=%s", p.event.URL)
repo, err := p.setupRepo(ctx)
if err != nil {
return nil, nil, err
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When setupRepo returns an error, it may still have successfully matched a Repository object. Returning nil for the repository here prevents the caller from using that repository information for error reporting or status updates. It is better to return the matched repo along with the error.

Suggested change
return nil, nil, err
return nil, repo, err

msg = fmt.Sprintf("cannot locate templates in %s/ directory for this repository in %s", tektonDir, p.event.HeadBranch)
}
p.eventEmitter.EmitMessage(nil, logLevel, reason, msg)
return "", nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Returning "", nil when err != nil (checked at line 205) swallows potential infrastructure or API errors (e.g., rate limits, network failures). This makes it difficult for users to understand why their pipelines are not triggering. The function should distinguish between a "directory not found" condition and other errors, returning the latter to the caller.

Suggested change
return "", nil
return "", err

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pre-existing behavior, the original code returned nil, nil here (previously on the combined err != nil || rawTemplates == "" path). The error is not silently discarded; it's emitted at ErrorLevel using eventEmitter.EmitMessage with reason RepositoryInvalidPipelineRunTemplate, so it is visible on the cluster.
Propagating the error here would cause matchRepoPR call to post a faiulure status on the commit - which is aa bheaviour change. @zakisk could you provide some context on this behaviour?

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 82.14286% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.05%. Comparing base (9c4e9cb) to head (7ee69df).

Files with missing lines Patch % Lines
pkg/pipelineascode/match.go 82.14% 7 Missing and 3 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2699      +/-   ##
==========================================
+ Coverage   59.00%   59.05%   +0.04%     
==========================================
  Files         208      208              
  Lines       20436    20477      +41     
==========================================
+ Hits        12059    12092      +33     
- Misses       7603     7607       +4     
- Partials      774      778       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Reorder matchRepoPR to fetch .tekton templates before ACL checks.
When the .tekton directory is missing, the flow returns early
without triggering permission checks or posting unwarranted status
updates to the Git provider.

Split verifyRepoAndUser into setupRepo and checkUserAccess, and
extract fetchTektonTemplates from getPipelineRunsFromRepo. The
existing verifyRepoAndUser is kept as a thin wrapper for flows
that need setup + ACL without .tekton checks.

Signed-off-by: Akshay Pant <akpant@redhat.com>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
@theakshaypant theakshaypant force-pushed the feat/skip-neutral-status-on-absent-tekton-dir branch from 7ee69df to b02e485 Compare April 27, 2026 08:24
@theakshaypant theakshaypant marked this pull request as ready for review April 27, 2026 08:24
@zakisk
Copy link
Copy Markdown
Member

zakisk commented Apr 28, 2026

changes looks fine but I have concern about API calling, let's assume a scenario where a repo has 100 pipeline runs and an unauthorized user sends PR, PaC will iterate through all the pipeline run and then will check the permission. it won't make issue when there is no pipeline run, but a repo with 100 pipeline run or other tekton resources (taskruns, stepactions) there will api calls equals to resources which exhaust the rate limit of token and after all that it will just put a message that use is not authorized to run CI 🤷🏻
cc: @chmouel

@zakisk
Copy link
Copy Markdown
Member

zakisk commented Apr 28, 2026

there no issue of having neutral check on /ok-to-test comment IMO.

@theakshaypant
Copy link
Copy Markdown
Member Author

a repo with 100 pipeline run or other tekton resources (taskruns, stepactions) there will api calls equals to resources which exhaust the rate limit

That is a fair concern, let me rethink and update here.

there no issue of having neutral check on /ok-to-test comment IMO.

Agreed, have retained this original behaviour from 846416e

@theakshaypant theakshaypant marked this pull request as draft May 4, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PAC should not request /ok-to-test approval or create check runs when no .tekton/ pipeline runs exist in the repository

3 participants