mirror of
https://github.com/bapung/gitea-runner-operator.git
synced 2026-06-21 15:38:42 +00:00
Merge pull request #4 from bapung/fix/repo-scope-for-user
fix: handle case if owner is a user, take priority over org
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user