Skip to content

Commit 7ab099a

Browse files
committed
add comments on expected behavior
1 parent 0c222f8 commit 7ab099a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

models/actions/runner.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func (r *ActionRunner) IsOnline() bool {
124124
}
125125

126126
// Editable checks if the runner is editable by the user
127+
// ownerID == 0 and repoID == 0 means any runner including global runners
128+
// ownerID == 0 and repoID != 0 means any runner for the given repo
129+
// ownerID != 0 and repoID == 0 means any runner for the given user/org
130+
// ownerID != 0 and repoID != 0 means any runner for the given user/org or repo
127131
func (r *ActionRunner) Editable(ownerID, repoID int64) bool {
128132
if ownerID == 0 && repoID == 0 {
129133
return true
@@ -168,6 +172,10 @@ func init() {
168172
db.RegisterModel(&ActionRunner{})
169173
}
170174

175+
// FindRunnerOptions
176+
// ownerID == 0 and repoID == 0 means any runner including global runners
177+
// repoID != 0 means any runner for the given repo
178+
// ownerID != 0 and repoID == 0 means any runner for the given user/org
171179
type FindRunnerOptions struct {
172180
db.ListOptions
173181
IDs []int64

routers/api/v1/shared/runners.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
3535
ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token})
3636
}
3737

38+
// List Runners for api route validated ownerID and repoID
39+
// ownerID == 0 and repoID == 0 means all runners including global runners, does not appear in sql where clause
40+
// ownerID == 0 and repoID != 0 means all runners for the given repo
41+
// ownerID != 0 and repoID == 0 means all runners for the given user/org
42+
// ownerID != 0 and repoID != 0 undefined behavior
43+
// Access rights are checked at the API route level
3844
func ListRunners(ctx *context.APIContext, ownerID, repoID int64) {
3945
runners, total, err := db.FindAndCount[actions_model.ActionRunner](ctx, &actions_model.FindRunnerOptions{
4046
OwnerID: ownerID,
@@ -57,6 +63,12 @@ func ListRunners(ctx *context.APIContext, ownerID, repoID int64) {
5763
ctx.JSON(http.StatusOK, &res)
5864
}
5965

66+
// Get Runners for api route validated ownerID and repoID
67+
// ownerID == 0 and repoID == 0 means any runner including global runners
68+
// ownerID == 0 and repoID != 0 means any runner for the given repo
69+
// ownerID != 0 and repoID == 0 means any runner for the given user/org
70+
// ownerID != 0 and repoID != 0 undefined behavior
71+
// Access rights are checked at the API route level
6072
func GetRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
6173
runner, err := actions_model.GetRunnerByID(ctx, runnerID)
6274
if err != nil {
@@ -70,6 +82,12 @@ func GetRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
7082
ctx.JSON(http.StatusOK, convert.ToActionRunner(ctx, runner))
7183
}
7284

85+
// Delete Runner for api route validated ownerID and repoID
86+
// ownerID == 0 and repoID == 0 means any runner including global runners
87+
// ownerID == 0 and repoID != 0 means any runner for the given repo
88+
// ownerID != 0 and repoID == 0 means any runner for the given user/org
89+
// ownerID != 0 and repoID != 0 undefined behavior
90+
// Access rights are checked at the API route level
7391
func DeleteRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
7492
runner, err := actions_model.GetRunnerByID(ctx, runnerID)
7593
if err != nil {

0 commit comments

Comments
 (0)