mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-23 13:16:31 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
This commit is contained in:
@@ -81,6 +81,7 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequest).
|
||||
WithDoer(doer).
|
||||
WithPayload(apiPullRequest).
|
||||
WithPullRequest(issue.PullRequest).
|
||||
Notify(ctx)
|
||||
return
|
||||
}
|
||||
@@ -136,6 +137,7 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
|
||||
Repository: convert.ToRepo(ctx, issue.Repo, perm_model.AccessModeNone),
|
||||
Sender: convert.ToUser(ctx, doer, nil),
|
||||
}).
|
||||
WithPullRequest(issue.PullRequest).
|
||||
Notify(ctx)
|
||||
return
|
||||
}
|
||||
@@ -160,6 +162,10 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
|
||||
mode, _ := access_model.AccessLevel(ctx, doer, repo)
|
||||
|
||||
if issue.IsPull {
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
log.Error("LoadPullRequest: %v", err)
|
||||
return
|
||||
}
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestComment).
|
||||
WithDoer(doer).
|
||||
WithPayload(&api.IssueCommentPayload{
|
||||
@@ -170,6 +176,7 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
|
||||
Sender: convert.ToUser(ctx, doer, nil),
|
||||
IsPull: true,
|
||||
}).
|
||||
WithPullRequest(issue.PullRequest).
|
||||
Notify(ctx)
|
||||
return
|
||||
}
|
||||
@@ -377,7 +384,7 @@ func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
|
||||
WithPayload(&api.CreatePayload{
|
||||
Ref: refFullName.ShortName(),
|
||||
Sha: refID,
|
||||
RefType: refFullName.RefGroup(),
|
||||
RefType: refFullName.RefType(),
|
||||
Repo: apiRepo,
|
||||
Sender: apiPusher,
|
||||
}).
|
||||
@@ -394,7 +401,7 @@ func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
|
||||
WithRef(refFullName.ShortName()). // FIXME: should we use a full ref name
|
||||
WithPayload(&api.DeletePayload{
|
||||
Ref: refFullName.ShortName(),
|
||||
RefType: refFullName.RefGroup(),
|
||||
RefType: refFullName.RefType(),
|
||||
PusherType: api.PusherTypeUser,
|
||||
Repo: apiRepo,
|
||||
Sender: apiPusher,
|
||||
|
||||
@@ -61,7 +61,7 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
|
||||
}
|
||||
|
||||
if !source.IsActive {
|
||||
return nil, nil, oauth2.ErrAuthSourceNotActived
|
||||
return nil, nil, oauth2.ErrAuthSourceNotActivated
|
||||
}
|
||||
|
||||
authenticator, ok := source.Cfg.(PasswordAuthenticator)
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
type Provider interface {
|
||||
Name() string
|
||||
DisplayName() string
|
||||
Image() string
|
||||
IconURL() string
|
||||
CustomURLSettings() *CustomURLSettings
|
||||
}
|
||||
|
||||
@@ -34,23 +34,28 @@ type GothProvider interface {
|
||||
GothProviderCreator
|
||||
}
|
||||
|
||||
// ImagedProvider provide an overridden image setting for the provider
|
||||
type ImagedProvider struct {
|
||||
// AuthSourceProvider provides a provider for an AuthSource. Multiple auth sources could use the same registered GothProvider
|
||||
// So each auth source should have its own DisplayName and IconURL for display.
|
||||
// The Name is the GothProvider's name, to help to find the GothProvider to sign in.
|
||||
// The DisplayName is the auth source config's name, site admin set it on the admin page, the IconURL can also be set there.
|
||||
type AuthSourceProvider struct {
|
||||
GothProvider
|
||||
image string
|
||||
sourceName, iconURL string
|
||||
}
|
||||
|
||||
// Image returns the image path for this provider
|
||||
func (i *ImagedProvider) Image() string {
|
||||
return i.image
|
||||
func (p *AuthSourceProvider) Name() string {
|
||||
return p.GothProvider.Name()
|
||||
}
|
||||
|
||||
// NewImagedProvider is a constructor function for the ImagedProvider
|
||||
func NewImagedProvider(image string, provider GothProvider) *ImagedProvider {
|
||||
return &ImagedProvider{
|
||||
GothProvider: provider,
|
||||
image: image,
|
||||
func (p *AuthSourceProvider) DisplayName() string {
|
||||
return p.sourceName
|
||||
}
|
||||
|
||||
func (p *AuthSourceProvider) IconURL() string {
|
||||
if p.iconURL != "" {
|
||||
return p.iconURL
|
||||
}
|
||||
return p.GothProvider.IconURL()
|
||||
}
|
||||
|
||||
// Providers contains the map of registered OAuth2 providers in Gitea (based on goth)
|
||||
@@ -95,11 +100,13 @@ func GetActiveOAuth2Providers() ([]string, map[string]Provider, error) {
|
||||
var orderedKeys []string
|
||||
providers := make(map[string]Provider)
|
||||
for _, source := range authSources {
|
||||
prov := gothProviders[source.Cfg.(*Source).Provider]
|
||||
if source.Cfg.(*Source).IconURL != "" {
|
||||
prov = &ImagedProvider{prov, source.Cfg.(*Source).IconURL}
|
||||
oauth2Cfg, ok := source.Cfg.(*Source)
|
||||
if !ok {
|
||||
log.Error("Invalid OAuth2 source config: %v", oauth2Cfg)
|
||||
continue
|
||||
}
|
||||
providers[source.Name] = prov
|
||||
gothProv := gothProviders[oauth2Cfg.Provider]
|
||||
providers[source.Name] = &AuthSourceProvider{GothProvider: gothProv, sourceName: source.Name, iconURL: oauth2Cfg.IconURL}
|
||||
orderedKeys = append(orderedKeys, source.Name)
|
||||
}
|
||||
|
||||
@@ -138,8 +145,7 @@ func ClearProviders() {
|
||||
goth.ClearProviders()
|
||||
}
|
||||
|
||||
// ErrAuthSourceNotActived login source is not actived error
|
||||
var ErrAuthSourceNotActived = errors.New("auth source is not actived")
|
||||
var ErrAuthSourceNotActivated = errors.New("auth source is not activated")
|
||||
|
||||
// used to create different types of goth providers
|
||||
func createProvider(providerName string, source *Source) (goth.Provider, error) {
|
||||
@@ -150,7 +156,7 @@ func createProvider(providerName string, source *Source) (goth.Provider, error)
|
||||
|
||||
p, ok := gothProviders[source.Provider]
|
||||
if !ok {
|
||||
return nil, ErrAuthSourceNotActived
|
||||
return nil, ErrAuthSourceNotActivated
|
||||
}
|
||||
|
||||
provider, err = p.CreateGothProvider(providerName, callbackURL, source)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
package oauth2
|
||||
|
||||
import "code.gitea.io/gitea/modules/setting"
|
||||
|
||||
// BaseProvider represents a common base for Provider
|
||||
type BaseProvider struct {
|
||||
name string
|
||||
@@ -19,9 +21,14 @@ func (b *BaseProvider) DisplayName() string {
|
||||
return b.displayName
|
||||
}
|
||||
|
||||
// Image returns an image path for this provider
|
||||
func (b *BaseProvider) Image() string {
|
||||
return "/assets/img/auth/" + b.name + ".png"
|
||||
// IconURL returns an icon path for this provider
|
||||
// Use svg for default icons, providers_openid has its own IconURL function
|
||||
func (b *BaseProvider) IconURL() string {
|
||||
name := b.name
|
||||
if b.name == "gplus" {
|
||||
name = "google"
|
||||
}
|
||||
return setting.AppSubURL + "/assets/img/auth/" + name + ".svg"
|
||||
}
|
||||
|
||||
// CustomURLSettings returns the custom url settings for this provider
|
||||
@@ -29,4 +36,4 @@ func (b *BaseProvider) CustomURLSettings() *CustomURLSettings {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ (Provider) = &BaseProvider{}
|
||||
var _ Provider = &BaseProvider{}
|
||||
|
||||
@@ -49,7 +49,7 @@ func NewCustomProvider(name, displayName string, customURLSetting *CustomURLSett
|
||||
}
|
||||
}
|
||||
|
||||
var _ (GothProvider) = &CustomProvider{}
|
||||
var _ GothProvider = &CustomProvider{}
|
||||
|
||||
func init() {
|
||||
RegisterGothProvider(NewCustomProvider(
|
||||
|
||||
@@ -24,9 +24,9 @@ func (o *OpenIDProvider) DisplayName() string {
|
||||
return "OpenID Connect"
|
||||
}
|
||||
|
||||
// Image returns an image path for this provider
|
||||
func (o *OpenIDProvider) Image() string {
|
||||
return "/assets/img/auth/openid_connect.svg"
|
||||
// IconURL returns an icon path for this provider
|
||||
func (o *OpenIDProvider) IconURL() string {
|
||||
return setting.AppSubURL + "/assets/img/svg/gitea-openid.svg"
|
||||
}
|
||||
|
||||
// CreateGothProvider creates a GothProvider from this Provider
|
||||
@@ -48,7 +48,7 @@ func (o *OpenIDProvider) CustomURLSettings() *CustomURLSettings {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ (GothProvider) = &OpenIDProvider{}
|
||||
var _ GothProvider = &OpenIDProvider{}
|
||||
|
||||
func init() {
|
||||
RegisterGothProvider(&OpenIDProvider{})
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewSimpleProvider(name, displayName string, scopes []string, newFn SimplePr
|
||||
}
|
||||
}
|
||||
|
||||
var _ (GothProvider) = &SimpleProvider{}
|
||||
var _ GothProvider = &SimpleProvider{}
|
||||
|
||||
func init() {
|
||||
RegisterGothProvider(
|
||||
@@ -69,13 +69,13 @@ func init() {
|
||||
}))
|
||||
|
||||
// named gplus due to legacy gplus -> google migration (Google killed Google+). This ensures old connections still work
|
||||
RegisterGothProvider(NewImagedProvider("/assets/img/auth/google.png", NewSimpleProvider("gplus", "Google", []string{"email"},
|
||||
RegisterGothProvider(NewSimpleProvider("gplus", "Google", []string{"email"},
|
||||
func(clientKey, secret, callbackURL string, scopes ...string) goth.Provider {
|
||||
if setting.OAuth2Client.UpdateAvatar || setting.OAuth2Client.EnableAutoRegistration {
|
||||
scopes = append(scopes, "profile")
|
||||
}
|
||||
return google.New(clientKey, secret, callbackURL, scopes...)
|
||||
})))
|
||||
}))
|
||||
|
||||
RegisterGothProvider(NewSimpleProvider("twitter", "Twitter", nil,
|
||||
func(clientKey, secret, callbackURL string, scopes ...string) goth.Provider {
|
||||
|
||||
@@ -57,6 +57,12 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode
|
||||
return
|
||||
}
|
||||
|
||||
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
|
||||
if err = issues_model.PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,7 +7,7 @@ package migrations
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/go-github/v52/github"
|
||||
"github.com/google/go-github/v53/github"
|
||||
)
|
||||
|
||||
// ErrRepoNotCreated returns the error that repository not created
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/proxy"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/google/go-github/v52/github"
|
||||
"github.com/google/go-github/v53/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
||||
@@ -123,6 +123,13 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu
|
||||
}
|
||||
|
||||
_, _ = issue_service.CreateComment(ctx, ops)
|
||||
|
||||
if !pr.IsWorkInProgress() {
|
||||
if err := issues_model.PullRequestCodeOwnersReview(ctx, pull, pr); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
)
|
||||
|
||||
// CreateNewBranch creates a new repository branch
|
||||
@@ -181,10 +180,6 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||
return err
|
||||
}
|
||||
|
||||
if err := pull_service.CloseBranchPulls(doer, repo.ID, branchName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Don't return error below this
|
||||
if err := PushUpdate(
|
||||
&repo_module.PushUpdateOptions{
|
||||
@@ -199,9 +194,5 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||
log.Error("Update: %v", err)
|
||||
}
|
||||
|
||||
if err := git_model.AddDeletedBranch(ctx, repo.ID, branchName, commit.ID.String(), doer.ID); err != nil {
|
||||
log.Warn("AddDeletedBranch: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -273,6 +273,9 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
// close all related pulls
|
||||
log.Error("close related pull request failed: %v", err)
|
||||
}
|
||||
if err := git_model.AddDeletedBranch(db.DefaultContext, repo.ID, branch, opts.OldCommitID, pusher.ID); err != nil {
|
||||
log.Warn("AddDeletedBranch: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Even if user delete a branch on a repository which he didn't watch, he will be watch that.
|
||||
|
||||
@@ -755,7 +755,7 @@ func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventCreate, &api.CreatePayload{
|
||||
Ref: refName, // FIXME: should it be a full ref name?
|
||||
Sha: refID,
|
||||
RefType: refFullName.RefGroup(),
|
||||
RefType: refFullName.RefType(),
|
||||
Repo: apiRepo,
|
||||
Sender: apiPusher,
|
||||
}); err != nil {
|
||||
@@ -791,12 +791,12 @@ func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
|
||||
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventDelete, &api.DeletePayload{
|
||||
Ref: refName, // FIXME: should it be a full ref name?
|
||||
RefType: refFullName.RefGroup(),
|
||||
RefType: refFullName.RefType(),
|
||||
PusherType: api.PusherTypeUser,
|
||||
Repo: apiRepo,
|
||||
Sender: apiPusher,
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks.(delete %s): %v", refFullName.RefGroup(), err)
|
||||
log.Error("PrepareWebhooks.(delete %s): %v", refFullName.RefType(), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user