Skip to content

Commit 3d270ec

Browse files
authored
Merge branch 'main' into bugfix/runner_delete
2 parents eacdea5 + c422f17 commit 3d270ec

File tree

31 files changed

+2346
-379
lines changed

31 files changed

+2346
-379
lines changed

models/actions/variable.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,23 @@ func InsertVariable(ctx context.Context, ownerID, repoID int64, name, data strin
5858

5959
type FindVariablesOpts struct {
6060
db.ListOptions
61+
IDs []int64
6162
RepoID int64
6263
OwnerID int64 // it will be ignored if RepoID is set
6364
Name string
6465
}
6566

6667
func (opts FindVariablesOpts) ToConds() builder.Cond {
6768
cond := builder.NewCond()
69+
70+
if len(opts.IDs) > 0 {
71+
if len(opts.IDs) == 1 {
72+
cond = cond.And(builder.Eq{"id": opts.IDs[0]})
73+
} else {
74+
cond = cond.And(builder.In("id", opts.IDs))
75+
}
76+
}
77+
6878
// Since we now support instance-level variables,
6979
// there is no need to check for null values for `owner_id` and `repo_id`
7080
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
@@ -85,12 +95,12 @@ func FindVariables(ctx context.Context, opts FindVariablesOpts) ([]*ActionVariab
8595
return db.Find[ActionVariable](ctx, opts)
8696
}
8797

88-
func UpdateVariable(ctx context.Context, variable *ActionVariable) (bool, error) {
89-
count, err := db.GetEngine(ctx).ID(variable.ID).Cols("name", "data").
90-
Update(&ActionVariable{
91-
Name: variable.Name,
92-
Data: variable.Data,
93-
})
98+
func UpdateVariableCols(ctx context.Context, variable *ActionVariable, cols ...string) (bool, error) {
99+
variable.Name = strings.ToUpper(variable.Name)
100+
count, err := db.GetEngine(ctx).
101+
ID(variable.ID).
102+
Cols(cols...).
103+
Update(variable)
94104
return count != 0, err
95105
}
96106

models/issues/issue.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
user_model "code.gitea.io/gitea/models/user"
1818
"code.gitea.io/gitea/modules/container"
1919
"code.gitea.io/gitea/modules/log"
20+
"code.gitea.io/gitea/modules/optional"
2021
"code.gitea.io/gitea/modules/setting"
2122
api "code.gitea.io/gitea/modules/structs"
2223
"code.gitea.io/gitea/modules/timeutil"
@@ -501,6 +502,45 @@ func GetIssueByIndex(ctx context.Context, repoID, index int64) (*Issue, error) {
501502
return issue, nil
502503
}
503504

505+
func isPullToCond(isPull optional.Option[bool]) builder.Cond {
506+
if isPull.Has() {
507+
return builder.Eq{"is_pull": isPull.Value()}
508+
}
509+
return builder.NewCond()
510+
}
511+
512+
func FindLatestUpdatedIssues(ctx context.Context, repoID int64, isPull optional.Option[bool], pageSize int) (IssueList, error) {
513+
issues := make([]*Issue, 0, pageSize)
514+
err := db.GetEngine(ctx).Where("repo_id = ?", repoID).
515+
And(isPullToCond(isPull)).
516+
OrderBy("updated_unix DESC").
517+
Limit(pageSize).
518+
Find(&issues)
519+
return issues, err
520+
}
521+
522+
func FindIssuesSuggestionByKeyword(ctx context.Context, repoID int64, keyword string, isPull optional.Option[bool], excludedID int64, pageSize int) (IssueList, error) {
523+
cond := builder.NewCond()
524+
if excludedID > 0 {
525+
cond = cond.And(builder.Neq{"`id`": excludedID})
526+
}
527+
528+
// It seems that GitHub searches both title and content (maybe sorting by the search engine's ranking system?)
529+
// The first PR (https://github.com/go-gitea/gitea/pull/32327) uses "search indexer" to search "name(title) + content"
530+
// But it seems that searching "content" (especially LIKE by DB engine) generates worse (unusable) results.
531+
// So now (https://github.com/go-gitea/gitea/pull/33538) it only searches "name(title)", leave the improvements to the future.
532+
cond = cond.And(db.BuildCaseInsensitiveLike("`name`", keyword))
533+
534+
issues := make([]*Issue, 0, pageSize)
535+
err := db.GetEngine(ctx).Where("repo_id = ?", repoID).
536+
And(isPullToCond(isPull)).
537+
And(cond).
538+
OrderBy("updated_unix DESC, `index` DESC").
539+
Limit(pageSize).
540+
Find(&issues)
541+
return issues, err
542+
}
543+
504544
// GetIssueWithAttrsByIndex returns issue by index in a repository.
505545
func GetIssueWithAttrsByIndex(ctx context.Context, repoID, index int64) (*Issue, error) {
506546
issue, err := GetIssueByIndex(ctx, repoID, index)

modules/structs/repo_actions.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,36 @@ type ActionTaskResponse struct {
3232
Entries []*ActionTask `json:"workflow_runs"`
3333
TotalCount int64 `json:"total_count"`
3434
}
35+
36+
// CreateActionWorkflowDispatch represents the payload for triggering a workflow dispatch event
37+
// swagger:model
38+
type CreateActionWorkflowDispatch struct {
39+
// required: true
40+
// example: refs/heads/main
41+
Ref string `json:"ref" binding:"Required"`
42+
// required: false
43+
Inputs map[string]string `json:"inputs,omitempty"`
44+
}
45+
46+
// ActionWorkflow represents a ActionWorkflow
47+
type ActionWorkflow struct {
48+
ID string `json:"id"`
49+
Name string `json:"name"`
50+
Path string `json:"path"`
51+
State string `json:"state"`
52+
// swagger:strfmt date-time
53+
CreatedAt time.Time `json:"created_at"`
54+
// swagger:strfmt date-time
55+
UpdatedAt time.Time `json:"updated_at"`
56+
URL string `json:"url"`
57+
HTMLURL string `json:"html_url"`
58+
BadgeURL string `json:"badge_url"`
59+
// swagger:strfmt date-time
60+
DeletedAt time.Time `json:"deleted_at,omitempty"`
61+
}
62+
63+
// ActionWorkflowResponse returns a ActionWorkflow
64+
type ActionWorkflowResponse struct {
65+
Workflows []*ActionWorkflow `json:"workflows"`
66+
TotalCount int64 `json:"total_count"`
67+
}

modules/util/error.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ func (w SilentWrap) Unwrap() error {
3636
return w.Err
3737
}
3838

39+
type LocaleWrap struct {
40+
err error
41+
TrKey string
42+
TrArgs []any
43+
}
44+
45+
// Error returns the message
46+
func (w LocaleWrap) Error() string {
47+
return w.err.Error()
48+
}
49+
50+
// Unwrap returns the underlying error
51+
func (w LocaleWrap) Unwrap() error {
52+
return w.err
53+
}
54+
3955
// NewSilentWrapErrorf returns an error that formats as the given text but unwraps as the provided error
4056
func NewSilentWrapErrorf(unwrap error, message string, args ...any) error {
4157
if len(args) == 0 {
@@ -63,3 +79,16 @@ func NewAlreadyExistErrorf(message string, args ...any) error {
6379
func NewNotExistErrorf(message string, args ...any) error {
6480
return NewSilentWrapErrorf(ErrNotExist, message, args...)
6581
}
82+
83+
// ErrWrapLocale wraps an err with a translation key and arguments
84+
func ErrWrapLocale(err error, trKey string, trArgs ...any) error {
85+
return LocaleWrap{err: err, TrKey: trKey, TrArgs: trArgs}
86+
}
87+
88+
func ErrAsLocale(err error) *LocaleWrap {
89+
var e LocaleWrap
90+
if errors.As(err, &e) {
91+
return &e
92+
}
93+
return nil
94+
}

options/locale/locale_en-US.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ show_only_public = Showing only public
385385

386386
issues.in_your_repos = In your repositories
387387

388+
guide_title = No Activity
389+
guide_desc = You are currently not following any repositories or users, so there is no content to display. You can explore repositories or users of interest from the links below.
390+
explore_repos = Explore repositories
391+
explore_users = Explore users
392+
empty_org = There are no organizations yet.
393+
empty_repo = There are no repositories yet.
394+
388395
[explore]
389396
repos = Repositories
390397
users = Users

routers/api/v1/api.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,11 +1155,17 @@ func Routes() *web.Router {
11551155
m.Post("/accept", repo.AcceptTransfer)
11561156
m.Post("/reject", repo.RejectTransfer)
11571157
}, reqToken())
1158-
addActionsRoutes(
1159-
m,
1160-
reqOwner(),
1161-
repo.NewAction(),
1162-
)
1158+
1159+
addActionsRoutes(m, reqOwner(), repo.NewAction()) // it adds the routes for secrets/variables and runner management
1160+
1161+
m.Group("/actions/workflows", func() {
1162+
m.Get("", repo.ActionsListRepositoryWorkflows)
1163+
m.Get("/{workflow_id}", repo.ActionsGetWorkflow)
1164+
m.Put("/{workflow_id}/disable", reqRepoWriter(unit.TypeActions), repo.ActionsDisableWorkflow)
1165+
m.Put("/{workflow_id}/enable", reqRepoWriter(unit.TypeActions), repo.ActionsEnableWorkflow)
1166+
m.Post("/{workflow_id}/dispatches", reqRepoWriter(unit.TypeActions), bind(api.CreateActionWorkflowDispatch{}), repo.ActionsDispatchWorkflow)
1167+
}, context.ReferencesGitRepo(), reqToken(), reqRepoReader(unit.TypeActions))
1168+
11631169
m.Group("/hooks/git", func() {
11641170
m.Combo("").Get(repo.ListGitHooks)
11651171
m.Group("/{id}", func() {

routers/api/v1/org/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,11 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
450450
if opt.Name == "" {
451451
opt.Name = ctx.PathParam("variablename")
452452
}
453-
if _, err := actions_service.UpdateVariable(ctx, v.ID, opt.Name, opt.Value); err != nil {
453+
454+
v.Name = opt.Name
455+
v.Data = opt.Value
456+
457+
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
454458
if errors.Is(err, util.ErrInvalidArgument) {
455459
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
456460
} else {

0 commit comments

Comments
 (0)