refactor: rename to actions

This commit is contained in:
Jason Song
2022-12-06 15:16:25 +08:00
parent 56368f3963
commit 223782ca4c
50 changed files with 247 additions and 247 deletions

View File

@@ -51,7 +51,7 @@ func init() {
}
func (run *ActionRun) HTMLURL() string {
return fmt.Sprintf("%s/bots/runs/%d", run.Repo.HTMLURL(), run.Index)
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.HTMLURL(), run.Index)
}
// LoadAttributes load Repo TriggerUser if not loaded
@@ -108,11 +108,11 @@ func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
_, err := db.GetEngine(ctx).ID(repo.ID).
SetExpr("num_runs",
builder.Select("count(*)").From("bot_run").
builder.Select("count(*)").From("action_run").
Where(builder.Eq{"repo_id": repo.ID}),
).
SetExpr("num_closed_runs",
builder.Select("count(*)").From("bot_run").
builder.Select("count(*)").From("action_run").
Where(builder.Eq{
"repo_id": repo.ID,
}.And(
@@ -129,7 +129,7 @@ func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) err
return err
}
// InsertRun inserts a bot run
// InsertRun inserts a run
func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWorkflow) error {
ctx, commiter, err := db.TxContext(ctx)
if err != nil {
@@ -137,7 +137,7 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
}
defer commiter.Close()
index, err := db.GetNextResourceIndex(ctx, "bot_run_index", run.RepoID)
index, err := db.GetNextResourceIndex(ctx, "action_run_index", run.RepoID)
if err != nil {
return err
}

View File

@@ -48,8 +48,8 @@ func (runs RunList) LoadTriggerUser(ctx context.Context) error {
return err
}
for _, run := range runs {
if run.TriggerUserID == user_model.BotUserID {
run.TriggerUser = user_model.NewBotUser()
if run.TriggerUserID == user_model.ActionsUserID {
run.TriggerUser = user_model.NewActionsUser()
} else {
run.TriggerUser = users[run.TriggerUserID]
}

View File

@@ -197,7 +197,7 @@ func FindRunners(ctx context.Context, opts FindRunnerOptions) (runners RunnerLis
return runners, sess.Find(&runners)
}
// GetRunnerByUUID returns a bot runner via uuid
// GetRunnerByUUID returns a runner via uuid
func GetRunnerByUUID(ctx context.Context, uuid string) (*ActionRunner, error) {
var runner ActionRunner
has, err := db.GetEngine(ctx).Where("uuid=?", uuid).Get(&runner)
@@ -209,7 +209,7 @@ func GetRunnerByUUID(ctx context.Context, uuid string) (*ActionRunner, error) {
return &runner, nil
}
// GetRunnerByID returns a bot runner via id
// GetRunnerByID returns a runner via id
func GetRunnerByID(ctx context.Context, id int64) (*ActionRunner, error) {
var runner ActionRunner
has, err := db.GetEngine(ctx).Where("id=?", id).Get(&runner)

View File

@@ -33,7 +33,7 @@ func init() {
db.RegisterModel(new(ActionRunnerToken))
}
// GetRunnerToken returns a bot runner via token
// GetRunnerToken returns a action runner via token
func GetRunnerToken(ctx context.Context, token string) (*ActionRunnerToken, error) {
var runnerToken ActionRunnerToken
has, err := db.GetEngine(ctx).Where("token=?", token).Get(&runnerToken)

View File

@@ -117,7 +117,7 @@ func (task *ActionTask) GetBuildViewLink() string {
if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil {
return ""
}
return task.Job.Run.Repo.Link() + "/bots/runs/" + strconv.FormatInt(task.ID, 10)
return task.Job.Run.Repo.Link() + "/actions/runs/" + strconv.FormatInt(task.ID, 10)
}
func (task *ActionTask) GetCommitLink() string {
@@ -265,7 +265,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
jobCond = builder.In("repo_id", builder.Select("id").From("repository").Where(builder.Eq{"owner_id": runner.OwnerID}))
}
if jobCond.IsValid() {
jobCond = builder.In("run_id", builder.Select("id").From("bot_run").Where(jobCond))
jobCond = builder.In("run_id", builder.Select("id").From("action_run").Where(jobCond))
}
var jobs []*ActionRunJob

View File

@@ -35,8 +35,8 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
}
for _, comment := range comments {
if comment.PosterID == user_model.BotUserID {
comment.Poster = user_model.NewBotUser()
if comment.PosterID == user_model.ActionsUserID {
comment.Poster = user_model.NewActionsUser()
} else if comment.PosterID <= 0 {
continue
} else {

View File

@@ -92,8 +92,8 @@ func (issues IssueList) loadPosters(ctx context.Context) error {
}
for _, issue := range issues {
if issue.PosterID == user_model.BotUserID {
issue.Poster = user_model.NewBotUser()
if issue.PosterID == user_model.ActionsUserID {
issue.Poster = user_model.NewActionsUser()
} else if issue.PosterID <= 0 {
continue
} else {

View File

@@ -444,7 +444,7 @@ var migrations = []Migration{
NewMigration("Add index for access_token", v1_19.AddIndexForAccessToken),
// in dev
NewMigration("Add bots tables", addBotTables),
NewMigration("Add actions tables", addActionsTables),
}
// GetCurrentDBVersion returns the current db version

View File

@@ -10,8 +10,8 @@ import (
"xorm.io/xorm"
)
func addBotTables(x *xorm.Engine) error {
type BotRunner struct {
func addActionsTables(x *xorm.Engine) error {
type ActionRunner struct {
ID int64
UUID string `xorm:"CHAR(36) UNIQUE"`
Name string `xorm:"VARCHAR(32)"`
@@ -39,7 +39,7 @@ func addBotTables(x *xorm.Engine) error {
Deleted timeutil.TimeStamp `xorm:"deleted"`
}
type BotRunnerToken struct {
type ActionRunnerToken struct {
ID int64
Token string `xorm:"UNIQUE"`
OwnerID int64 `xorm:"index"` // org level runner, 0 means system
@@ -51,7 +51,7 @@ func addBotTables(x *xorm.Engine) error {
Deleted timeutil.TimeStamp `xorm:"deleted"`
}
type BotRun struct {
type ActionRun struct {
ID int64
Title string
RepoID int64 `xorm:"index unique(repo_index)"`
@@ -71,7 +71,7 @@ func addBotTables(x *xorm.Engine) error {
Updated timeutil.TimeStamp `xorm:"updated"`
}
type BotRunJob struct {
type ActionRunJob struct {
ID int64
RunID int64 `xorm:"index"`
RepoID int64 `xorm:"index"`
@@ -97,9 +97,9 @@ func addBotTables(x *xorm.Engine) error {
NumClosedRuns int `xorm:"NOT NULL DEFAULT 0"`
}
type BotRunIndex db.ResourceIndex
type ActionRunIndex db.ResourceIndex
type BotTask struct {
type ActionTask struct {
ID int64
JobID int64
Attempt int64
@@ -128,7 +128,7 @@ func addBotTables(x *xorm.Engine) error {
Updated timeutil.TimeStamp `xorm:"updated index"`
}
type BotTaskStep struct {
type ActionTaskStep struct {
ID int64
Name string
TaskID int64 `xorm:"index unique(task_number)"`
@@ -162,14 +162,14 @@ func addBotTables(x *xorm.Engine) error {
}
return x.Sync(
new(BotRunner),
new(BotRunnerToken),
new(BotRun),
new(BotRunJob),
new(ActionRunner),
new(ActionRunnerToken),
new(ActionRun),
new(ActionRunJob),
new(Repository),
new(BotRunIndex),
new(BotTask),
new(BotTaskStep),
new(ActionRunIndex),
new(ActionTask),
new(ActionTaskStep),
new(dbfsMeta),
new(dbfsData),
)

View File

@@ -174,7 +174,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(PullRequestsConfig)
case unit.TypeIssues:
r.Config = new(IssuesConfig)
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages, unit.TypeBots:
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages, unit.TypeActions:
fallthrough
default:
r.Config = new(UnitConfig)

View File

@@ -27,7 +27,7 @@ const (
TypeExternalTracker // 7 ExternalTracker
TypeProjects // 8 Kanban board
TypePackages // 9 Packages
TypeBots // 10 Bots
TypeActions // 10 Actions
)
// Value returns integer value for unit type
@@ -55,8 +55,8 @@ func (u Type) String() string {
return "TypeProjects"
case TypePackages:
return "TypePackages"
case TypeBots:
return "TypeBots"
case TypeActions:
return "TypeActions"
}
return fmt.Sprintf("Unknown Type %d", u)
}
@@ -80,7 +80,7 @@ var (
TypeExternalTracker,
TypeProjects,
TypePackages,
TypeBots,
TypeActions,
}
// DefaultRepoUnits contains the default unit types
@@ -292,11 +292,11 @@ var (
perm.AccessModeRead,
}
UnitBots = Unit{
TypeBots,
"repo.bots",
"/bots",
"repo.bots.desc",
UnitActions = Unit{
TypeActions,
"repo.actions",
"/actions",
"repo.actions.desc",
7,
perm.AccessModeOwner,
}
@@ -312,7 +312,7 @@ var (
TypeExternalWiki: UnitExternalWiki,
TypeProjects: UnitProjects,
TypePackages: UnitPackages,
TypeBots: UnitBots,
TypeActions: UnitActions,
}
)

View File

@@ -104,7 +104,7 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
setting.Packages.Storage.Path = filepath.Join(setting.AppDataPath, "packages")
setting.Bots.Storage.Path = filepath.Join(setting.AppDataPath, "bots_log")
setting.Actions.Storage.Path = filepath.Join(setting.AppDataPath, "actions_log")
setting.Git.HomePath = filepath.Join(setting.AppDataPath, "home")

View File

@@ -983,8 +983,8 @@ func GetPossbileUserByID(ctx context.Context, id int64) (*User, error) {
switch id {
case -1:
return NewGhostUser(), nil
case BotUserID:
return NewBotUser(), nil
case ActionsUserID:
return NewActionsUser(), nil
case 0:
return nil, ErrUserNotExist{}
default:

View File

@@ -36,30 +36,30 @@ func NewReplaceUser(name string) *User {
}
const (
BotUserID = -2
BotUserName = "[robot]gitea-bots"
ActionsUserID = -2
ActionsUserName = "[bot]gitea-actions"
)
// NewBotUser creates and returns a fake user for running the build.
func NewBotUser() *User {
// NewActionsUser creates and returns a fake user for running the actions.
func NewActionsUser() *User {
return &User{
ID: BotUserID,
Name: "[robot]gitea-bots",
LowerName: "[robot]gitea-bots",
ID: ActionsUserID,
Name: ActionsUserName,
LowerName: ActionsUserName,
IsActive: true,
FullName: "Gitea Bots",
FullName: "Gitea Actions",
Email: "teabot@gitea.io",
KeepEmailPrivate: true,
LoginName: "[robot]gitea-bots",
LoginName: ActionsUserName,
Type: UserTypeIndividual,
AllowCreateOrganization: true,
Visibility: structs.VisibleTypePublic,
}
}
func (u *User) IsBots() bool {
func (u *User) IsActions() bool {
if u == nil {
return false
}
return u.ID == BotUserID && u.Name == BotUserName
return u.ID == ActionsUserID && u.Name == ActionsUserName
}