Skip to content

feat(webhook): add Forgejo CLI setup#2764

Merged
chmouel merged 1 commit into
tektoncd:mainfrom
SecKatie:issue-2755-forgejo-cli-webhook
Jul 6, 2026
Merged

feat(webhook): add Forgejo CLI setup#2764
chmouel merged 1 commit into
tektoncd:mainfrom
SecKatie:issue-2755-forgejo-cli-webhook

Conversation

@SecKatie

@SecKatie SecKatie commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

📝 Description of the Change

Adds Forgejo to the CLI webhook setup path used by tkn pac create repo and tkn pac webhook add.

This PR:

  • adds forgejo to webhook provider selection and detection
  • creates Forgejo repository webhooks with the vendored Forgejo SDK
  • configures the Forgejo events PAC already handles: push, pull_request, and issue_comment
  • updates Forgejo docs with CLI setup and token requirements
Added Forgejo support to `tkn pac create repo` and `tkn pac webhook add`.

🔗 Linked GitHub Issue

Fixes #2755

🧪 Testing Strategy

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

Ran:

make check

🤖 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.

Used AI assistance to help implement the Forgejo CLI webhook setup, tests, docs, and PR preparation. I reviewed the generated code and ran the local checks listed above.

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 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 How to write a git commit message guide. The Gitlint linter ensures in CI it is properly validated
  • ✨ I have ensured my commit message prefix, for example fix: or 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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 4, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: SecKatie / name: Katie Mulliken (2fe600d)

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

Copy link
Copy Markdown

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 adds support for configuring Forgejo webhooks via the CLI, including updated documentation, a new forgejoConfig implementation, and corresponding unit tests. Feedback points out that parsing SSH repository URLs in forgejoInstanceURL can cause an error that blocks the setup process, and suggests ignoring the error to gracefully fall back to an empty default URL.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/cli/webhook/forgejo.go Outdated
@SecKatie SecKatie force-pushed the issue-2755-forgejo-cli-webhook branch from 2fe600d to ffd287b Compare June 5, 2026 01:03
Comment thread pkg/cli/webhook/forgejo.go Outdated
@theakshaypant

Copy link
Copy Markdown
Member

/ok-to-test

@SecKatie SecKatie force-pushed the issue-2755-forgejo-cli-webhook branch from ffd287b to d0cd587 Compare June 5, 2026 01:33
Comment thread pkg/cli/webhook/forgejo.go
Comment thread pkg/cli/webhook/forgejo_test.go Outdated
Comment thread pkg/cli/webhook/forgejo_test.go Outdated
Comment thread pkg/cli/webhook/webhook.go
Comment thread pkg/cli/webhook/forgejo.go Outdated
@SecKatie SecKatie force-pushed the issue-2755-forgejo-cli-webhook branch 4 times, most recently from 4eef949 to a6e6012 Compare June 5, 2026 17:37
@theakshaypant

Copy link
Copy Markdown
Member

