Skip to content

Commit 0b82431

Browse files
authored
Merge branch 'main' into lunny/fix_git_config_conflict
2 parents 661fa4f + c7b99c8 commit 0b82431

File tree

12 files changed

+573
-92
lines changed

12 files changed

+573
-92
lines changed

.github/workflows/release-nightly.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ jobs:
7575
- name: Get cleaned branch name
7676
id: clean_name
7777
run: |
78-
# if main then say nightly otherwise cleanup name
79-
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
80-
echo "branch=nightly" >> "$GITHUB_OUTPUT"
81-
exit 0
82-
fi
8378
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
8479
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
8580
- name: Login to Docker Hub
@@ -122,11 +117,6 @@ jobs:
122117
- name: Get cleaned branch name
123118
id: clean_name
124119
run: |
125-
# if main then say nightly otherwise cleanup name
126-
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
127-
echo "branch=nightly" >> "$GITHUB_OUTPUT"
128-
exit 0
129-
fi
130120
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
131121
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
132122
- name: Login to Docker Hub

routers/api/v1/repo/status.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
271271
}
272272
ctx.SetTotalCountHeader(count)
273273

274-
if len(statuses) == 0 {
275-
ctx.JSON(http.StatusOK, &api.CombinedStatus{})
276-
return
277-
}
278-
279-
combiStatus := convert.ToCombinedStatus(ctx, statuses, convert.ToRepo(ctx, repo, ctx.Repo.Permission))
274+
combiStatus := convert.ToCombinedStatus(ctx, refCommit.Commit.ID.String(), statuses,
275+
convert.ToRepo(ctx, repo, ctx.Repo.Permission))
280276
ctx.JSON(http.StatusOK, combiStatus)
281277
}

routers/web/admin/auths.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewAuthSource(ctx *context.Context) {
9797
ctx.Data["AuthSources"] = authSources
9898
ctx.Data["SecurityProtocols"] = securityProtocols
9999
ctx.Data["SMTPAuths"] = smtp.Authenticators
100-
oauth2providers := oauth2.GetSupportedOAuth2Providers()
100+
oauth2providers := oauth2.GetSupportedOAuth2ProvidersWithContext(ctx)
101101
ctx.Data["OAuth2Providers"] = oauth2providers
102102

103103
ctx.Data["SSPIAutoCreateUsers"] = true
@@ -107,7 +107,9 @@ func NewAuthSource(ctx *context.Context) {
107107
ctx.Data["SSPIDefaultLanguage"] = ""
108108

109109
// only the first as default
110-
ctx.Data["oauth2_provider"] = oauth2providers[0].Name()
110+
if len(oauth2providers) > 0 {
111+
ctx.Data["oauth2_provider"] = oauth2providers[0].Name()
112+
}
111113

112114
ctx.HTML(http.StatusOK, tplAuthNew)
113115
}
@@ -240,7 +242,7 @@ func NewAuthSourcePost(ctx *context.Context) {
240242
ctx.Data["AuthSources"] = authSources
241243
ctx.Data["SecurityProtocols"] = securityProtocols
242244
ctx.Data["SMTPAuths"] = smtp.Authenticators
243-
oauth2providers := oauth2.GetSupportedOAuth2Providers()
245+
oauth2providers := oauth2.GetSupportedOAuth2ProvidersWithContext(ctx)
244246
ctx.Data["OAuth2Providers"] = oauth2providers
245247

246248
ctx.Data["SSPIAutoCreateUsers"] = true

routers/web/feed/render.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ import (
88
)
99

1010
// RenderBranchFeed render format for branch or file
11-
func RenderBranchFeed(ctx *context.Context) {
12-
_, showFeedType := GetFeedType(ctx.PathParam("reponame"), ctx.Req)
11+
func RenderBranchFeed(ctx *context.Context, feedType string) {
1312
if ctx.Repo.TreePath == "" {
14-
ShowBranchFeed(ctx, ctx.Repo.Repository, showFeedType)
13+
ShowBranchFeed(ctx, ctx.Repo.Repository, feedType)
1514
} else {
16-
ShowFileFeed(ctx, ctx.Repo.Repository, showFeedType)
15+
ShowFileFeed(ctx, ctx.Repo.Repository, feedType)
1716
}
1817
}
18+
19+
func RenderBranchFeedRSS(ctx *context.Context) {
20+
RenderBranchFeed(ctx, "rss")
21+
}
22+
23+
func RenderBranchFeedAtom(ctx *context.Context) {
24+
RenderBranchFeed(ctx, "atom")
25+
}

routers/web/repo/actions/view.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ func Rerun(ctx *context_module.Context) {
429429
ctx.ServerError("UpdateRun", err)
430430
return
431431
}
432+
433+
if err := run.LoadAttributes(ctx); err != nil {
434+
ctx.ServerError("run.LoadAttributes", err)
435+
return
436+
}
437+
notify_service.WorkflowRunStatusUpdate(ctx, run.Repo, run.TriggerUser, run)
432438
}
433439

434440
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
@@ -485,7 +491,6 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
485491
}
486492

487493
actions_service.CreateCommitStatus(ctx, job)
488-
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
489494
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
490495

491496
return nil
@@ -560,9 +565,8 @@ func Cancel(ctx *context_module.Context) {
560565
if len(updatedjobs) > 0 {
561566
job := updatedjobs[0]
562567
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
563-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
564568
}
565-
ctx.JSON(http.StatusOK, struct{}{})
569+
ctx.JSONOK()
566570
}
567571

568572
func Approve(ctx *context_module.Context) {
@@ -606,15 +610,14 @@ func Approve(ctx *context_module.Context) {
606610
if len(updatedjobs) > 0 {
607611
job := updatedjobs[0]
608612
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
609-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
610613
}
611614

612615
for _, job := range updatedjobs {
613616
_ = job.LoadAttributes(ctx)
614617
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
615618
}
616619

617-
ctx.JSON(http.StatusOK, struct{}{})
620+
ctx.JSONOK()
618621
}
619622

620623
func Delete(ctx *context_module.Context) {

routers/web/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,8 @@ func registerWebRoutes(m *web.Router) {
16151615
m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, context.RepoRefByDefaultBranch(), repo.CherryPick)
16161616
}, repo.MustBeNotEmpty)
16171617

1618-
m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
1619-
m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
1618+
m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeedRSS)
1619+
m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeedAtom)
16201620

