Skip to content

feat: Gitea pull request label support#6101

Open
gnanirahulnutakki wants to merge 2 commits intoakuity:mainfrom
gnanirahulnutakki:codengr/oss-kargo-6021
Open

feat: Gitea pull request label support#6101
gnanirahulnutakki wants to merge 2 commits intoakuity:mainfrom
gnanirahulnutakki:codengr/oss-kargo-6021

Conversation

@gnanirahulnutakki
Copy link
Copy Markdown

@gnanirahulnutakki gnanirahulnutakki commented Apr 16, 2026

Fixes #6021

Summary

  • resolve configured Gitea label names to repository label IDs ( with pagination support ) before creating the PR
  • add regression coverage for both the successful label pagination path and missing-label validation

Testing

  • go test ./pkg/gitprovider/gitea
  • ./hack/bin/golangci-lint run --config .golangci.yaml ./pkg/gitprovider/gitea/...

Signed-off-by: Gnani Rahul <gnutakki@radiantlogic.com>
@gnanirahulnutakki gnanirahulnutakki requested a review from a team as a code owner April 16, 2026 06:18
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 16, 2026

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit fa8ec91
🔍 Latest deploy log https://app.netlify.com/projects/docs-kargo-io/deploys/69e2925f629a990008dd7b9c
😎 Deploy Preview https://deploy-preview-6101.docs.kargo.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gnanirahulnutakki gnanirahulnutakki changed the title Fix Gitea pull request label support fix: restore Gitea pull request label support Apr 16, 2026
Comment thread pkg/gitprovider/gitea/gitea.go Outdated
Comment on lines +192 to +199
repoLabels, _, err := p.client.ListRepoLabels(
p.owner,
p.repo,
gitea.ListLabelsOptions{},
)
if err != nil {
return nil, fmt.Errorf("error listing repository labels: %w", err)
}
Copy link
Copy Markdown
Member

@fuskovic fuskovic Apr 17, 2026

Choose a reason for hiding this comment

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

ListRepoLabels is called with an empty gitea.ListLabelsOptions{}, which uses Gitea's default page size https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.20.0/gitea/list_options.go#L19.

If a repository has more labels than the default, the function will not see them and will incorrectly report them as missing.

One solution for making sure we are listing all labels here could be incrementing opts.Page in a loop until the response is empty.

I'd like to see a test for this too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Paged label lookup now walks ListRepoLabels using Response.NextPage until exhaustion instead of assuming the first page contains every repository label. I added regression coverage for a label that only appears on a later page so this does not silently regress.

Comment thread pkg/gitprovider/gitea/gitea.go Outdated
Comment on lines +169 to +182
if len(labelIDs) > 0 {
if _, _, err := p.client.AddIssueLabels(
p.owner,
p.repo,
giteaPR.Index,
gitea.IssueLabelsOption{Labels: labelIDs},
); err != nil {
return nil, fmt.Errorf(
"error adding labels to pull request %d: %w",
giteaPR.Index,
err,
)
}
}
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.

So if we get here it means we successfully created a PR but because we failed to add labels we report an error.

We could improve the error here e.g. successfully created pr number %d but failed to add labels: %w.

Although, I think a better solution would be to not have this be a separate call at all.

It looks like CreatePullRequestOption has a Labels field: https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.20.0/gitea/pull.go#L159 and since you already resolve labelIDs before the CreatePullRequest call it makes more sense to just add your labelIDs there.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The separate AddIssueLabels call is gone. Resolved label IDs are now passed directly in CreatePullRequestOption.Labels, so label application stays part of PR creation instead of becoming a second failure point after the PR already exists. The updated test asserts that path, and I also validated it end-to-end against a live OrbStack-backed Gitea instance with a real paginated label set.

@fuskovic fuskovic added area/controller Affects the (main) controller area/external-providers Related to external API providers kind/enhancement An entirely new feature priority/low Low commitment from maintainers; progress is likely to be community-driven and removed area/controller Affects the (main) controller labels Apr 17, 2026
Signed-off-by: Gnani Rahul <gnutakki@radiantlogic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 88.23529% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.47%. Comparing base (f24bf4d) to head (fa8ec91).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/gitprovider/gitea/gitea.go 88.23% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6101      +/-   ##
==========================================
+ Coverage   57.44%   57.47%   +0.03%     
==========================================
  Files         474      474              
  Lines       40230    40277      +47     
==========================================
+ Hits        23110    23151      +41     
- Misses      15745    15748       +3     
- Partials     1375     1378       +3     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fuskovic fuskovic changed the title fix: restore Gitea pull request label support feat: Gitea pull request label support Apr 20, 2026
@fuskovic fuskovic added this pull request to the merge queue Apr 20, 2026
@fuskovic fuskovic removed this pull request from the merge queue due to a manual request Apr 20, 2026
Comment on lines +191 to +197
labelIDsByName := make(map[string]int64, len(repoLabels))
for _, repoLabel := range repoLabels {
if repoLabel == nil {
continue
}
labelIDsByName[repoLabel.Name] = repoLabel.ID
}
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.

This loop is unnecessary — you can build the map directly inside the pagination loop, eliminating the intermediate repoLabels slice entirely.

@krancour krancour added this to the v1.11.0 milestone Apr 20, 2026
@krancour krancour added the area/controller Affects the (main) controller label Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/controller Affects the (main) controller area/external-providers Related to external API providers kind/enhancement An entirely new feature priority/low Low commitment from maintainers; progress is likely to be community-driven

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add gitea label support

3 participants