/ok-to-test

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.23%. Comparing base (27ac5d7) to head (d8fdce9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cli/webhook/forgejo.go 83.05% 10 Missing and 10 partials ⚠️
pkg/cli/webhook/webhook.go 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2764      +/-   ##
==========================================
+ Coverage   61.01%   61.23%   +0.22%     
==========================================
  Files         211      212       +1     
  Lines       17228    17352     +124     
==========================================
+ Hits        10511    10626     +115     
+ Misses       5917     5916       -1     
- Partials      800      810      +10     
Flag Coverage Δ
unit-tests 61.23% <81.60%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@SecKatie SecKatie force-pushed the issue-2755-forgejo-cli-webhook branch from a6e6012 to 9e5f6dd Compare June 14, 2026 02:48
@SecKatie

Copy link
Copy Markdown
Contributor Author

Updated the unit tests to cover more branches.

@zakisk

zakisk commented Jun 14, 2026

Copy link
Copy Markdown
Member

@SecKatie E2E tests has some issues this they are failing always. We will fix and do review it. Thanks

Comment thread docs/content/docs/providers/forgejo.md Outdated
Comment thread pkg/cli/webhook/forgejo.go Outdated
Comment thread pkg/cli/webhook/forgejo.go
@chmouel chmouel force-pushed the issue-2755-forgejo-cli-webhook branch from 9e5f6dd to e4816ab Compare July 1, 2026 13:44
@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

@SecKatie hope you don't mind but to speed up the merge of this PR I have amended your commit and force-pushed the reviewed changes in commit e4816ab to your PR (adding myself as co-author).

Summary:

  • corrected the Forgejo webhook event set by using pull_request_only for opened, reopened, and closed pull requests while keeping sync and label events explicit;
  • made repository parsing handle .git, trailing slashes, Forgejo instance subpaths, and SSH-style URLs without aborting manual setup;
  • documented why repository and issue write permissions are required and clarified when the CLI creates the provider secret;
  • added regression coverage for the URL and event behavior; and
  • added Chmouel Boudjnah as a co-author while preserving Katie Mulliken as the commit author.

I also replied to and resolved the remaining review threads with the corresponding changes or rationale.

@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@chmouel chmouel requested a review from Copilot July 1, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Forgejo support to the CLI webhook setup flow (tkn pac create repo / tkn pac webhook add) by introducing a Forgejo-specific webhook installer, extending provider selection/detection, adding unit tests, and updating Forgejo provider documentation.

Changes:

  • Add forgejo to webhook provider selection/detection in the CLI flow.
  • Implement Forgejo webhook creation via the vendored Forgejo SDK.
  • Add unit tests for provider detection and Forgejo webhook setup logic; update Forgejo docs for CLI setup and token requirements.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/cli/webhook/webhook.go Adds forgejo as a supported provider option for CLI webhook setup and selection.
pkg/cli/webhook/webhook_test.go Adds unit tests for GetProviderName including Forgejo.
pkg/cli/webhook/forgejo.go Implements Forgejo CLI webhook configuration prompts and webhook creation via Forgejo SDK.
pkg/cli/webhook/forgejo_test.go Adds unit tests for Forgejo config prompting, instance URL parsing, webhook creation, and token usage.
docs/content/docs/providers/forgejo.md Documents CLI-based Forgejo webhook setup and required token access/scopes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cli/webhook/forgejo.go
Comment thread pkg/cli/webhook/forgejo_test.go Outdated
Comment thread pkg/cli/webhook/forgejo_test.go Outdated
@chmouel chmouel force-pushed the issue-2755-forgejo-cli-webhook branch from e4816ab to 9c235c6 Compare July 1, 2026 13:55
@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@chmouel chmouel force-pushed the issue-2755-forgejo-cli-webhook branch from 9c235c6 to 9934077 Compare July 1, 2026 14:15
@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

bitbucket error is unrelated and being fixed in #2819

cc @zakisk

jira: https://redhat.atlassian.net/browse/SRVKP-12240 fyi

@zakisk

zakisk commented Jul 1, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

/retest

@chmouel

chmouel commented Jul 1, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM!
Just need to confirm if we want to "retain" the gitea support while adding this CLI setup for forgejo

Comment thread pkg/cli/webhook/webhook.go Outdated
Comment thread pkg/cli/webhook/webhook.go
Add Forgejo to the webhook setup used by `tkn pac create repo` and
`tkn pac webhook add`. Create the repository webhook and store the
token and webhook secret for runtime use.

Handle repository URLs with `.git` suffixes, trailing slashes,
instance subpaths, and SSH forms without blocking manual setup. Use
the Forgejo event groups that cover push, pull request lifecycle,
sync, label, and comment events.

Document why each token permission is needed and clarify when the CLI
creates the provider secret.

Fixes tektoncd#2755.

Co-authored-by: Chmouel Boudjnah <chmouel@redhat.com>
Signed-off-by: Katie Mulliken <mulliken@redhat.com>
@chmouel chmouel force-pushed the issue-2755-forgejo-cli-webhook branch from 61330ed to d8fdce9 Compare July 6, 2026 09:18
@chmouel

chmouel commented Jul 6, 2026

Copy link
Copy Markdown
Member

✅ Manual validation report (kind cluster) — Forgejo CLI setup

I ran a full end-to-end manual validation of this PR on a live kind environment using the PR tkn-pac binary built from this branch.

Environment

  • Kubernetes context: kind cluster
  • PAC namespace: pipelines-as-code
  • Test namespace: sample
  • Public Forgejo endpoint and PAC ingress route configured and reachable

Flows validated

  1. tkn pac webhook add -n sample sample
  • Provider selected at prompt: forgejo
  • Alias-path repository URL scenario exercised
  • Result: webhook created on Forgejo and Kubernetes secret updated successfully.
  1. tkn pac create repo -n sample --name <repo> --url <forgejo-repo-url>
  • Provider selected at prompt: forgejo
  • Result: Repository CR created, webhook created, secret created, CR updated with webhook secret.
  • Verified secret keys: provider.token, webhook.secret.
  1. tkn pac webhook update-token -n sample sample
  • Result: provider token rotation succeeded (Secret sample updated).
  1. Runtime trigger validation (webhook event → PAC reconciliation → PipelineRun)
  • Triggered repo events and confirmed PAC processed them.
  • Verified PipelineRun creation in sample.
  • Verified SCM status reporting path (in_progress) after correcting token scopes.

Issue found during validation (environment/config), then resolved

  • Initial webhook add attempt failed because spec.git_provider.url in the Repository CR pointed to an internal in-cluster host not resolvable from the CLI host.
  • Patched the CR to the public Forgejo endpoint; rerun succeeded.
  • Also saw expected scope error (write:issue) until token scopes were corrected; after updating token, status creation succeeded.

Confidence for merge

High confidence this PR is ready to merge.

The CLI enhancement works interactively in real conditions across all targeted flows (create repo, webhook add, update-token, runtime trigger), and the gitea.* alias usage with forgejo selection was exercised successfully.

@chmouel

chmouel commented Jul 6, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@chmouel chmouel merged commit 1433ee8 into tektoncd:main Jul 6, 2026
18 of 27 checks passed
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.

Ask: support Forgejo in tkn pac create repo and webhook add

6 participants