forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
* upstream/main: Add support for commit cross references (go-gitea#22645) Fix missing message in git hook when pull requests disabled on fork (go-gitea#22625) Check quota limits for container uploads (go-gitea#22450) Consume hcaptcha and pwn deps (go-gitea#22610) Issues: add Project filter to issues list and search (go-gitea#22544) Improve accessibility of navigation bar and footer (go-gitea#22635) Support system hook API (go-gitea#14537) Improve checkIfPRContentChanged (go-gitea#22611)
- Loading branch information
Showing
37 changed files
with
1,338 additions
and
233 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package webhook | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
// GetDefaultWebhooks returns all admin-default webhooks. | ||
func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error) { | ||
webhooks := make([]*Webhook, 0, 5) | ||
return webhooks, db.GetEngine(ctx). | ||
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, false). | ||
Find(&webhooks) | ||
} | ||
|
||
// GetSystemOrDefaultWebhook returns admin system or default webhook by given ID. | ||
func GetSystemOrDefaultWebhook(ctx context.Context, id int64) (*Webhook, error) { | ||
webhook := &Webhook{ID: id} | ||
has, err := db.GetEngine(ctx). | ||
Where("repo_id=? AND org_id=?", 0, 0). | ||
Get(webhook) | ||
if err != nil { | ||
return nil, err | ||
} else if !has { | ||
return nil, ErrWebhookNotExist{ID: id} | ||
} | ||
return webhook, nil | ||
} | ||
|
||
// GetSystemWebhooks returns all admin system webhooks. | ||
func GetSystemWebhooks(ctx context.Context, isActive util.OptionalBool) ([]*Webhook, error) { | ||
webhooks := make([]*Webhook, 0, 5) | ||
if isActive.IsNone() { | ||
return webhooks, db.GetEngine(ctx). | ||
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, true). | ||
Find(&webhooks) | ||
} | ||
return webhooks, db.GetEngine(ctx). | ||
Where("repo_id=? AND org_id=? AND is_system_webhook=? AND is_active = ?", 0, 0, true, isActive.IsTrue()). | ||
Find(&webhooks) | ||
} | ||
|
||
// DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0) | ||
func DeleteDefaultSystemWebhook(ctx context.Context, id int64) error { | ||
return db.WithTx(ctx, func(ctx context.Context) error { | ||
count, err := db.GetEngine(ctx). | ||
Where("repo_id=? AND org_id=?", 0, 0). | ||
Delete(&Webhook{ID: id}) | ||
if err != nil { | ||
return err | ||
} else if count == 0 { | ||
return ErrWebhookNotExist{ID: id} | ||
} | ||
|
||
_, err = db.DeleteByBean(ctx, &HookTask{HookID: id}) | ||
return err | ||
}) | ||
} | ||
|
||
// CopyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo | ||
func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error { | ||
ws, err := GetDefaultWebhooks(ctx) | ||
if err != nil { | ||
return fmt.Errorf("GetDefaultWebhooks: %v", err) | ||
} | ||
|
||
for _, w := range ws { | ||
w.ID = 0 | ||
w.RepoID = repoID | ||
if err := CreateWebhook(ctx, w); err != nil { | ||
return fmt.Errorf("CreateWebhook: %v", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package hcaptcha | ||
|
||
const ( | ||
ErrMissingInputSecret ErrorCode = "missing-input-secret" | ||
ErrInvalidInputSecret ErrorCode = "invalid-input-secret" | ||
ErrMissingInputResponse ErrorCode = "missing-input-response" | ||
ErrInvalidInputResponse ErrorCode = "invalid-input-response" | ||
ErrBadRequest ErrorCode = "bad-request" | ||
ErrInvalidOrAlreadySeenResponse ErrorCode = "invalid-or-already-seen-response" | ||
ErrNotUsingDummyPasscode ErrorCode = "not-using-dummy-passcode" | ||
ErrSitekeySecretMismatch ErrorCode = "sitekey-secret-mismatch" | ||
) | ||
|
||
// ErrorCode is any possible error from hCaptcha | ||
type ErrorCode string | ||
|
||
// String fulfills the Stringer interface | ||
func (err ErrorCode) String() string { | ||
switch err { | ||
case ErrMissingInputSecret: | ||
return "Your secret key is missing." | ||
case ErrInvalidInputSecret: | ||
return "Your secret key is invalid or malformed." | ||
case ErrMissingInputResponse: | ||
return "The response parameter (verification token) is missing." | ||
case ErrInvalidInputResponse: | ||
return "The response parameter (verification token) is invalid or malformed." | ||
case ErrBadRequest: | ||
return "The request is invalid or malformed." | ||
case ErrInvalidOrAlreadySeenResponse: | ||
return "The response parameter has already been checked, or has another issue." | ||
case ErrNotUsingDummyPasscode: | ||
return "You have used a testing sitekey but have not used its matching secret." | ||
case ErrSitekeySecretMismatch: | ||
return "The sitekey is not registered with the provided secret." | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
// Error fulfills the error interface | ||
func (err ErrorCode) Error() string { | ||
return err.String() | ||
} |
Oops, something went wrong.