From e6755bf2ba06d78fbd203b782005a9962fd09f6b Mon Sep 17 00:00:00 2001 From: Bapung Date: Tue, 13 Jan 2026 21:28:33 +0800 Subject: [PATCH] fix: handle case if owner is a user, take priority over org --- internal/gitea/client.go | 3 +++ internal/gitea/client_test.go | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/internal/gitea/client.go b/internal/gitea/client.go index 5bb9d0a..2400033 100644 --- a/internal/gitea/client.go +++ b/internal/gitea/client.go @@ -131,6 +131,9 @@ func (c *HTTPClient) GetRunnerStats( ) (*RunnerStats, error) { switch scope { case v1alpha1.RunnerGroupScopeRepo: + if user != "" { + return c.getRunnerStatsForRepo(ctx, giteaURL, authToken, user, repo, labels) + } return c.getRunnerStatsForRepo(ctx, giteaURL, authToken, org, repo, labels) case v1alpha1.RunnerGroupScopeOrg: return c.getRunnerStatsForOrg(ctx, giteaURL, authToken, org, labels) diff --git a/internal/gitea/client_test.go b/internal/gitea/client_test.go index 922f8a3..72bc269 100644 --- a/internal/gitea/client_test.go +++ b/internal/gitea/client_test.go @@ -80,6 +80,21 @@ func TestHTTPClient_GetRunnerStats(t *testing.T) { expectedQueued: 0, // No runner capabilities provided -> no match expectedError: false, }, + { + name: "repo scope (user owned)", + scope: v1alpha1.RunnerGroupScopeRepo, + user: "testuser", + repo: "testrepo", + labels: []string{"linux"}, + mockResponse: ActionWorkflowJobsResponse{ + TotalCount: 1, + Jobs: []ActionWorkflowJob{ + {ID: 1, Status: "queued", Labels: []string{"linux"}}, + }, + }, + expectedQueued: 1, + expectedError: false, + }, { name: "global scope with specific labels", scope: v1alpha1.RunnerGroupScopeGlobal, @@ -135,9 +150,13 @@ func TestHTTPClient_GetRunnerStats(t *testing.T) { expectedPath := "" switch tt.scope { case v1alpha1.RunnerGroupScopeRepo: - expectedPath = "/api/v1/repos/testorg/testrepo/actions/jobs" + owner := tt.org + if tt.user != "" { + owner = tt.user + } + expectedPath = "/api/v1/repos/" + owner + "/" + tt.repo + "/actions/jobs" case v1alpha1.RunnerGroupScopeOrg: - expectedPath = "/api/v1/orgs/testorg/actions/jobs" + expectedPath = "/api/v1/orgs/" + tt.org + "/actions/jobs" case v1alpha1.RunnerGroupScopeGlobal: expectedPath = "/api/v1/admin/actions/jobs" case v1alpha1.RunnerGroupScopeUser: