fix: handle case if owner is a user, take priority over org

This commit is contained in:
2026-01-13 21:28:33 +08:00
parent 6298940adb
commit e6755bf2ba
2 changed files with 24 additions and 2 deletions

View File

@@ -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)

View File

@@ -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: