Commit Graph

819 Commits

Author SHA1 Message Date
Jason Song
f114a9c80a fix: ctx for NewCommitStatus 2023-01-09 14:01:09 +08:00
Jason Song
f414fd6141 Merge branch 'main' into feature/bots 2023-01-09 12:17:08 +08:00
Jason Song
7adc2de464 Use context parameter in models/git (#22367)
After #22362, we can feel free to use transactions without
`db.DefaultContext`.

And there are still lots of models using `db.DefaultContext`, I think we
should refactor them carefully and one by one.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-01-09 11:50:54 +08:00
Jason Song
5e9d4f7b9c Merge branch 'main' into feature/bots 2023-01-09 10:42:38 +08:00
Jason Song
6135359a04 Always reuse transaction (#22362) 2023-01-08 09:34:58 +08:00
Jason Song
21db670907 fix: use webhook_module 2023-01-06 20:46:36 +08:00
Jason Song
748fd3d085 chore: add init.go to actions 2023-01-06 18:06:12 +08:00
Jason Song
4b1d3c75d5 fix: ignore events caused by actions for actions notifier only 2023-01-06 17:21:07 +08:00
Jason Song
326ae5d442 fix: keep original commit message 2023-01-06 13:51:40 +08:00
Jason Song
ff75cbd81d chore: fix log 2023-01-06 13:47:45 +08:00
Jason Song
eee662442a fix: simplify deleting 2023-01-05 15:40:19 +08:00
Jason Song
c3d7f15513 chore: remove CreateRunnerForm 2023-01-05 15:20:02 +08:00
Jason Song
08383bdcbc chore: simplify truncateContent 2023-01-05 15:16:14 +08:00
Jason Song
4bb8604180 chore: add comments 2023-01-05 14:58:49 +08:00
Jason Song
e8dbe827cb fix: use %w 2023-01-05 14:45:40 +08:00
Jason Song
bb3eb5efdc fix: use ctx 2023-01-05 14:44:09 +08:00
Jason Song
ede9a5f2fa chore: add comments 2023-01-05 14:43:07 +08:00
Jason Song
b884772652 Apply suggestions from code review
Co-authored-by: delvh <dev.lh@web.de>
2023-01-05 11:59:32 +08:00
Jason Song
b4c692a2bb chore: format code 2023-01-05 10:49:50 +08:00
Jason Song
c3b37c4e44 Update services/actions/clear_tasks.go
Co-authored-by: delvh <dev.lh@web.de>
2023-01-04 20:39:18 +08:00
Jason Song
066097a0fb Update services/forms/runner.go
Co-authored-by: delvh <dev.lh@web.de>
2023-01-04 20:38:24 +08:00
Jason Song
e35a046c7a Update services/auth/basic.go
Co-authored-by: delvh <dev.lh@web.de>
2023-01-04 20:36:09 +08:00
Jason Song
6148e4c940 fix: rename to GetPossibleUserByID 2023-01-04 18:52:22 +08:00
Jason Song
7f6a803d24 fix: omit total in FindTasks 2023-01-04 18:52:22 +08:00
Jason Song
53afbcecad Merge branch 'main' into feature/bots 2023-01-03 09:43:23 +08:00
Gusted
96797fed31 Unify hashing for avatar (#22289)
- Unify the hashing code for repository and user avatars into a
function.
- Use a sane hash function instead of MD5.
- Only require hashing once instead of twice(w.r.t. hashing for user
avatar).
- Improve the comment for the hashing code of why it works.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
2023-01-02 22:46:39 +01:00
delvh
0f4e1b9ac6 Restructure webhook module (#22256)
Previously, there was an `import services/webhooks` inside
`modules/notification/webhook`.
This import was removed (after fighting against many import cycles).
Additionally, `modules/notification/webhook` was moved to
`modules/webhook`,
and a few structs/constants were extracted from `models/webhooks` to
`modules/webhook`.

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-01-01 23:23:15 +08:00
Jason Song
133437d4eb Merge branch 'main' into feature/bots 2022-12-30 09:36:51 +08:00
Jason Song
47efba78ec Support template for merge message description (#22248)
Fix #21435.

Use the first line of the template as the git commit message title, and
the rest as the description.

## Snapshots

<img width="806" alt="image"
src="https://user-images.githubusercontent.com/9418365/209644083-5d85179c-cf58-404f-bc98-c662398a2411.png">
<img width="860" alt="image"
src="https://user-images.githubusercontent.com/9418365/209644392-22573090-e2c1-458b-ba44-855b79735632.png">
<img width="1154" alt="image"
src="https://user-images.githubusercontent.com/9418365/209644457-a1b2711a-6787-45b4-b52c-a88d7fc132d7.png">

Co-authored-by: delvh <dev.lh@web.de>
2022-12-29 14:40:20 +02:00
Jason Song
3db95bfbad fix: check oauth2 user id 2022-12-29 17:33:47 +08:00
Jason Song
a145ec2f2b fix: do not init actions service when disabled 2022-12-29 16:19:25 +08:00
Jason Song
5ae2816ac4 chore: use webhook_model alias 2022-12-29 16:06:59 +08:00
Jason Song
ec020563ae refactor: mv modules/notification/actions to services/actions 2022-12-29 16:05:00 +08:00
Jason Song
f11a31e54e Merge branch 'main' into feature/bots 2022-12-29 14:51:21 +08:00
KN4CK3R
a35749893b Move convert package to services (#22264)
Addition to #22256

The `convert` package relies heavily on different models which is
[disallowed by our definition of
modules](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#design-guideline).
This helps to prevent possible import cycles.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2022-12-29 10:57:15 +08:00
Jason Song
d8f2343497 fix: auth return 2022-12-28 18:26:31 +08:00
Jason Song
c393a9ca93 Merge branch 'main' into feature/bots 2022-12-28 18:22:40 +08:00
Lunny Xiao
ca67c5a8a7 refactor auth interface to return error when verify failure (#22119)
This PR changed the Auth interface signature from 
`Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess
SessionStore) *user_model.User`
to 
`Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess
SessionStore) (*user_model.User, error)`.

There is a new return argument `error` which means the verification
condition matched but verify process failed, we should stop the auth
process.

Before this PR, when return a `nil` user, we don't know the reason why
it returned `nil`. If the match condition is not satisfied or it
verified failure? For these two different results, we should have
different handler. If the match condition is not satisfied, we should
try next auth method and if there is no more auth method, it's an
anonymous user. If the condition matched but verify failed, the auth
process should be stop and return immediately.

This will fix #20563

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: Jason Song <i@wolfogre.com>
2022-12-28 13:53:28 +08:00
Jason Song
d995fc6281 Merge branch 'main' into feature/bots 2022-12-28 13:29:46 +08:00
Xinyu Zhou
7cc7db73b9 Add option to prohibit fork if user reached maximum limit of repositories (#21848)
If user has reached the maximum limit of repositories:

- Before
  - disallow create
  - allow fork without limit
- This patch:
  - disallow create
  - disallow fork
- Add option `ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT` (Default **true**) :
enable this allow user fork repositories without maximum number limit

fixed https://github.com/go-gitea/gitea/issues/21847

Signed-off-by: Xinyu Zhou <i@sourcehut.net>
2022-12-27 15:21:14 -06:00
Jason Song
6cf09ccab4 Use complete SHA to create and query commit status (#22244)
Fix #13485.

Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2022-12-27 21:12:49 +08:00
Jason Song
3462760632 Merge branch 'main' into feature/bots 2022-12-23 20:56:52 +08:00
Jason Song
71ca3067bc Check primary keys for all tables and drop ForeignReference (#21721)
Some dbs require that all tables have primary keys, see
- #16802
- #21086

We can add a test to keep it from being broken again.

Edit:

~Added missing primary key for `ForeignReference`~ Dropped the
`ForeignReference` table to satisfy the check, so it closes #21086.

More context can be found in comments.

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: zeripath <art27@cantab.net>
2022-12-23 19:35:43 +08:00
Jason Song
a6917db570 fix: do not init cron for actions when it's disabled 2022-12-23 17:07:11 +08:00
Jason Song
058675f7e5 fix: use new secrets 2022-12-22 14:44:22 +08:00
Jason Song
d183b32aa8 Merge branch 'main' into feature/bots 2022-12-22 12:00:41 +08:00
Jason Song
88e813d1ca Revert "Add simple master key provider for secret encryption"
This reverts commit d4e84c0433.
2022-12-22 11:45:06 +08:00
Jason Song
b54f148164 Revert "Add AES GCM encryption provider"
This reverts commit 4af45f7bc9.
2022-12-22 11:37:11 +08:00
Jason Song
659055138b Secrets storage with SecretKey encrypted (#22142)
Fork of #14483, but [gave up
MasterKey](https://github.com/go-gitea/gitea/pull/14483#issuecomment-1350728557),
and fixed some problems.

Close #12065.
Needed by #13539.

Featrues:
- Secrets for repo and org, not user yet.
- Use SecretKey to encrypte/encrypt secrets.
- Trim spaces of secret value.
- Add a new locale ini block, to make it easy to support secrets for
user.

Snapshots:

Repo level secrets:

![image](https://user-images.githubusercontent.com/9418365/207823319-b8a4903f-38ca-4af7-9d05-336a5af906f3.png)

Rrg level secrets

![image](https://user-images.githubusercontent.com/9418365/207823371-8bd02e93-1928-40d1-8c76-f48b255ace36.png)

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
2022-12-20 17:07:13 +08:00
zeripath
d6b96627c1 Add setting to disable the git apply step in test patch (#22130)
For a long time Gitea has tested PR patches using a git apply --check
method, and in fact prior to the introduction of a read-tree assisted
three-way merge in #18004, this was the only way of checking patches.

Since #18004, the git apply --check method has been a fallback method,
only used when the read-tree three-way merge method has detected a
conflict. The read-tree assisted three-way merge method is much faster
and less resource intensive method of detecting conflicts. #18004 kept
the git apply method around because it was thought possible that this
fallback might be able to rectify conflicts that the read-tree three-way
merge detected. I am not certain if this could ever be the case.

Given the uncertainty here and the now relative stability of the
read-tree method - this PR makes using this fallback optional and
disables it by default. The hope is that users will not notice any
significant difference in conflict detection and we will be able to
remove the git apply fallback in future, and/or improve the read-tree
three-way merge method to catch any conflicts that git apply method
might have been able to fix.

An additional benefit is that patch checking should be significantly
less resource intensive and much quicker.

(See
https://github.com/go-gitea/gitea/issues/22083\#issuecomment-1347961737)

Ref #22083

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
2022-12-19 19:37:15 +08:00