Skip to content

fix(lint): resolve golangci-lint issues#2551

Merged
chmouel merged 1 commit intotektoncd:mainfrom
chmouel:fix-golangci-lint
Mar 9, 2026
Merged

fix(lint): resolve golangci-lint issues#2551
chmouel merged 1 commit intotektoncd:mainfrom
chmouel:fix-golangci-lint

Conversation

@chmouel
Copy link
Copy Markdown
Member

@chmouel chmouel commented Mar 9, 2026

Fix all 12 golangci-lint violations:

  • Add #nosec G118 to suppress false-positive in pipelinerunmetrics (cancel is called in goroutine)
  • Preallocate baseFields slice in github.go (prealloc)
  • Replace httptest.NewRequest with NewRequestWithContext in incoming_test.go and token_test.go (noctx)

Assisted-by: Claude Sonnet 4.6 (via Claude Code)

📝 Description of the Change

👨🏻‍ Linked Jira

🔗 Linked GitHub Issue

Fixes #2550

🧪 Testing Strategy

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

🤖 AI Assistance

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

If you have used AI assistance, please provide the following details:

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

Important

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: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com

**💡You can use the script ./hack/add-llm-coauthor.sh to automatically add
these co-author trailers to your commits.

✅ 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

Fix all 12 golangci-lint violations:
- Add #nosec G118 to suppress false-positive in
  pipelinerunmetrics (cancel is called in goroutine)
- Preallocate baseFields slice in github.go (prealloc)
- Replace httptest.NewRequest with NewRequestWithContext
  in incoming_test.go and token_test.go (noctx)

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
Assisted-by: Claude Sonnet 4.6 (via Claude Code)
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing code quality and adherence to best practices by resolving several golangci-lint violations. The changes involve suppressing a specific false-positive warning, optimizing slice allocation for better performance, and ensuring proper context handling in HTTP test requests. These updates contribute to a cleaner codebase and prevent potential issues related to context propagation.

Highlights

  • Linting Issue Resolution: Addressed a G118 false-positive linting issue in pipelinerunmetrics by adding a #nosec comment, acknowledging that the context cancellation is handled correctly in a goroutine.
  • Performance Optimization: Improved performance in github.go by preallocating the baseFields slice, which helps reduce reallocations when appending elements.
  • Context Propagation: Replaced httptest.NewRequest with httptest.NewRequestWithContext in incoming_test.go and token_test.go to ensure proper context propagation in HTTP requests within tests, addressing a noctx lint warning.
Changelog
  • pkg/adapter/incoming_test.go
    • Imported the context package.
    • Replaced httptest.NewRequest with httptest.NewRequestWithContext in multiple test functions (Test_listener_detectIncoming, Test_detectIncoming_legacy_warning, Test_detectIncoming_body_params_are_parsed, Test_parseIncomingPayload).
  • pkg/pipelinerunmetrics/injection.go
    • Added a #nosec G118 comment to the context.WithCancel call to suppress a false-positive security linter warning, clarifying that the cancel function is called within a goroutine.
  • pkg/provider/github/app/token_test.go
    • Replaced httptest.NewRequest with httptest.NewRequestWithContext in test functions (Test_GenerateJWT, Test_GetAndUpdateInstallationID, TestGetAndUpdateInstallationID_Fallbacks).
  • pkg/provider/github/github.go
    • Modified the initialization of the baseFields slice to preallocate its capacity using make([]any, 0, 18+len(kv)) for improved efficiency.
Activity
  • The pull request author, chmouel, indicated that Claude Sonnet 4.6 (via Claude Code) assisted in the creation of this PR.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@chmouel
Copy link
Copy Markdown
Member Author

chmouel commented Mar 9, 2026

no need to run the e2e tests since it's only a linter fix so merging

@chmouel chmouel merged commit 46ec8a2 into tektoncd:main Mar 9, 2026
10 of 12 checks passed
@chmouel chmouel deleted the fix-golangci-lint branch March 9, 2026 10:16
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 effectively resolves several golangci-lint violations, including noctx, G118, and prealloc. The changes are correct and address the reported issues. I have one suggestion for the prealloc fix in pkg/provider/github/github.go to improve readability and maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

golangci-lint errors

2 participants