aboutsummaryrefslogtreecommitdiffstats
path: root/modules
Commit message (Collapse)AuthorAgeFilesLines
* Add support for incoming emails (#22056)KN4CK3R2023-01-144-0/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | closes #13585 fixes #9067 fixes #2386 ref #6226 ref #6219 fixes #745 This PR adds support to process incoming emails to perform actions. Currently I added handling of replies and unsubscribing from issues/pulls. In contrast to #13585 the IMAP IDLE command is used instead of polling which results (in my opinion 😉) in cleaner code. Procedure: - When sending an issue/pull reply email, a token is generated which is present in the Reply-To and References header. - IMAP IDLE waits until a new email arrives - The token tells which action should be performed A possible signature and/or reply gets stripped from the content. I added a new service to the drone pipeline to test the receiving of incoming mails. If we keep this in, we may test our outgoing emails too in future. Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Log STDERR of external renderer when it fails (#22442)Jonathan Tran2023-01-131-1/+4
| | | | | | When using an external renderer, STDOUT is expected to be HTML. But anything written to STDERR is currently ignored. In cases where the renderer fails, I would like to log any error messages that the external program outputs to STDERR.
* Fix error when calculate the repository size (#22392)Lunny Xiao2023-01-133-16/+40
| | | | | | | | Fix #22386 `GetDirectorySize` moved as `getDirectorySize` because it becomes a special function which should not be put in `util`. Co-authored-by: Jason Song <i@wolfogre.com>
* Replace deprecated Webauthn library (#22400)techknowlogick2023-01-111-5/+4
| | | | | Fix #22052 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Allow HOST has no port (#22280)Lunny Xiao2023-01-113-5/+57
| | | | | | | Fix #22274 This PR will allow `HOST` without port. Then a default port will be given in future steps.
* Improve utils of slices (#22379)Jason Song2023-01-114-104/+173
| | | | | | | | | | | | | | | | | | | - Move the file `compare.go` and `slice.go` to `slice.go`. - Fix `ExistsInSlice`, it's buggy - It uses `sort.Search`, so it assumes that the input slice is sorted. - It passes `func(i int) bool { return slice[i] == target })` to `sort.Search`, that's incorrect, check the doc of `sort.Search`. - Conbine `IsInt64InSlice(int64, []int64)` and `ExistsInSlice(string, []string)` to `SliceContains[T]([]T, T)`. - Conbine `IsSliceInt64Eq([]int64, []int64)` and `IsEqualSlice([]string, []string)` to `SliceSortedEqual[T]([]T, T)`. - Add `SliceEqual[T]([]T, T)` as a distinction from `SliceSortedEqual[T]([]T, T)`. - Redesign `RemoveIDFromList([]int64, int64) ([]int64, bool)` to `SliceRemoveAll[T]([]T, T) []T`. - Add `SliceContainsFunc[T]([]T, func(T) bool)` and `SliceRemoveAllFunc[T]([]T, func(T) bool)` for general use. - Add comments to explain why not `golang.org/x/exp/slices`. - Add unit tests.
* Don't lookup mail server when using sendmail (#22300)Lunny Xiao2023-01-091-14/+17
| | | Fix #22287
* Use context parameter in models/git (#22367)Jason Song2023-01-092-6/+6
| | | | | | | | | 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>
* Always reuse transaction (#22362)Jason Song2023-01-082-2/+2
|
* Fix unstable emoji sort (#22346)KN4CK3R2023-01-051-1468/+1468
| | | Without the second sort every generate run produces a different result.
* Update Emoji dataset to Unicode 14 (#22342)isla w2023-01-041-304/+525
| | | | | | | | | | | | | | Gitea emoji dataset was out of date because it gets manually built and hasn't been rebuilt since it was added. This means Gitea doesn't recognize some newer emoji or changes to existing ones. After changing the max unicode version to 14 I just ran: `go run build/generate-emoji.go` This should address the initial issue seen in #22153 where Gitea doesn't recognize a standard alias used elsewhere when importing content. 14 is the latest supported version from the upstream source as 15 is not widely supported (in their opinion) yet
* Use git command instead of exec.Cmd in blame (#22098)Lunny Xiao2023-01-032-156/+39
| | | | | extract from #18147 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Display error log when a modified template has an error so that it could ↵Lunny Xiao2023-01-031-2/+9
| | | | | | | | | recovery when the error fixed (#22261) A drawback is the previous generated template has been cached, so you cannot get error in the UI but only from log Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: delvh <dev.lh@web.de>
* Unify hashing for avatar (#22289)Gusted2023-01-021-0/+28
| | | | | | | | | | | - 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>
* Fix get system setting bug when enabled redis cache (#22295)Lunny Xiao2023-01-021-33/+0
| | | | | | | | | Fix #22281 In #21621 , `Get[V]` and `Set[V]` has been introduced, so that cache value will be `*Setting`. For memory cache it's OK. But for redis cache, it can only store `string` for the current implementation. This PR revert some of changes of that and just store or return a `string` for system setting.
* Restructure `webhook` module (#22256)delvh2023-01-014-858/+133
| | | | | | | | | | | | 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>
* Reminder for no more logs to console (#22282)Jason Song2023-01-011-17/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Even if the log mode is `file`, there are still few logs printed to the console at the very beginning. That's fine but confusing. Someone will think the console is the only place to find logs, and get nothing helpful. See https://github.com/go-gitea/gitea/issues/22274#issuecomment-1367917717. There should be a reminder that there are no more logs to the console. And to avoid log loss, we should add configured loggers first, then remove console logger if there's no `console` in the mode. Tests with `MODE = file`: Before: <img width="1792" alt="image" src="https://user-images.githubusercontent.com/9418365/210079862-d591677f-347e-46ed-a548-bb2ddbb0885c.png"> After: <img width="1792" alt="image" src="https://user-images.githubusercontent.com/9418365/210080002-d66cc418-6888-4909-b370-d03f5986ef41.png"> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
* Fix bug of DisableGravatar default value (#22296)Lunny Xiao2023-01-011-1/+1
| | | | | | | #18058 made a mistake. The disableGravatar's default value depends on `OfflineMode`. If it's `true`, then `disableGravatar` is true, otherwise it's `false`. But not opposite. Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Use ErrInvalidArgument in packages (#22268)KN4CK3R2022-12-3111-41/+72
| | | | | | | | | Related to https://github.com/go-gitea/gitea/pull/22262#discussion_r1059010774 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
* Fix sitemap (#22272)Jason Song2022-12-302-66/+170
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix #22270. Related to #18407. The old code treated both sitemap and sitemap index as the format like: ```xml ... <url> <loc>http://localhost:3000/explore/users/sitemap-1.xml</loc> </url> ... ``` Actually, it's incorrect for sitemap index, it should be: ```xml ... <sitemap> <loc>http://localhost:3000/explore/users/sitemap-1.xml</loc> </sitemap> ... ``` See https://www.sitemaps.org/protocol.html Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: delvh <dev.lh@web.de>
* Add `sync_on_commit` option for push mirrors api (#22271)Chongyi Zheng2022-12-301-0/+2
| | | | | | | | | Push mirrors `sync_on_commit` option was added to the web interface in v1.18.0. However, it's not added to the API. This PR updates the API endpoint. Fixes #22267 Also, I think this should be backported to 1.18
* Correctly handle select on multiple channels in Queues (#22146)zeripath2022-12-303-57/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are a few places in FlushQueueWithContext which make an incorrect assumption about how `select` on multiple channels works. The problem is best expressed by looking at the following example: ```go package main import "fmt" func main() { closedChan := make(chan struct{}) close(closedChan) toClose := make(chan struct{}) count := 0 for { select { case <-closedChan: count++ fmt.Println(count) if count == 2 { close(toClose) } case <-toClose: return } } } ``` This PR double-checks that the contexts are closed outside of checking if there is data in the dataChan. It also rationalises the WorkerPool FlushWithContext because the previous implementation failed to handle pausing correctly. This will probably fix the underlying problem in #22145 Fix #22145 Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andrew Thornton <art27@cantab.net>
* Move `convert` package to services (#22264)KN4CK3R2022-12-2924-2356/+2
| | | | | | | | | | 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>
* refactor auth interface to return error when verify failure (#22119)Lunny Xiao2022-12-282-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Add option to prohibit fork if user reached maximum limit of repositories ↵Xinyu Zhou2022-12-271-0/+2
| | | | | | | | | | | | | | | | | | (#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>
* Use complete SHA to create and query commit status (#22244)Jason Song2022-12-278-11/+14
| | | | | | | 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>
* Add more test directory to exclude dir of air, remove watching templates ↵Lunny Xiao2022-12-271-1/+4
| | | | | | | | | | | | | | from air include dir because gitea has internal mechanism (#22246) Since #20218 introduced internal watching template, template watching should be removed from `air`. This will prevent restart the whole server once the template files changed to speed up developing when using `make watch`. To ensure `make watch` will reuse template watching, this PR introduced a new ENV `GITEA_RUN_MODE` to make sure `make watch` will always run in a dev mode of Gitea so that template watching will open. This PR also added more exclude testdata directories.
* Remove deadcode (#22245)Gusted2022-12-274-187/+0
| | | | | | | | - Remove code that isn't being used. Found this is my stash from a few weeks ago, not sure how I found this in the first place. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Normalize NuGet package version on upload (#22186)KN4CK3R2022-12-202-1/+32
| | | | | | | | Fixes #22178 After this change upload versions with different semver metadata are treated as the same version and trigger a duplicated version error. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Check for zero time instant in `TimeStamp.IsZero()` (#22171)Gusted2022-12-201-3/+8
| | | | | | | | | | | | | | | | | | - Currently, the 'IsZero' function for 'TimeStamp' just checks if the unix time is zero, which is not the behavior of 'Time.IsZero()', but Gitea is using this method in accordance with the behavior of 'Time.IsZero()'. - Adds a new condition to check for the zero time instant. - Fixes a bug where non-expiring GPG keys where shown as they expired on Jan 01, 0001. - Related https://codeberg.org/Codeberg/Community/issues/791 Before: ![image](https://user-images.githubusercontent.com/25481501/208509035-ecc5fa4a-3bd1-4fa3-beba-90875719163c.png) After: ![image](https://user-images.githubusercontent.com/25481501/208508950-3e7f6eeb-be83-432a-89a6-d738553dafe4.png)
* Add setting to disable the git apply step in test patch (#22130)zeripath2022-12-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Local storage should not store files as executable (#22162)zeripath2022-12-191-1/+2
| | | | | | | | | | The PR #21198 introduced a probable security vulnerability which resulted in making all storage files be marked as executable. This PR ensures that these are forcibly marked as non-executable. Fix #22161 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure that plain files are rendered correctly even when containing ↵zeripath2022-12-171-1/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ambiguous characters (#22017) As recognised in #21841 the rendering of plain text files is somewhat incorrect when there are ambiguous characters as the html code is double escaped. In fact there are several more problems here. We have a residual isRenderedHTML which is actually simply escaping the file - not rendering it. This is badly named and gives the wrong impression. There is also unusual behaviour whether the file is called a Readme or not and there is no way to get to the source code if the file is called README. In reality what should happen is different depending on whether the file is being rendered a README at the bottom of the directory view or not. 1. If it is rendered as a README on a directory - it should simply be escaped and rendered as `<pre>` text. 2. If it is rendered as a file then it should be rendered as source code. This PR therefore does: 1. Rename IsRenderedHTML to IsPlainText 2. Readme files rendered at the bottom of the directory are rendered without line numbers 3. Otherwise plain text files are rendered as source code. Replace #21841 Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Add doctor command for full GC of LFS (#21978)zeripath2022-12-151-0/+37
| | | | | | | | | | | | | | The recent PR adding orphaned checks to the LFS storage is not sufficient to completely GC LFS, as it is possible for LFSMetaObjects to remain associated with repos but still need to be garbage collected. Imagine a situation where a branch is uploaded containing LFS files but that branch is later completely deleted. The LFSMetaObjects will remain associated with the Repository but the Repository will no longer contain any pointers to the object. This PR adds a second doctor command to perform a full GC. Signed-off-by: Andrew Thornton <art27@cantab.net>
* Make gitea work using cmd.exe again (#22073)zeripath2022-12-141-0/+7
| | | | | | | | | | | | | | | | Gitea will attempt to lookup its location using LookPath however, this fails on cmd.exe if gitea is in the current working directory. exec.LookPath will return an exec.ErrDot error which we can test for and then simply using filepath.Abs(os.Args[0]) to absolute gitea against the current working directory. Fix #22063 Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* refactor bind functions based on generics (#22055)Lunny Xiao2022-12-121-10/+2
|
* Use multi reader instead to concat strings (#22099)Lunny Xiao2022-12-121-11/+8
| | | extract from #20326
* Rename almost all Ctx functions (#22071)Lunny Xiao2022-12-107-57/+51
|
* Add API management for issue/pull and comment attachments (#21783)KN4CK3R2022-12-097-60/+82
| | | | | | | | | | | | | | Close #14601 Fix #3690 Revive of #14601. Updated to current code, cleanup and added more read/write checks. Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andre Bruch <ab@andrebruch.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Norwin <git@nroo.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Update go dev dependencies (#22064)silverwind2022-12-083-3/+3
| | | | | `golangci-lint` [deprecated](https://github.com/golangci/golangci-lint/issues/1841) a bunch of linters, removed them.
* Support disabling database auto migration (#22053)Jason Song2022-12-072-0/+3
| | | | | Gitea will migrate the database model version automatically, but it should be able to be disabled and keep Gitea shutdown if the version is not matched.
* Ensure that Chinese punctuation is not ambiguous when locale is Chinese (#22019)zeripath2022-12-041-0/+6
| | | | | | | | | | Although there are per-locale fallbacks for ambiguity the locale names for Chinese do not quite match our locales. This PR simply maps zh-CN on to zh-hans and other zh variants on to zh-hant. Ref #20999 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Use GhostUser if needed for TrackedTimes (#22021)zeripath2022-12-041-6/+5
| | | | | | | | | When getting tracked times out of the db and loading their attributes handle not exist errors in a nicer way. (Also prevent an NPE.) Fix #22006 Signed-off-by: Andrew Thornton <art27@cantab.net>
* On tag/branch-exist check, dont panic if repo is nil (#21787)65432022-12-042-2/+2
| | | | fix a panic found in gitea logs
* refactor some functions to support ctx as first parameter (#21878)Lunny Xiao2022-12-0320-71/+77
| | | | Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lauris BH <lauris@nix.lv>
* Remove deprecated packages & staticcheck fixes (#22012)Chongyi Zheng2022-12-021-1/+1
| | | `ioutil` is deprecated and should use `io` instead
* Update gitea-vet to check FSFE REUSE (#22004)Jason Song2022-12-027-1/+7
| | | | | | | | | | | | | Related to: - #21840 - https://gitea.com/gitea/gitea-vet/pulls/21 What it looks like when it's working: https://drone.gitea.io/go-gitea/gitea/64040/1/5 All available SPDX license identifiers: [SPDX License List](https://spdx.org/licenses/). Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Use path not filepath in template filenames (#21993)zeripath2022-12-021-3/+3
| | | | | | | | | | Paths in git are always separated by `/` not `\` - therefore we should `path` and not `filepath` Fix #21987 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Lauris BH <lauris@nix.lv>
* Util type to parse ref name (#21969)Jason Song2022-12-011-20/+37
| | | | | | | Provide a new type to make it easier to parse a ref name. Actually, it's picked up from #21937, to make the origin PR lighter. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Skip initing LFS storage if disabled (#21996)Jason Song2022-12-011-0/+4
| | | | | | | A complement to #21985. I overlooked it because the name of the switch is `StartServer`, not `Enabled`. I believe the weird name is a legacy, but renaming is out of scope.