Commit Graph

1685 Commits (main)

Author SHA1 Message Date
Lunny Xiao d21ce9fa07
Improve the performance when detecting the file editable (#34653)
Noticed the SQL will be executed 4 times when visit the file render view
page. For a repository which have many pull requests, it maybe slow.
```SQL
2025/06/08 15:24:44 models/issues/pull_list.go:69:GetUnmergedPullRequestsByHeadInfo() [I] [SQL] SELECT * FROM `pull_request` INNER JOIN `issue` ON issue.id = pull_request.issue_id WHERE (head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?) [393 main false false 0] - 2.004167ms
2025/06/08 15:24:44 models/issues/pull_list.go:69:GetUnmergedPullRequestsByHeadInfo() [I] [SQL] SELECT * FROM `pull_request` INNER JOIN `issue` ON issue.id = pull_request.issue_id WHERE (head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?) [393 main false false 0] - 1.03975ms
2025/06/08 15:24:44 models/issues/pull_list.go:69:GetUnmergedPullRequestsByHeadInfo() [I] [SQL] SELECT * FROM `pull_request` INNER JOIN `issue` ON issue.id = pull_request.issue_id WHERE (head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?) [393 main false false 0] - 881.583µs
2025/06/08 15:24:44 models/issues/pull_list.go:69:GetUnmergedPullRequestsByHeadInfo() [I] [SQL] SELECT * FROM `pull_request` INNER JOIN `issue` ON issue.id = pull_request.issue_id WHERE (head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?) [393 main false false 0] - 935.084µs
```

This PR did a refactor to query it once only.
2025-06-12 18:12:45 +00:00
ChristopherHX c9505a26b9
Improve instance wide ssh commit signing (#34341)
* Signed SSH commits can look in the UI like on GitHub, just like gpg keys today in Gitea
* SSH format can be added in gitea config
* SSH Signing worked before with DEFAULT_TRUST_MODEL=committer

`TRUSTED_SSH_KEYS` can be a list of additional ssh public key contents
to trust for every user of this instance

Closes #34329
Related #31392

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-06-11 10:32:55 +00:00
Lunny Xiao fbc3796f9e
Fix pull requests API convert panic when head repository is deleted. (#34685)
Fix #34682
2025-06-10 20:19:52 -07:00
wxiaoguang 0082cb51fa
Fix last admin check when syncing users (#34649)
Fix #34358
2025-06-09 20:57:45 +00:00
Lunny Xiao 6d0b24064a
Keeping consistent between UI and API about combined commit status state and fix some bugs (#34562)
Extract from #34531 

## Move Commit status state to a standalone package

Move the state from `structs` to `commitstatus` package. It also
introduce `CommitStatusStates` so that the combine function could be
used from UI and API logic.

## Combined commit status Changed

This PR will follow Github's combined commit status. Before this PR,
every commit status could be a combined one.
According to
https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference
> Additionally, a combined state is returned. The state is one of:
> failure if any of the contexts report as error or failure
> pending if there are no statuses or a context is pending
> success if the latest status for all contexts is success

This PR will follow that rule and remove the `NoBetterThan` logic. This
also fixes the inconsistent between UI and API. In the API convert
package, it has implemented this which is different from the UI. It also
fixed the missing `URL` and `CommitURL` in the API.

## `CalcCommitStatus` return nil if there is no commit statuses

The behavior of `CalcCommitStatus` is changed. If the parameter commit
statuses is empty, it will return nil. The reference places should check
the returned value themselves.
2025-06-09 04:05:33 +00:00
wxiaoguang f6041441ee
Refactor FindOrgOptions to use enum instead of bool, fix membership visibility (#34629) 2025-06-09 03:30:34 +00:00
Lunny Xiao a9a705f4db
Fix missed merge commit sha and time when migrating from codecommit (#34645)
Fix #34627
2025-06-08 16:16:23 +00:00
wxiaoguang cc942e2a86
Fix GetUsersByEmails (#34643) 2025-06-07 18:30:36 +00:00
Lunny Xiao 108db0b04f
Fix possible pull request broken when leave the page immediately after clicking the update button (#34509)
If user leaves the page, the context will become cancelled, so that the
update process maybe terminal in an unexpected status. This PR haven't
resolve the problem totally. It uses a background context to not cancel
the update process even if the user leaved the pull request view page.

Fix #31779
2025-06-04 17:09:08 +00:00
Lunny Xiao 497b83b75d
Fix migration pull request title too long (#34577)
Fix #34294
2025-06-04 15:45:45 +00:00
Lunny Xiao 4e471487fb
Remove unnecessary duplicate code (#34552)
`GetIssuesLastCommitStatus` will revoke `GetIssuesAllCommitStatus` but
it has been invoked. The `CommitStatus` template variable has never been
used in notification subscription page so that it could be removed.
2025-06-03 16:27:29 +00:00
wxiaoguang 2a1585b32e
Refactor some tests (#34580)
1. use `test.MockVariableValue` as much as possible
2. avoid `time.Sleep` as much as possible
2025-06-03 01:26:19 +00:00
Philip Peterson c5e78fc7ad
Do not mutate incoming options to SearchRepositoryByName (#34553)
Similar to #34544, this PR changes the `opts` argument in
`SearchRepositoryByName()` to be passed by value instead of by pointer,
as its mutations do not escape the function scope and are not used
elsewhere. This simplifies reasoning about the function and avoids
unnecessary pointer usage.

This insight emerged during an initial attempt to refactor
`RenderUserSearch()`, which currently intermixes multiple concerns.

---------

Co-authored-by: Philip Peterson <philip-peterson@users.noreply.github.com>
2025-06-02 17:33:25 +00:00
Râu Cao f48c0135a6
Fix/improve avatar sync from LDAP (#34573)
This fixes 3 issues I encountered when debugging problems with our LDAP sync:

1. The comparison of the hashed image data in `IsUploadAvatarChanged` is
wrong. It seems to be from before avatar hashing was changed and unified
in #22289. This results in the function always returning `true` for any
avatars, even if they weren't changed.
2. Even if there's no avatar to upload (i.e. no avatar available for the
LDAP entry), the upload function would still be called for every single
user, only to then fail, because the data isn't valid. This is
unnecessary.
3. Another small issue is that the comparison function (and thus hashing
of data) is called for every user, even if there is no avatar attribute
configured at all for the LDAP source. Thus, I switched the condition
nesting, so that no cycles are wasted when avatar sync isn't configured
in the first place.

I also added a trace log for when there is actually a new avatar being
uploaded for an existing user, which is now only shown when that is
actually the case.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-06-02 10:05:47 -07:00
wxiaoguang e8d8984f7c
Fix some trivial problems (#34579) 2025-06-02 15:22:43 +00:00
Jim Lin 82ea2387e4
Always use an empty line to separate the commit message and trailer (#34512)
If the message from form.MergeMessageField is empty, we will miss a "\n"
between the title and the "Co-authored-by:" line. The title and message
should have a blank line between of them.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-06-02 06:29:16 +00:00
Lunny Xiao 7149c9c55d
Fix doctor deleting orphaned issues attachments (#34142)
Fix the bug when deleting orphaned issues attachments. The attachments
maybe stored on other storages service rather than disk.
2025-05-30 05:06:03 +00:00
badhezi 0cec4b84e2
Fix actions skipped commit status indicator (#34507)
Addresses https://github.com/go-gitea/gitea/issues/34500

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-28 11:36:21 -04:00
NorthRealm 4cb0c641ce
Add "View workflow file" to Actions list page (#34538)
This PR adds "View workflow file" to Actions list page, and replaces the
redundant link.

Related #34530

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-28 20:30:00 +08:00
Lunny Xiao 498088c053
Add webhook assigning test and fix possible bug (#34420)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-27 18:53:27 +00:00
Lunny Xiao 24a51059d7
Fix possible nil description of pull request when migrating from CodeCommit (#34541)
Fix #34320
2025-05-27 11:25:34 -07:00
Lunny Xiao 688da55f54
Split GetLatestCommitStatus as two functions (#34535)
Extract from #34531. This will reduce unnecessary count operation in
databases.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-26 19:00:22 +00:00
Lunny Xiao b595f81b79
Performance optimization for tags synchronization (#34355)
The tags synchronization is very slow for a non-mirror repository with
many tags especially forking. This PR make all repositories' tags
synchronization use the same function and remove the low performance
synchronization function. The commit count of tag now will not be stored
into database when syncing. Since the commits count will always be read
from cache or git data, the `NumCommits` in the release table will be
updated for the first read from git data.
2025-05-22 13:54:42 -07:00
Lunny Xiao 06ccda06c4
Fix possible panic (#34508) 2025-05-22 12:59:42 +00:00
ChristopherHX 73f640fc15
Fix ephemeral runner deletion (#34447)
* repository deletion, delete ephemeral runners with active tasks as
well skips regular cleanup
* user deletion, delete ephemeral runners with active tasks as well
skips regular cleanup
* delete ephemeral runners once status changes to done
* You no longer see used ephemeral runners after the task is done
  * if you see one the cron job takes care of it
2025-05-20 15:42:31 +00:00
badhezi 0534eddd16
Use run-name and evaluate workflow variables (#34301)
This addresses https://github.com/go-gitea/gitea/issues/34247
depends on https://gitea.com/gitea/act/pulls/137

I couldn't find any previous implementation for `run-name` support on
workflows so I created one.

Key points:
All dispatched workflows, scheduled workflows and detected workflows
(from different hooks) will use and evaluate `run-name` if exists, with
the corresponding gitea context and variables. This will be used as the
Action run title and replace the default commit message being used
today.

Had to change act package jobparser (see link above)
and create two helpers
3a1320c70d/models/actions/utils.go (L86)
and
3a1320c70d/services/actions/context.go (L169)
to pass the correct types to
[GenerateGiteaContext](https://github.com/go-gitea/gitea/pull/34301/files#diff-9c9c27cb61a33e55ad33dc2c2e6a3521957a3e5cc50ddf652fdcd1def87b044dR86)
and
[WithGitContext](65c232c4a5/pkg/jobparser/jobparser.go (L84))
respectively.

<img width="1336" alt="Screenshot 2025-04-28 at 17 13 01"
src="https://github.com/user-attachments/assets/73cb03d0-23a0-4858-a466-bbf0748cea98"
/>
2025-05-20 02:24:10 +00:00
Adam Majer 9cfcc079c7
Export repo's manual merge settings (#34502) 2025-05-19 13:08:00 -04:00
Sebastian Weigand 7b518bc6c7
Change "rejected" to "changes requested" in 3rd party PR review notification (#34481)
This PR changes 3rd party notifications wording on a PR review that
requests changes and can be considered a follow up for #5858 to also fix
#5857 in 3rd party notifications.

The difference in the actual notification would be the following:

```diff
- Pull request review rejected
+ Pull request review changes requested
```

While this is a simple string change at first look, it has a deeper UX
meaning.

# Motivation

We could observe that some developers are hesitant to press the "Request
changes" button since their peers first see that their changes were
rejected, thus a more appropriate wording that also falls in line with
the meaning and UI would be beneficial.

## Meaning

Pressing the `Request changes` button in a PR review means that as a
reviewer you are willing to merge the general change in a PR if changes
requested review comments are implemented.
Rejecting a PR on the other hand would be equivalent with closing it
since that change isn't welcome at all (e.g. out of scope feature).

## Sync with UI

The UI button says `request changes` and the other options 


![image](https://github.com/user-attachments/assets/3766cc89-40d7-4c5e-9ff7-a0e1f6991ea6)



## Considered Problems

This might break some automation for users who rely on string matching.
2025-05-15 23:56:26 -04:00
NorthRealm 1e2f3514b9
Add endpoint deleting workflow run (#34337)
Add endpoint deleting workflow run
Resolves #26219

/claim #26219

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-13 19:18:13 +00:00
ChristopherHX a0595add72
Fix remove org user failure on mssql (#34449)
* mssql does not support fetching 0 repositories
  * remove paging by NumRepos that might be 0
* extend admin api test to purge user 2

Fixes #34448

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-14 02:33:56 +08:00
wxiaoguang 5cb4cbf044
Fix repo broken check (#34444)
Fix #34424
2025-05-13 08:18:45 +00:00
Lunny Xiao 780e92ea99
Only git operations should update `last changed` of a repository (#34388)
Try to fix #32046
2025-05-11 19:18:46 +00:00
GWDx 71a1187209
Fix incorrect divergence cache after switching default branch (#34370)
Issue: After switching the default branch, other branches are still
compared against the old default branch due to outdated divergence
cache.

Change: Clear the divergence cache in SetRepoDefaultBranch to ensure
correct comparisons against the new default branch.

Fixes #34369
2025-05-08 18:00:29 +00:00
bytedream 2fbc8f9e87
Fix LFS file not stored in LFS when uploaded/edited via API or web UI (#34367)
Files that should be stored in LFS and are uploaded/edited from the API
or web UI aren't stored in LFS. This may be a regression from #34154.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-05-08 13:07:53 +08:00
Lunny Xiao 2a660b4a1b
Upgrade go-github v61 -> v71 (#34385)
There will be a possible bug when migrating from Github
https://github.com/google/go-github/issues/3229
This PR upgrades go-github from v61 to v71 to resolve that problem.
2025-05-06 20:10:14 -07:00
Tobias Balle-Petersen 3e49fba578
feat: return time of last usage for public keys and access tokens in the api (#34323)
In the Gitea GUI, the user can see the time that _AccessTokens_ and
_PublicKeys_ were last used. This information is not returned by the
_/users/{username}/tokens_ and _/user/keys_ endpoints in the API. This
PR adds the missing data.

The time of last usage for for _tokens_ & _keys_ seem to be stored in
the _Updated_ field of the structs internally. For consistency, I have
used the name _updated_at_ for the new field returned by the _API_.
However, for the _API_ user, I don't think that name reflects the data
returned, as I believe it is the time of last usage. I propose that we
use the name _last_used_at_ instead. Let's hear reviewers opinion on
that.

* PublicKey
  1. _last_used_at_: string($date-time)
* AccessToken
  1. _created_at_: string($date-time) (for parity with public keys)
  2. _last_used_at_: string($date-time)

Fix #34313
2025-05-01 21:42:17 +03:00
Tobias Balle-Petersen e67f74efc8
fix: do not return archive download URLs in API if downloads are disabled (#34324)
If archive downloads are are disabled using
_DISABLE_DOWNLOAD_SOURCE_ARCHIVES_, archive links are still returned by
the API.

This PR changes the data returned, so the fields _zipball_url_ and
_tarball_url_ are omitted if archive downloads have been disabled.

Resolve #32159
2025-04-30 10:06:37 -07:00
Kerwin Bryant 2b76993415
support the open-icon of folder (#34168)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-28 19:51:32 -07:00
Lunny Xiao 44d7d2973a
Fix wrong review requests when updating the pull request (#34286)
Fix #34224

The previous implementation in #33744 will get the pushed commits
changed files. But it's not always right when push a merged commit. This
PR reverted the logic in #33744 and will always get the PR's changed
files and get code owners.
2025-04-28 22:57:56 +00:00
wxiaoguang 0148d03f21
Enforce two-factor auth (2FA: TOTP or WebAuthn) (#34187)
Fix #880

Design:

1. A global setting `security.TWO_FACTOR_AUTH`.
* To support org-level config, we need to introduce a better "owner
setting" system first (in the future)
2. A user without 2FA can login and may explore, but can NOT read or
write to any repositories via API/web.
3. Keep things as simple as possible.
* This option only aggressively suggest users to enable their 2FA at the
moment, it does NOT guarantee that users must have 2FA before all other
operations, it should be good enough for real world use cases.
* Some details and tests could be improved in the future since this
change only adds a check and seems won't affect too much.

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2025-04-28 15:31:59 -07:00
Brecht Van Lommel a9343896f4
Option to delay conflict checking of old pull requests until page view (#27779)
`[repository.pull-request] DELAY_CHECK_FOR_INACTIVE_DAYS` is a new
setting to delay the mergeable check for pull requests that have been
inactive for the specified number of days.

This avoids potentially long delays for big repositories with many pull
requests. and reduces system load overall when there are many
repositories or pull requests.

When viewing the PR, checking will start immediately and the PR merge
box will automatically reload when complete. Accessing the PR through
the API will also start checking immediately.

The default value of `7` provides a balance between system load, and
keeping behavior similar to what it was before both for users and API
access. With `0` all conflict checking will be delayed, while `-1`
always checks immediately to restore the previous behavior.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-24 19:26:57 +00:00
Lunny Xiao e73c1139ac
Fix panic when comment is nil (#34257)
Fix #34254
2025-04-24 01:58:00 +00:00
wxiaoguang 8aee07a064
Improve "not found" error messages for API (#34267)
Make the message clear, for example: #34266
2025-04-23 17:42:50 +08:00
Denys Konovalov 9a071a596f
Add API endpoint to request contents of multiple files simultaniously (#34139)
Adds an API POST endpoint under `/repos/{owner}/{repo}/file-contents`
which receives a list of paths and returns a list of the contents of
these files.

This API endpoint will be helpful for applications like headless CMS
(reference: https://github.com/sveltia/sveltia-cms/issues/198) which
need to retrieve a large number of files by reducing the amount of
needed API calls.

Close #33495

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-22 01:20:11 +08:00
YaFou e947f309b1
Add API routes to lock and unlock issues (#34165)
This pull request adds a GitHub-compatible API endpoint to lock and
unlock an issue.

The following routes exist now:
- `PUT /api/v1/repos/{owner}/{repo}/issues/{id}/lock` to lock an issue
- `DELETE /api/v1/repos/{owner}/{repo}/issues/{id}/lock` to unlock an issue

Fixes #33677
Fixes #20012

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-21 00:43:43 +00:00
Lunny Xiao 6d3c6741ec
Fix notify watch failure when the content is too long (#34233)
Fix #28193

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-20 02:49:57 +00:00
ChristopherHX 21b43fce08
Actions Runner rest api (#33873)
Implements runner apis based on
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization

- Add Post endpoints for registration-token, google/go-github revealed
this as problem
  - We should deprecate Get Endpoints, leaving them for compatibility
- Get endpoint of admin has api path /admin/runners/registration-token
that feels wrong, /admin/actions/runners/registration-token seems more
consistent with user/org/repo api
- Get Runner Api
- List Runner Api
- Delete Runner Api

- Tests admin / user / org / repo level endpoints

Related to #33750 (implements point 1 and 2)
Via needs discovered in #32461, this runner api is needed to allow
cleanup of runners that are deallocated without user interaction.

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-18 15:22:41 +00:00
Kerwin Bryant 2b99a58f54
Mark parent directory as viewed when all files are viewed (#33958)
Fix #25644 

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-04-15 22:35:22 +08:00
wxiaoguang 58a3952458
Fix package upload temp path (#34196)
Fix #34195

The temp dir should be created when it is used.
2025-04-14 18:55:02 +08:00
Lunny Xiao f6474cf2e9
Fix bug when migrating repository (#34182)
This PR fixed a bug which is a regression from #31035
2025-04-14 04:48:03 +00:00