mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-21 09:06:46 +09:00
Secret and variable functions took an adjacent `ownerID, repoID int64` pair, so swapping the two compiled and only failed at runtime. They now take a `BelongingScope` value instead. `BelongingScope` also replaces the "drop OwnerID when RepoID is set" step that `InsertEncryptedSecret` and `InsertVariable` each implemented separately No behaviour change. It also makes adding another scope dimension, such as the environment ID in https://github.com/go-gitea/gitea/pull/38149, a one-field change. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Zettat123 <zettat123@gmail.com>
29 lines
886 B
Go
29 lines
886 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
// BelongingScope identifies the owner (user/org) or repository an Actions secret or variable belongs to.
|
|
// Both zero values mean "global scope".
|
|
// Always use the functions to create a BelongingScope, rather than creating one directly, to avoid accidentally creating an invalid scope.
|
|
type BelongingScope struct {
|
|
internalOwnerID int64
|
|
internalRepoID int64
|
|
}
|
|
|
|
func BelongingScopeOwner(ownerID int64) BelongingScope {
|
|
return BelongingScope{internalOwnerID: ownerID}
|
|
}
|
|
|
|
func BelongingScopeRepo(repoID int64) BelongingScope {
|
|
return BelongingScope{internalRepoID: repoID}
|
|
}
|
|
|
|
func BelongingScopeGlobal() BelongingScope {
|
|
return BelongingScope{}
|
|
}
|
|
|
|
func (scope BelongingScope) GetOwnerRepoIDs() (ownerID, repoID int64) {
|
|
return scope.internalOwnerID, scope.internalRepoID
|
|
}
|