aboutsummaryrefslogtreecommitdiffstats
path: root/services
Commit message (Collapse)AuthorAgeFilesLines
* Improve LFS error logs (#24072)wxiaoguang2023-04-121-2/+3
| | | | | The error logs were not clear. Help (but not fix) #24053
* Fix accidental overwriting of LDAP team memberships (#24050)sillyguodong2023-04-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the `for` loop, the value of `membershipsToAdd[org]` and `membershipsToRemove[org]` is a slice that should be appended instead of overwritten. Due to the current overwrite, the LDAP group sync only matches the last group at the moment. ## Example reproduction - an LDAP user is both a member of `cn=admin_staff,ou=people,dc=planetexpress,dc=com` and `cn=ship_crew,ou=people,dc=planetexpress,dc=com`. - configuration of `Map LDAP groups to Organization teams ` in `Authentication Sources`: ```json { "cn=admin_staff,ou=people,dc=planetexpress,dc=com":{ "test_organization":[ "admin_staff", "test_add" ] }, "cn=ship_crew,ou=people,dc=planetexpress,dc=com":{ "test_organization":[ "ship_crew" ] } ``` - start `Synchronize external user data` task in the `Dashboard`. - the user was only added for the team `test_organization.ship_crew`
* Use actions job link as commit status URL instead of run link (#24023)Jason Song2023-04-101-1/+20
| | | | | | | A commit status is bound to a job, not a run. --------- Co-authored-by: silverwind <me@silverwind.io>
* Make label templates have consistent behavior and priority (#23749)wxiaoguang2023-04-101-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix https://github.com/go-gitea/gitea/issues/23715 Other related PRs: * #23717 * #23716 * #23719 This PR is different from others, it tries to resolve the problem fundamentally (and brings more benefits) Although it looks like some more lines are added, actually many new lines are for tests. ---- Before, the code was just "guessing" the file type and try to parse them. <details> ![image](https://user-images.githubusercontent.com/2114189/228002245-57d58e27-1078-4da9-bf42-5bc0b264c6ce.png) </details> This PR: * Always remember the original option file names, and always use correct parser for them. * Another benefit is that we can sort the Label Templates now (before there was a map, its key order is undefined) ![image](https://user-images.githubusercontent.com/2114189/228002432-931b9f18-3908-484b-a36b-04760c9ad132.png)
* Update github.com/google/go-github to v51 (#23946)harryzcy2023-04-082-20/+27
| | | | `github.com/google/go-github` has new major version releases frequently. It is required to update all import path, in additional to `go.mod`
* Drop "unrolled/render" package (#23965)wxiaoguang2023-04-081-2/+1
| | | | | | | | | | | | None of the features of `unrolled/render` package is used. The Golang builtin "html/template" just works well. Then we can improve our HTML render to resolve the "$.root.locale.Tr" problem as much as possible. Next step: we can have a template render pool (by Clone), then we can inject global functions with dynamic context to every `Execute` calls. Then we can use `{{Locale.Tr ....}}` directly in all templates , no need to pass the `$.root.locale` again and again.
* Set `ref` to fully-formed of the tag when trigger event is `release` (#23944)sillyguodong2023-04-072-5/+5
| | | | | Fix #23943 When trigger event is `release`, ref should be like `refs/tags/<tag_name>` instead of `CommitID`
* Title can be empty when creating tag only (#23917)Zettat1232023-04-061-1/+1
| | | | | | | | Fixes #23809 Make the title not required. If the title is empty when creating release (not tag), an error message will be displayed. ![image](https://user-images.githubusercontent.com/15528715/229761056-c52e338b-5f25-4d7d-bb44-2cb0304abcee.png)
* Actions: Use default branch as ref when a branch/tag delete occurs (#23910)Brad Nabholz2023-04-061-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently using the tip of main (2c585d62a4ebbb52175b8fd8697458ae1c3b2937) and when deleting a branch (and presumably tag, but not tested), no workflows with `on: [delete]` are being triggered. The runner isn't being notified about them. I see this in the gitea log: `2023/04/04 04:29:36 ...s/notifier_helper.go:102:Notify() [E] an error occurred while executing the NotifyDeleteRef actions method: gitRepo.GetCommit: object does not exist [id: test, rel_path: ]` Understandably the ref has already been deleted and so `GetCommit` fails. Currently at https://github.com/go-gitea/gitea/blob/main/services/actions/notifier_helper.go#L130, if the ref is an empty string it falls back to the default branch name. This PR also checks if it is a `HookEventDelete` and does the same. Currently `${{ github.ref }}` would be equivalent to the deleted branch (if `notify()` succeded), but this PR allows `notify()` to proceed and also aligns it with the GitHub Actions behavior at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#delete: `$GITHUB_REF` / `${{ github.ref }}` => Default branch (main/master) `$GITHUB_SHA` / `${{ github.sha }}` => Last commit on default branch If the user needs the name of the deleted branch (or tag), it is available as `${{ github.event.ref }}`. There appears to be no way for the user to get the tip commit SHA of the deleted branch (GitHub does not do this either). N.B. there may be other conditions other than `HookEventDelete` where the default branch ref needs swapped in, but this was sufficient for my use case.
* Delete deleted release attachments immediately from storage (#23913)Lunny Xiao2023-04-061-1/+1
| | | | | | | | Previously, deleted release attachments were kept forever on the external storage. Note: It may be very slow now if there are many attachments to be deleted on this release. Fix #23728
* Treat PRs with agit flow as fork PRs when triggering actions. (#23884)Jason Song2023-04-061-1/+16
| | | | | | There is no fork concept in agit flow, anyone with read permission can push `refs/for/<target-branch>/<topic-branch>` to the repo. So we should treat it as a fork pull request because it may be from an untrusted user.
* Add activity feeds API (#23494)Zettat1232023-04-041-0/+52
| | | | | Close #5666 Add APIs for getting activity feeds.
* Use User.ID instead of User.Name in ActivityPub API for Person IRI (#23823)wxiaoguang2023-04-041-0/+21
| | | | | | | | Thanks to @trwnh Close #23802 The ActivityPub id is an HTTPS URI that should remain constant, even if the user changes their name.
* Check `IsActionsToken` for LFS authentication (#23841)Zettat1232023-04-021-1/+19
| | | | | | | Close #23824 Actions cannot fetch LFS objects from private repos because we don't check if the user is the `ActionUser`.
* [Patch] Fix closed PR also triggers Webhooks and actions (#23782)sillyguodong2023-03-301-0/+4
| | | | | | Fix #23707 Cause by #23189 This PR is a quick fix that, when pushing commits to closed PR, webhook and actions also be triggered.
* Refactor commit status for Actions jobs (#23786)Jason Song2023-03-294-55/+67
| | | | | | | | | | | | | | | | | | | Before: <img width="353" alt="xnip_230329_163852" src="https://user-images.githubusercontent.com/9418365/228479807-424452df-10fa-45cf-ae4b-09939c0ed54c.png"> After: <img width="508" alt="xnip_230329_163358" src="https://user-images.githubusercontent.com/9418365/228479923-537b54fe-9564-4105-a068-bcc75fa2a7ea.png"> Highlights: - Treat `StatusSkipped` as `CommitStatusSuccess` instead of `CommitStatusFailure`, so it fixed #23599. - Use the bot user `gitea-actions` instead of the trigger as the creator of commit status. - New format `<run_name> / <job_name> / (<event>)` for the context of commit status to avoid conflicts. - Add descriptions for commit status. - Add the missing calls to `CreateCommitStatus`. - Refactor `CreateCommitStatus` to make it easier to use.
* Don't apply the group filter when listing LDAP group membership if it is ↵zeripath2023-03-291-1/+1
| | | | | | | | | | empty (#23745) When running listLdapGroupMemberships check if the groupFilter is empty before using it to list memberships. Fix #23615 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add API to manage issue dependencies (#17935)qwerty2872023-03-281-16/+20
| | | | | | | | | | | | | | | | | | | | Adds API endpoints to manage issue/PR dependencies * `GET /repos/{owner}/{repo}/issues/{index}/blocks` List issues that are blocked by this issue * `POST /repos/{owner}/{repo}/issues/{index}/blocks` Block the issue given in the body by the issue in path * `DELETE /repos/{owner}/{repo}/issues/{index}/blocks` Unblock the issue given in the body by the issue in path * `GET /repos/{owner}/{repo}/issues/{index}/dependencies` List an issue's dependencies * `POST /repos/{owner}/{repo}/issues/{index}/dependencies` Create a new issue dependencies * `DELETE /repos/{owner}/{repo}/issues/{index}/dependencies` Remove an issue dependency Closes https://github.com/go-gitea/gitea/issues/15393 Closes #22115 Co-authored-by: Andrew Thornton <art27@cantab.net>
* Fix tags view (#23243)Wiktor Kwapisiewicz2023-03-271-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR fixes several issues reported in https://github.com/go-gitea/gitea/issues/23221. It does three things: 1. Fixes the `DefaultBranch` variable that has not been set. 2. Sets `Title` and `Message` for newly created tags from the Tag message. This makes it easier to create releases from tags that have messages and for those that don't it doesn't have any effect. 3. Makes UI changes so that tags look more like proper releases. Before: ![2023-03-02-12-31-19](https://user-images.githubusercontent.com/1718963/222416890-941a74d4-9cd0-4c45-a59e-199d2580cd8c.png) After: ![2023-03-02-12-31-31](https://user-images.githubusercontent.com/1718963/222416919-abce2009-8955-4cd0-9bed-1374582e04f7.png) I purposefully didn't reformat the template so that the diff is cleaner but can do so if that's welcome. Thanks for your time! --------- Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
* Create commit status when event is `pull_request_sync` (#23683)sillyguodong2023-03-241-1/+1
| | | | | | | | | | | Fix: #23674 If the type of `hook_event` is `pull_request_sync`, also need to insert a record of `commit_status` into DB. Because `pull_request` event and `pull_request_sync` event have the same payload, so the code is reusable. Screenshot: ![image](https://user-images.githubusercontent.com/33891828/227465436-1b436807-d0b2-4a2b-8890-09d96c7f666d.png)
* Fix incorrect `HookEventType` of pull request review comments (#23650)Zettat1232023-03-244-5/+5
| | | | | `HookEventType` of pull request review comments should be `HookEventPullRequestReviewComment` but some event types are `HookEventPullRequestComment` now.
* Introduce path Clean/Join helper functions (#23495)wxiaoguang2023-03-213-6/+4
| | | | | | | | | | | | | | | Since #23493 has conflicts with latest commits, this PR is my proposal for fixing #23371 Details are in the comments And refactor the `modules/options` module, to make it always use "filepath" to access local files. Benefits: * No need to do `util.CleanPath(strings.ReplaceAll(p, "\\", "/"))), "/")` any more (not only one before) * The function behaviors are clearly defined
* fix submodule is nil panic (#23588)来自村里的小螃蟹2023-03-201-1/+3
| | | | | | | | | | #23587 submodule path is nil It is panic a nil error --------- Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Add absent repounits to create/edit repo API (#23500)James Cleverley-Prance2023-03-161-0/+18
| | | | Adds the ability to enable/disable Actions, Packages and Releases from the API, via the Edit and Get Repository API endpoints.
* Disable sending email after push a commit to a closed PR (#23462)sillyguodong2023-03-151-1/+4
| | | | | | | | | | | Close #23440 Cause by #23189 In #23189, we should insert a comment record into db when pushing a commit to the PR, even if the PR is closed. But should skip sending any notification in this case. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* add admin API email endpoints (#22792)techknowlogick2023-03-141-0/+11
| | | | add email endpoint to admin API to ensure API parity with admin dashboard.
* add user rename endpoint to admin api (#22789)techknowlogick2023-03-143-2/+59
| | | | | | | | | | | | this is a simple endpoint that adds the ability to rename users to the admin API. Note: this is not in a mergeable state. It would be better if this was handled by a PATCH/POST to the /api/v1/admin/users/{username} endpoint and the username is modified. --------- Co-authored-by: Jason Song <i@wolfogre.com>
* Fix missing commit status in PR which from forked repo (#23351)sillyguodong2023-03-131-23/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | close: #23347 ### Reference and Inference According to Github REST API [doc](https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#list-commit-statuses-for-a-reference): 1. The `Drone CI` that can create some commit status by [API](https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status) is enabled in `go-gitea/gitea`. So I tried to call the API to get a commit status list of a PR which is commited to upstream repo(`go-gitea/gitea`). As a result, the API returned a array of commit status. ![image](https://user-images.githubusercontent.com/33891828/223913371-313d047a-5e2e-484c-b13e-dcd38748703e.png) 2. Then I tried to call the API to get commit status list of the reference which of the `SHA` is the same as step 1 in the repo which is forked from `go-gitea/gitea`. But I got a empty array. ![image](https://user-images.githubusercontent.com/33891828/223930827-17a64d3c-f466-4980-897c-77fe386c4d3b.png) So, I believe it that: 1. The commit status is not shared between upstream repo and forked repo. 2. The coomit status is bound to a repo that performs actions. (Gitea's logic is the same) ### Cause During debugging, I found it that commit status are not stored in the DB as expected. So, I located the following code: https://github.com/go-gitea/gitea/blob/8cadd51bf295e6ff36ac36efed68cc5de34c9382/services/actions/commit_status.go#L18-L26 When I create a PR, the type of `event` is `pull request`, not `push`. So the code return function directly. ### Screenshot ![image](https://user-images.githubusercontent.com/33891828/223939339-dadf539c-1fdd-40c4-96e9-2e4fa733f531.png) ![image](https://user-images.githubusercontent.com/33891828/223939519-edb02bf0-2478-4ea5-9366-be85468f02db.png) ![image](https://user-images.githubusercontent.com/33891828/223939557-ec6f1375-5536-400e-8987-fb7d2fd452fa.png) ### Other In this PR, I also fix the problem of missing icon which represents running in PRs list. ![image](https://user-images.githubusercontent.com/33891828/223939898-2a0339e4-713f-4c7b-9d99-2250a43f3457.png) ![image](https://user-images.githubusercontent.com/33891828/223939979-037a975f-5ced-480c-bac7-0ee00ebfff4b.png)
* Add Swift package registry (#22404)KN4CK3R2023-03-132-1/+3
| | | | | | This PR adds a [Swift](https://www.swift.org/) package registry. ![grafik](https://user-images.githubusercontent.com/1666336/211842523-07521cbd-8fb6-400f-820c-ee8048b05ae8.png)
* Preserve file size when creating attachments (#23406)Peter2023-03-124-8/+11
| | | | | | | | | | | When creating attachments (issue, release, repo) the file size (being part of the multipart file header) is passed through the chain of creating an attachment to ensure the MinIO client can stream the file directly instead of having to read it to memory completely at first. Fixes #23393 Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Add missing tabs to org projects page (#22705)yp053272023-03-101-9/+0
| | | | | | | | | | | | | | | | | Fixes https://github.com/go-gitea/gitea/issues/22676 Context Data `IsOrganizationMember` and `IsOrganizationOwner` is used to control the visibility of `people` and `team` tab. https://github.com/go-gitea/gitea/blob/2871ea08096cba15546f357d0ec473734ee9d8be/templates/org/menu.tmpl#L19-L40 And because of the reuse of user projects page, User Context is changed to Organization Context. But the value of `IsOrganizationMember` and `IsOrganizationOwner` are not being given. I reused func `HandleOrgAssignment` to add them to the ctx, but may have some unnecessary variables, idk whether it is ok. I found there is a missing `PageIsViewProjects` at create project page.
* Add user webhooks (#21563)KN4CK3R2023-03-102-6/+6
| | | | | | | Currently we can add webhooks for organizations but not for users. This PR adds the latter. You can access it from the current users settings. ![grafik](https://user-images.githubusercontent.com/1666336/197391408-15dfdc23-b476-4d0c-82f7-9bc9b065988f.png)
* Handle OpenID discovery URL errors a little nicer when creating/editing ↵zeripath2023-03-101-0/+4
| | | | | | | | | | | sources (#23397) When there is an error creating a new openIDConnect authentication source try to handle the error a little better. Close #23283 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Improve squash merge commit author and co-author with private emails (#22977)Brecht Van Lommel2023-03-092-7/+53
| | | | | | | | | | | | | When emails addresses are private, squash merges always use `@noreply.localhost` for the author of the squash commit. And the author is redundantly added as a co-author in the commit message. Also without private mails, the redundant co-author is possible when committing with a signature that's different than the user full name and primary email. Now try to find a commit by the same user in the list of commits, and prefer the signature from that over one constructed from the account settings.
* Fix pull request update showing too many commits with multiple branches (#22856)Brecht Van Lommel2023-03-092-81/+15
| | | | | | | | | | | | | | | When the base repository contains multiple branches with the same commits as the base branch, pull requests can show a long list of commits already in the base branch as having been added. What this is supposed to do is exclude commits already in the base branch. But the mechansim to do so assumed a commit only exists in a single branch. Now use `git rev-list A B --not branchName` instead of filtering commits afterwards. The logic to detect if there was a force push also was wrong for multiple branches. If the old commit existed in any branch in the base repository it would assume there was no force push. Instead check if the old commit is an ancestor of the new commit.
* Refactor merge/update git command calls (#23366)wxiaoguang2023-03-093-38/+28
| | | | | | | | | | | | | | | | Follow #22568 * Remove unnecessary ToTrustedCmdArgs calls * the FAQ in #22678 * Quote: When using ToTrustedCmdArgs, the code will be very complex (see the changes for examples). Then developers and reviewers can know that something might be unreasonable. * The `signArg` couldn't be empty, it's either `-S{keyID}` or `--no-gpg-sign`. * Use `signKeyID` instead, add comment "empty for no-sign, non-empty to sign" * 5-line code could be extracted to a common `NewGitCommandCommit()` to handle the `signKeyID`, but I think it's not a must, current code is clear enough.
* Improve cache context (#23330)Jason Song2023-03-081-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related to: #22294 #23186 #23054 Replace: #23218 Some discussion is in the comments of #23218. Highlights: - Add Expiration for cache context. If a cache context has been used for more than 10s, the cache data will be ignored, and warning logs will be printed. - Add `discard` field to `cacheContext`, a `cacheContext` with `discard` true will drop all cached data and won't store any new one. - Introduce `WithNoCacheContext`, if one wants to run long-life tasks, but the parent context is a cache context, `WithNoCacheContext(perentCtx)` will discard the cache data, so it will be safe to keep the context for a long time. - It will be fine to treat an original context as a cache context, like `GetContextData(context.Backgraud())`, no warning logs will be printed. Some cases about nesting: When: - *A*, *B* or *C* means a cache context. - ~*A*~, ~*B*~ or ~*C*~ means a discard cache context. - `ctx` means `context.Backgrand()` - *A(ctx)* means a cache context with `ctx` as the parent context. - *B(A(ctx))* means a cache context with `A(ctx)` as the parent context. - `With` means `WithCacheContext` - `WithNo` means `WithNoCacheContext` So: - `With(ctx)` -> *A(ctx)* - `With(With(ctx))` -> *A(ctx)*, not *B(A(ctx))* - `With(With(With(ctx)))` -> *A(ctx)*, not *C(B(A(ctx)))* - `WithNo(ctx)` -> *ctx*, not *~A~(ctx)* - `WithNo(With(ctx))` -> *~A~(ctx)* - `WithNo(WithNo(With(ctx)))` -> *~A~(ctx)*, not *~B~(~A~(ctx))* - `With(WithNo(With(ctx)))` -> *B(~A~(ctx))* - `WithNo(With(WithNo(With(ctx))))` -> *~B~(~A~(ctx))* - `With(WithNo(With(WithNo(With(ctx)))))` -> *C(~B~(~A~(ctx)))*
* Use CleanPath instead of path.Clean (#23371)Lunny Xiao2023-03-083-6/+6
| | | As title.
* Refactor and tidy-up the merge/update branch code (#22568)zeripath2023-03-0711-606/+753
| | | | | | | | | | | | | | | | | | | The merge and update branch code was previously a little tangled and had some very long functions. The functions were not very clear in their reasoning and there were deficiencies in their logging and at least one bug in the handling of LFS for update by rebase. This PR substantially refactors this code and splits things out to into separate functions. It also attempts to tidy up the calls by wrapping things in "context"s. There are also attempts to improve logging when there are errors. Signed-off-by: Andrew Thornton <art27@cantab.net> --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: delvh <dev.lh@web.de>
* Fix broken code editor diff preview (#23307)wxiaoguang2023-03-061-1/+1
| | | | | | | | | | | | | | | | | | | | | Close #23265, the code editor diff preview has been broken for long time. * Fix the regression for `data-line-num` * `.code-diff` is necessary to show the line number * Fix the regression for #12434 * The diff: [12434](https://github.com/go-gitea/gitea/pull/12434/files?diff=unified&w=1) * It hides the Type(4) (aka HunkHeader) for unexpected cases. Diff with ignoring whitespaces: https://github.com/go-gitea/gitea/pull/23307/files?diff=unified&w=1 Before: see the issue #23265 After: ![image](https://user-images.githubusercontent.com/2114189/222942810-286dc9af-0b39-4e9d-8585-8c299b881241.png)
* Make Ctrl+Enter submit a pending comment (starting review) instead of ↵wxiaoguang2023-03-043-6/+6
| | | | | | | | | | | | | | | | | | submitting a single comment (#23245) Close #23241 Before: press Ctrl+Enter in the Code Review Form, a single comment will be added. After: press Ctrl+Enter in the Code Review Form, start the review with pending comments. The old name `is_review` is not clear, so the new code use `pending_review` as the new name. Co-authored-by: delvh <leon@kske.dev> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Avoid panic caused by broken payload when creating commit status (#23216)Jason Song2023-03-043-6/+29
| | | | | | | | | | | | | | | | | | When creating commit status for Actons jobs, a payload with nil `HeadCommit` will cause panic. Reported at: https://gitea.com/gitea/act_runner/issues/28#issuecomment-732166 Although the `HeadCommit` probably can not be nil after #23215, `CreateCommitStatus` should protect itself, to avoid being broken in the future. In addition, it's enough to print error log instead of returning err when `CreateCommitStatus` failed. --------- Co-authored-by: delvh <dev.lh@web.de>
* Fill head commit to in payload when notifying push commits for mirroring ↵Jason Song2023-03-031-0/+7
| | | | | | | | | | | | | | | | | | | | | | (#23215) Just like what has been done when pushing manually: https://github.com/go-gitea/gitea/blob/7a5af25592003ddc3017fcd7b822a3e02fc40ef6/services/repository/push.go#L225-L226 Before: <img width="448" alt="image" src="https://user-images.githubusercontent.com/9418365/222100123-cd4839d1-2d4d-45f7-b7a0-0cbc73162b44.png"> After: <img width="448" alt="image" src="https://user-images.githubusercontent.com/9418365/222100225-f3c5bb65-7ab9-41e2-8e39-9d84c23c352d.png"> --------- Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix cannot reopen after pushing commits to a closed PR (#23189)sillyguodong2023-03-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Close: #22784 1. On GH, we can reopen a PR which was closed before after pushing commits. After reopening PR, we can see the commits that were pushed after closing PR in the time line. So the case of [issue](https://github.com/go-gitea/gitea/issues/22784) is a bug which needs to be fixed. 2. After closing a PR and pushing commits, `headBranchSha` is not equal to `sha`(which is the last commit ID string of reference). If the judgement exists, the button of reopen will not display. So, skip the judgement if the status of PR is closed. ![image](https://user-images.githubusercontent.com/33891828/222037529-651fccf9-0bba-433e-b2f0-79c17e0cc812.png) 3. Even if PR is already close, we should still insert comment record into DB when we push commits. So we should still call function `CreatePushPullComment()`. https://github.com/go-gitea/gitea/blob/067b0c2664d127c552ccdfd264257caca4907a77/services/pull/pull.go#L260-L282 So, I add a switch(`includeClosed`) to the `GetUnmergedPullRequestsByHeadInfo` func to control whether the status of PR must be open. In this case, by setting `includeClosed` to `true`, we can query the closed PR. ![image](https://user-images.githubusercontent.com/33891828/222621045-bb80987c-10c5-4eac-aa0c-1fb9c6aefb51.png) 4. In the loop of comments, I use the`latestCloseCommentID` variable to record the last occurrence of the close comment. In the go template, if the status of PR is closed, the comments whose type is `CommentTypePullRequestPush(29)` after `latestCloseCommentID` won't be rendered. ![image](https://user-images.githubusercontent.com/33891828/222058913-c91cf3e3-819b-40c5-8015-654b31eeccff.png) e.g. 1). The initial status of the PR is opened. ![image](https://user-images.githubusercontent.com/33891828/222453617-33c5093e-f712-4cd6-8489-9f87e2075869.png) 2). Then I click the button of `Close`. PR is closed now. ![image](https://user-images.githubusercontent.com/33891828/222453694-25c588a9-c121-4897-9ae5-0b13cf33d20b.png) 3). I try to push a commit to this PR, even though its current status is closed. ![image](https://user-images.githubusercontent.com/33891828/222453916-361678fb-7321-410d-9e37-5a26e8095638.png) But in comments list, this commit do not display.This is as expected :) ![image](https://user-images.githubusercontent.com/33891828/222454169-7617a791-78d2-404e-be5e-77d555f93313.png) 4). Click the `Reopen` button, the commit which is pushed after closing PR display now. ![image](https://user-images.githubusercontent.com/33891828/222454533-897893b6-b96e-4701-b5cb-b1800f382b8f.png) --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Add loading yaml label template files (#22976)Lauris BH2023-03-021-8/+11
| | | | | | | | Extract from #11669 and enhancement to #22585 to support exclusive scoped labels in label templates * Move label template functionality to label module * Fix handling of color codes * Add Advanced label template
* Do not create commit graph for temporary repos (#23219)Brecht Van Lommel2023-03-011-2/+8
| | | | | | | When fetching remotes for conflict checking, skip unnecessary and potentially slow writing of commit graphs. In a test with the Blender repository, this reduces conflict checking time for one pull request from about 2s to 0.1s.
* Use context parameter in services/repository (#23186)Jason Song2023-02-2812-66/+68
| | | | | | | | Use context parameter in `services/repository`. And use `cache.WithCacheContext(ctx)` to generate push action history feeds. Fix #23160
* Require approval to run actions for fork pull request (#22803)Jason Song2023-02-241-2/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, Gitea will run actions automatically which are triggered by fork pull request. It's a security risk, people can create a PR and modify the workflow yamls to execute a malicious script. So we should require approval for first-time contributors, which is the default strategy of a public repo on GitHub, see [Approving workflow runs from public forks](https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks). Current strategy: - don't need approval if it's not a fork PR; - always need approval if the user is restricted; - don't need approval if the user can write; - don't need approval if the user has been approved before; - otherwise, need approval. https://user-images.githubusercontent.com/9418365/217207121-badf50a8-826c-4425-bef1-d82d1979bc81.mov GitHub has an option for that, you can see that at `/<owner>/<repo>/settings/actions`, and we can support that later. <img width="835" alt="image" src="https://user-images.githubusercontent.com/9418365/217199990-2967e68b-e693-4e59-8186-ab33a1314a16.png"> --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix SyncOnCommit always return false in API of push_mirrors (#23088)sillyguodong2023-02-231-0/+1
| | | | | | | | | | Fix: #22990 --- Before, the return value of the api is always false,regrardless of whether the entry of `sync_on_commit` is true or false. I have confirmed that the value of `sync_on_commit` dropped into the database is correct. So, I think it is enough to make some small changes.
* Use minio/sha256-simd for accelerated SHA256 (#23052)zeripath2023-02-224-4/+5
| | | | | | | | | | | | minio/sha256-simd provides additional acceleration for SHA256 using AVX512, SHA Extensions for x86 and ARM64 for ARM. It provides a drop-in replacement for crypto/sha256 and if the extensions are not available it falls back to standard crypto/sha256. --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: John Olheiser <john.olheiser@gmail.com>