-
Notifications
You must be signed in to change notification settings - Fork 114
fix: avoid reporting errors for non-Tekton res #2147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: avoid reporting errors for non-Tekton res #2147
Conversation
8c994b7
to
9100bc3
Compare
AI Review from gemini-proOf course! I've carefully analyzed the provided git changes. Here's a breakdown of my findings, covering improvements, potential issues, and overall code quality. This change is a well-executed refactoring of the YAML validation error handling. It significantly improves the system's robustness and the clarity of error reporting for users. Overall AnalysisThe main goal of this change is to replace a simple The changes are consistently applied across the File-by-File Breakdown1.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors YAML validation error handling to only report issues for Tekton resources or fundamentally invalid YAML by introducing a structured error type and filtering logic.
- Introduced
PacYamlValidations
struct andGenericBadYAMLValidation
constant. - Updated
ReadTektonTypes
andreportValidationErrors
to collect and filter structured errors by Tekton API group or generic YAML syntax. - Added end-to-end tests and a Gitea integration test to verify non-Tekton resources are ignored.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/testdata/randomcrd.yaml | Added CRD YAML for non-Tekton resource test |
test/gitea_test.go | New test to ensure non-Tekton YAML does not generate comments on PR |
pkg/resolve/resolve.go | Refactored YAML decoding to record structured errors and filter by schema |
pkg/resolve/resolve_test.go | Updated tests to validate structured errors, schema detection, and filtering logic |
pkg/pipelineascode/match.go | Adapted getPipelineRunsFromRepo to use structured errors type |
pkg/errors/errors.go | Introduced PacYamlValidations type and GenericBadYAMLValidation constant |
docs/content/docs/guide/running.md | Updated documentation to clarify error reporting scope for Tekton resources |
Comments suppressed due to low confidence (6)
pkg/resolve/resolve.go:55
- [nitpick] The function name has a typo:
Atleast
should beAtLeast
for correct casing and readability. Consider renaming todetectAtLeastNameOrGenerateNameAndSchemaFromPipelineRun
.
func detectAtleastNameOrGenerateNameAndSchemaFromPipelineRun(data string) (string, string) {
test/gitea_test.go:241
- [nitpick] The test name is a bit long and uses a double negative. Consider renaming to something clearer like
TestGiteaDoesNotReportNonTektonResources
.
func TestGiteaYamlReportingNotReportingNotTektonResources(t *testing.T) {
pkg/pipelineascode/match.go:194
- The code uses fmt.Errorf but
fmt
is not imported in this file. Please addimport "fmt"
to resolve the compilation error.
Err: fmt.Errorf("yaml validation error: %s", matches[3]),
pkg/resolve/resolve_test.go:333
- The
assert.Equal
arguments are reversed: the literal should be the expected value and the constant should be the actual. Swap them for clearer intent (assert.Equal(t, "Generic bad YAML Validation", pacerrors.GenericBadYAMLValidation)
).
assert.Equal(t, pacerrors.GenericBadYAMLValidation, "Generic bad YAML Validation")
e6cb4d2
to
0f4d44c
Compare
if there is any non-tekton resource with invalid YAML, PaC will still fail to process the event, right? |
@zakisk that's correct, if it ends up with .yaml and it's invalid it would fail, but then it's up to the user to not put *** in their .tekton |
but if comment is not created for non-tekton resources (and it shouldn't) it will create confusion that why event is not processed? I think non-tekton resources should be ignored whether they're good or bad, wdyt? |
we can't read the yaml file because of the error so we don't really know if it's a tekton resource or not, we try to grep inot the yaml if there is a kind: PipelineRun but that would be not enough |
The handling of YAML validation errors was refactored to be more intelligent and less noisy. It now only reports errors for resources that are identified as Tekton resources or are fundamentally invalid YAML. - Refactored validation errors from a simple map to a structured type that includes the resource name, schema, and error object. - Updated YAML parsing to extract the resource's `apiVersion` (schema) even when the document fails to decode fully as a Tekton object. - Implemented filtering to report validation errors only for resources with a `tekton.dev` API group or for generic YAML syntax errors. - This prevents creating error comments on pull requests for other valid, non-Tekton YAML files located in the `.tekton` directory. Jira: https://issues.redhat.com/browse/SRVKP-7906 Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
0f4d44c
to
3cb3105
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congrats @chmouel your PR Has been approved 🎉
✅ Pull Request Approved
Approval Status:
- Required Approvals: 1
- Current Approvals: 1
👥 Reviewers Who Approved:
Reviewer | Permission Level | Approval Status |
---|---|---|
@zakisk | admin |
✅ |
📝 Next Steps
- Ensure all required checks pass
- Comply with branch protection rules
- Request a maintainer to merge using the
/merge
command (or merge it
directly if you have repository permission).
Automated by the PAC Boussole 🧭
/merge |
46067b2
into
openshift-pipelines:main
✅ PR Successfully Merged
Approvals Summary:
Thank you @chmouel for your valuable contribution! 🎉 Automated by the PAC Boussole 🧭 |
The handling of YAML validation errors was refactored to be more intelligent and less noisy. It now only reports errors for resources that are identified as Tekton resources or are fundamentally invalid YAML.
apiVersion
(schema) even when the document fails to decode fully as a Tekton object.tekton.dev
API group or for generic YAML syntax errors..tekton
directory.Jira: https://issues.redhat.com/browse/SRVKP-7906
Changes
Submitter Checklist
📝 Ensure your commit message is clear and informative. Refer to the How to write a git commit message guide. Include the commit message in the PR body rather than linking to an external site (e.g., Jira ticket).
♽ Run make test lint before submitting a PR to avoid unnecessary CI processing. Consider installing pre-commit and running pre-commit install in the repository root for an efficient workflow.
✨ We use linters to maintain clean and consistent code. Run make lint before submitting a PR. Some linters offer a --fix mode, executable with make fix-linters (ensure markdownlint and golangci-lint are installed).
📖 Document any user-facing features or changes in behavior.
🧪 While 100% coverage isn't required, we encourage unit tests for code changes where possible.
🎁 If feasible, add an end-to-end test. See README for details.
🔎 Address any CI test flakiness before merging, or provide a valid reason to bypass it (e.g., token rate limitations).
If adding a provider feature, fill in the following details:
(update the provider documentation accordingly)