16211621
m.Group("/src", func() {
16221622
m.Get("", func(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink) }) // there is no "{owner}/{repo}/src" page, so redirect to "{owner}/{repo}" to avoid 404

services/actions/clear_tasks.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ func notifyWorkflowJobStatusUpdate(ctx context.Context, jobs []*actions_model.Ac
4242
_ = job.LoadAttributes(ctx)
4343
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
4444
}
45-
if len(jobs) > 0 {
46-
job := jobs[0]
47-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
48-
}
45+
job := jobs[0]
46+
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
4947
}
5048
}
5149

@@ -101,7 +99,7 @@ func stopTasks(ctx context.Context, opts actions_model.FindTaskOptions) error {
10199
return nil
102100
}
103101

104-
// CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time
102+
// CancelAbandonedJobs cancels jobs that have not been picked by any runner for a long time
105103
func CancelAbandonedJobs(ctx context.Context) error {
106104
jobs, err := db.Find[actions_model.ActionRunJob](ctx, actions_model.FindRunJobOptions{
107105
Statuses: []actions_model.Status{actions_model.StatusWaiting, actions_model.StatusBlocked},
@@ -113,24 +111,40 @@ func CancelAbandonedJobs(ctx context.Context) error {
113111
}
114112

115113
now := timeutil.TimeStampNow()
114+
115+
// Collect one job per run to send workflow run status update
116+
updatedRuns := map[int64]*actions_model.ActionRunJob{}
117+
116118
for _, job := range jobs {
117119
job.Status = actions_model.StatusCancelled
118120
job.Stopped = now
119121
updated := false
120122
if err := db.WithTx(ctx, func(ctx context.Context) error {
121123
n, err := actions_model.UpdateRunJob(ctx, job, nil, "status", "stopped")
122-
updated = err == nil && n > 0
123-
return err
124+
if err != nil {
125+
return err
126+
}
127+
if err := job.LoadAttributes(ctx); err != nil {
128+
return err
129+
}
130+
updated = n > 0
131+
if updated && job.Run.Status.IsDone() {
132+
updatedRuns[job.RunID] = job
133+
}
134+
return nil
124135
}); err != nil {
125136
log.Warn("cancel abandoned job %v: %v", job.ID, err)
126137
// go on
127138
}
128139
CreateCommitStatus(ctx, job)
129140
if updated {
130-
NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
131141
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
132142
}
133143
}
134144

145+
for _, job := range updatedRuns {
146+
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
147+
}
148+
135149
return nil
136150
}

services/auth/source/oauth2/providers.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"html"
1111
"html/template"
1212
"net/url"
13+
"slices"
1314
"sort"
1415

1516
"code.gitea.io/gitea/models/auth"
@@ -75,6 +76,10 @@ func (p *AuthSourceProvider) IconHTML(size int) template.HTML {
7576
// value is used to store display data
7677
var gothProviders = map[string]GothProvider{}
7778

79+
func isAzureProvider(name string) bool {
80+
return name == "azuread" || name == "microsoftonline" || name == "azureadv2"
81+
}
82+
7883
// RegisterGothProvider registers a GothProvider
7984
func RegisterGothProvider(provider GothProvider) {
8085
if _, has := gothProviders[provider.Name()]; has {
@@ -83,13 +88,47 @@ func RegisterGothProvider(provider GothProvider) {
8388
gothProviders[provider.Name()] = provider
8489
}
8590

91+
// getExistingAzureADAuthSources returns a list of Azure AD provider names that are already configured
92+
func getExistingAzureADAuthSources(ctx context.Context) ([]string, error) {
93+
authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
94+
LoginType: auth.OAuth2,
95+
})
96+
if err != nil {
97+
return nil, err
98+
}
99+
100+
var existingAzureProviders []string
101+
for _, source := range authSources {
102+
if oauth2Cfg, ok := source.Cfg.(*Source); ok {
103+
if isAzureProvider(oauth2Cfg.Provider) {
104+
existingAzureProviders = append(existingAzureProviders, oauth2Cfg.Provider)
105+
}
106+
}
107+
}
108+
return existingAzureProviders, nil
109+
}
110+
86111
// GetSupportedOAuth2Providers returns the map of unconfigured OAuth2 providers
87112
// key is used as technical name (like in the callbackURL)
88113
// values to display
114+
// Note: Azure AD providers (azuread, microsoftonline, azureadv2) are filtered out
115+
// unless they already exist in the system to encourage use of OpenID Connect
89116
func GetSupportedOAuth2Providers() []Provider {
117+
return GetSupportedOAuth2ProvidersWithContext(context.Background())
118+
}
119+
120+
// GetSupportedOAuth2ProvidersWithContext returns the list of supported OAuth2 providers with context for filtering
121+
func GetSupportedOAuth2ProvidersWithContext(ctx context.Context) []Provider {
90122
providers := make([]Provider, 0, len(gothProviders))
123+
existingAzureSources, err := getExistingAzureADAuthSources(ctx)
124+
if err != nil {
125+
log.Error("Failed to get existing OAuth2 auth sources: %v", err)
126+
}
91127

92128
for _, provider := range gothProviders {
129+
if isAzureProvider(provider.Name()) && !slices.Contains(existingAzureSources, provider.Name()) {
130+
continue
131+
}
93132
providers = append(providers, provider)
94133
}
95134
sort.Slice(providers, func(i, j int) bool {

services/convert/status.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,19 @@ func ToCommitStatuses(ctx context.Context, statuses []*git_model.CommitStatus) [
4242
}
4343

4444
// ToCombinedStatus converts List of CommitStatus to a CombinedStatus
45-
func ToCombinedStatus(ctx context.Context, statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus {
46-
if len(statuses) == 0 {
47-
return nil
45+
func ToCombinedStatus(ctx context.Context, commitID string, statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus {
46+
status := api.CombinedStatus{
47+
SHA: commitID,
48+
TotalCount: len(statuses),
49+
Repository: repo,
50+
CommitURL: repo.URL + "/commits/" + url.PathEscape(commitID),
51+
URL: repo.URL + "/commits/" + url.PathEscape(commitID) + "/status",
4852
}
4953

5054
combinedStatus := git_model.CalcCommitStatus(statuses)
51-
52-
return &api.CombinedStatus{
53-
State: combinedStatus.State,
54-
Statuses: ToCommitStatuses(ctx, statuses),
55-
SHA: combinedStatus.SHA,
56-
TotalCount: len(statuses),
57-
Repository: repo,
58-
CommitURL: repo.URL + "/commits/" + url.PathEscape(combinedStatus.SHA),
59-
URL: repo.URL + "/commits/" + url.PathEscape(combinedStatus.SHA) + "/status",
55+
if combinedStatus != nil {
56+
status.Statuses = ToCommitStatuses(ctx, statuses)
57+
status.State = combinedStatus.State
6058
}
59+
return &status
6160
}

0 commit comments

Comments
 (0)