mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 17:41:16 +02:00
Compare commits
81 Commits
v1.23.0-de
...
v1.10.2
Author | SHA1 | Date | |
---|---|---|---|
|
2ccd92407a | ||
|
17c691f8aa | ||
|
cb3fe4cbf1 | ||
|
c63a80138a | ||
|
b4b8c9679f | ||
|
c0bb5ebc15 | ||
|
9409ac9030 | ||
|
a3928fd820 | ||
|
f0bda12c49 | ||
|
58c38ab4b6 | ||
|
a276aaf61e | ||
|
e03934f035 | ||
|
3a14a69e8a | ||
|
f0f48e0fff | ||
|
1aeeaa8e89 | ||
|
eb8d5f6aff | ||
|
9ef148abeb | ||
|
f11df80058 | ||
|
59913f405c | ||
|
42dae399eb | ||
|
f36efe0b54 | ||
|
38664d7f39 | ||
|
c4e52d232e | ||
|
2b257a91de | ||
|
c01afd584d | ||
|
1270e2ad85 | ||
|
29fa3a0f68 | ||
|
65a573f3c7 | ||
|
ade5ec5aa7 | ||
|
38ce87a61a | ||
|
261b19ced7 | ||
|
6ef0ab4d96 | ||
|
ecdb4c1750 | ||
|
a0e76de75a | ||
|
880f26c7f0 | ||
|
fd461ca555 | ||
|
3487fb66a1 | ||
|
1122230d0e | ||
|
9619ccf0e5 | ||
|
023ae3c48c | ||
|
3227a11f71 | ||
|
3497efac4a | ||
|
43fc99a7ed | ||
|
8693e54426 | ||
|
b27cac021f | ||
|
ca69ded83e | ||
|
fbcf235633 | ||
|
1275c88589 | ||
|
42d0efd1f3 | ||
|
68b7f9f3f7 | ||
|
26457782c1 | ||
|
1c65ecc1c6 | ||
|
c5e5063ec9 | ||
|
b040a87665 | ||
|
2236375d66 | ||
|
646fd8b570 | ||
|
4dac8b2389 | ||
|
3341aaf3f0 | ||
|
e766f11bd3 | ||
|
432f9dd1a3 | ||
|
8caf05989f | ||
|
9bde52ffc1 | ||
|
fa03af8456 | ||
|
14ebda6fd5 | ||
|
1d10747514 | ||
|
83c90e9ba0 | ||
|
2fbd5ae2e5 | ||
|
0032278a46 | ||
|
ccf5298a2c | ||
|
ece768ab6e | ||
|
bac9424a62 | ||
|
afeab941b3 | ||
|
cf35355db8 | ||
|
8e9265c402 | ||
|
435ce92935 | ||
|
22cea96c18 | ||
|
7565ac02c2 | ||
|
4e85c8e0d8 | ||
|
34b8becef0 | ||
|
0752a3895a | ||
|
595033f78e |
123
CHANGELOG.md
123
CHANGELOG.md
@@ -4,12 +4,61 @@ This changelog goes through all the changes that have been made in each release
|
||||
without substantial changes to our git log; to see the highlights of what has
|
||||
been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
|
||||
## [1.10.0-RC1](https://github.com/go-gitea/gitea/releases/tag/v1.10.0-rc1) - 2019-10-14
|
||||
## [1.10.2](https://github.com/go-gitea/gitea/releases/tag/v1.10.2) - 2020-01-02
|
||||
* BUGFIXES
|
||||
* Allow only specific Columns to be updated on Issue via API (#9539) (#9580)
|
||||
* Add ErrReactionAlreadyExist error (#9550) (#9564)
|
||||
* Fix bug when migrate from API (#8631) (#9563)
|
||||
* Use default avatar for ghost user (#9536) (#9537)
|
||||
* Fix repository issues pagination bug when there are more than one label filter (#9512) (#9528)
|
||||
* Fix deleted branch not removed when push the branch again (#9516) (#9524)
|
||||
* Fix missing repository status when migrating repository via API (#9511)
|
||||
* Trigger webhook when deleting a branch after merging a PR (#9510)
|
||||
* Fix paging on /repos/{owner}/{repo}/git/trees/{sha} API endpoint (#9482)
|
||||
* Fix NewCommitStatus (#9434) (#9435)
|
||||
* Use OriginalURL instead of CloneAddr in migration logging (#9418) (#9420)
|
||||
* Fix Slack webhook payload title generation to work with Mattermost (#9404)
|
||||
* DefaultBranch needs to be prefixed by BranchPrefix (#9356) (#9359)
|
||||
* Fix issue indexer not triggered when migrating a repository (#9333)
|
||||
* Fix bug that release attachment files not deleted when deleting repository (#9322) (#9329)
|
||||
* Fix migration releases (#9319) (#9326) (#9328)
|
||||
* Fix File Edit: Author/Committer interchanged (#9297) (#9300)
|
||||
|
||||
## [1.10.1](https://github.com/go-gitea/gitea/releases/tag/v1.10.1) - 2019-12-05
|
||||
* BUGFIXES
|
||||
* Fix max length check and limit in multiple repo forms (#9148) (#9204)
|
||||
* Properly fix displaying virtual session provider in admin panel (#9137) (#9203)
|
||||
* Upgrade levelqueue to 0.1.0 (#9192) (#9199)
|
||||
* Fix panic when diff (#9187) (#9193)
|
||||
* Smtp logger configuration sendTos should be an array (#9154) (#9157)
|
||||
* Always Show Password Field on Link Account Sign-in Page (#9150)
|
||||
* Create PR on Current Repository by Default (#8670) (#9141)
|
||||
* Fix race on indexer (#9136) (#9139)
|
||||
* Fix reCAPTCHA URL (#9119)
|
||||
* Hide migrated credentials (#9098)
|
||||
* Update golang.org/x/crypto vendor to use acme v2 (#9056) (#9085)
|
||||
* Fix password checks on admin create/edit user (#9076) (#9081)
|
||||
* Fix add search as a reserved username (#9063) (#9065)
|
||||
* Fix permission checks for close/reopen from commit (#8875) (#9033)
|
||||
* Ensure Written is set in GZIP ProxyResponseWriter (#9018) (#9025)
|
||||
* Fix broken link to branch from issue list (#9003) (#9021)
|
||||
* Fix wrong system notice when repository is empty (#9020)
|
||||
* Shadow password correctly for session config (#8984) (#9002)
|
||||
|
||||
## [1.10.0](https://github.com/go-gitea/gitea/releases/tag/v1.10.0) - 2019-11-13
|
||||
* BREAKING
|
||||
* Fix deadline on update issue or PR via API (#8698)
|
||||
* Hide some user information via API if user doesn't have enough permission (#8655) (#8657)
|
||||
* Remove legacy handling of drone token (#8191)
|
||||
* Change repo search to use exact match for topic search. (#7941)
|
||||
* Add pagination for admin api get orgs and fix only list public orgs bug (#7742)
|
||||
* Implement the ability to change the ssh port to match what is in the gitea config (#7286)
|
||||
* SECURITY
|
||||
* Fix issue with user.fullname (#8903)
|
||||
* Ignore mentions for users with no access (#8395)
|
||||
* Be more strict with git arguments (#7715)
|
||||
* Extract the username and password from the mirror url (#7651)
|
||||
* reserve .well-known username (#7637)
|
||||
* FEATURE
|
||||
* Org/Members: display 2FA members states + optimize sql requests (#7621)
|
||||
* SetDefaultBranch on pushing to empty repository (#7610)
|
||||
@@ -19,6 +68,41 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Add option to initialize repository with labels (#6061)
|
||||
* Add additional password hash algorithms (#6023)
|
||||
* BUGFIXES
|
||||
* Allow to merge if file path contains " or \ (#8629) (#8771)
|
||||
* On windows set core.longpaths true (#8776) (#8786)
|
||||
* Fix 500 when edit hook (#8782) (#8789)
|
||||
* Fix Checkbox at RepoSettings Protected Branch (#8799) (#8801)
|
||||
* Fix SSH2 conditional in key parsing code (#8806) (#8810)
|
||||
* Fix commit expand button to not go to commit link (#8745) (#8825)
|
||||
* Fix new user form for non-local users (#8826) (#8828)
|
||||
* Fix to close opened io resources as soon as not needed (#8839) (#8846)
|
||||
* Fix edit content button on migrated issue content (#8877) (#8884)
|
||||
* Fix require external registration password (#8885) (#8890)
|
||||
* Fix password complexity check on registration (#8887) (#8888)
|
||||
* Update Github Migration Tests (#8896) (#8938) (#8945)
|
||||
* Enable punctuations ending mentions (#8889) (#8894)
|
||||
* Add Close() method to gogitRepository (#8901) (#8956)
|
||||
* Hotfix for review actions and notifications (#8965)
|
||||
* Expose db.SetMaxOpenConns and allow non MySQL dbs to set conn pool params (#8528) (#8618)
|
||||
* Fix milestone close timestamp (#8728) (#8730)
|
||||
* Fix 500 when getting user as unauthenticated user (#8653) (#8663)
|
||||
* Fix 'New Issue Missing Milestone Comment' (#8678) (#8681)
|
||||
* Use AppSubUrl for more redirections (#8647) (#8651)
|
||||
* Add SubURL to redirect path (#8632) (#8634)
|
||||
* Fix template error on account page (#8562) (#8622)
|
||||
* Allow externalID to be UUID (#8551) (#8624)
|
||||
* Prevent removal of non-empty emoji panel following selection of duplicate (#8609) (#8623)
|
||||
* Update heatmap fixtures to restore tests (#8615) (#8616)
|
||||
* Ensure that diff stats can scroll independently of the diff (#8581) (#8621)
|
||||
* Webhook: set Content-Type for application/x-www-form-urlencoded (#8600)
|
||||
* Fix #8582 by handling empty repos (#8587) (#8594)
|
||||
* Fix bug on pull requests when transfer head repository (#8564) (#8569)
|
||||
* Add missed close in ServeBlobLFS (#8527) (#8542)
|
||||
* Ensure that GitRepo is set on Empty repositories (#8539) (#8541)
|
||||
* Fix migrate mirror 500 bug (#8526) (#8530)
|
||||
* Fix password complexity regex for special characters (#8524)
|
||||
* Prevent .code-view from overriding font on icon fonts (#8614) (#8627)
|
||||
* Allow more than 255 characters for tokens in external_login_user table (#8554)
|
||||
* Fix errors in create org UI regarding team access permission (#8506)
|
||||
* Fix bug on FindExternalUsersByProvider (#8504)
|
||||
* Create .ssh dir as necessary (#8486)
|
||||
@@ -218,10 +302,6 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Support setting cookie domain (#6288)
|
||||
* Move migrating repository from frontend to backend (#6200)
|
||||
* Delete releases attachments if release is deleted (#6068)
|
||||
* SECURITY
|
||||
* Ignore mentions for users with no access (#8395)
|
||||
* Be more strict with git arguments (#7715)
|
||||
* reserve .well-known username (#7637)
|
||||
* TRANSLATION
|
||||
* Latvian translation for home page (#8468)
|
||||
* Add home template italian translation (#8352)
|
||||
@@ -250,7 +330,6 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* Fix global search result CSS, misc CSS tweaks (#7789)
|
||||
* Tweak label border CSS (#7739)
|
||||
* Fix create menu item widths (#7708)
|
||||
* Extract the username and password from the mirror url (#7651)
|
||||
* [Branch View] Delete duplicate protection symbol (#7624)
|
||||
* [Branch View] Delete Table Header (#7622)
|
||||
* [Branch View] icons to buttons (#7602)
|
||||
@@ -263,6 +342,38 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
|
||||
* wiki - editor - add buttons 'inline code', 'empty checkbox', 'checked checkbox' (#7243)
|
||||
* Fix Statuses API only shows first 10 statuses: Add paging and extend API GetCommitStatuses (#7141)
|
||||
|
||||
## [1.9.6](https://github.com/go-gitea/gitea/releases/tag/v1.9.6) - 2019-11-13
|
||||
* BUGFIXES
|
||||
* Allow to merge if file path contains " or \ (#8629) (#8772)
|
||||
* Fix 500 when edit hook (#8782) (#8790)
|
||||
* Fix issue with user.fullname (#8904)
|
||||
* Update Github Migration Test (#8897) (#8946)
|
||||
* Add Close() method to gogitRepository (#8901) (#8958)
|
||||
|
||||
## [1.9.5](https://github.com/go-gitea/gitea/releases/tag/v1.9.5) - 2019-10-30
|
||||
* BREAKING
|
||||
* Hide some user information via API if user doesn't have enough permission (#8655) (#8658)
|
||||
* BUGFIXES
|
||||
* Fix milestone close timestamp (#8728) (#8731)
|
||||
* Fix deadline on update issue or PR via API (#8699)
|
||||
* Fix 'New Issue Missing Milestone Comment' (#8678) (#8682)
|
||||
* Fix 500 when getting user as unauthenticated user (#8653) (#8662)
|
||||
* Use AppSubUrl for more redirections (#8647) (#8652)
|
||||
* Add SubURL to redirect path (#8632) (#8634) (#8640)
|
||||
* Fix #8582 by handling empty repos (#8587) (#8593)
|
||||
* Fix bug on pull requests when transfer head repository (#8571)
|
||||
* Add missed close in ServeBlobLFS (#8527) (#8543)
|
||||
* Return false if provided branch name is empty for IsBranchExist (#8485) (#8492)
|
||||
* Create .ssh dir as necessary (#8369) (#8486) (#8489)
|
||||
* Restore functionality for early gits (#7775) (#8476)
|
||||
* Add check for empty set when dropping indexes during migration (#8475)
|
||||
* Ensure Request Body Readers are closed in LFS server (#8454) (#8459)
|
||||
* Ensure that LFS files are relative to the LFS content path (#8455) (#8458)
|
||||
* SECURITY
|
||||
* Ignore mentions for users with no access (#8395) (#8484)
|
||||
* TESTING
|
||||
* Update heatmap fixtures to restore tests (#8615) (#8617)
|
||||
|
||||
## [1.9.4](https://github.com/go-gitea/gitea/releases/tag/v1.9.4) - 2019-10-08
|
||||
* BUGFIXES
|
||||
* Highlight issue references (#8101) (#8404)
|
||||
|
@@ -375,17 +375,20 @@ func runRepoSyncReleases(c *cli.Context) error {
|
||||
|
||||
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||
log.Warn(" SyncReleasesWithTags: %v", err)
|
||||
gitRepo.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
count, err = getReleaseCount(repo.ID)
|
||||
if err != nil {
|
||||
log.Warn(" GetReleaseCountByRepoID: %v", err)
|
||||
gitRepo.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
log.Trace(" repo %s releases synchronized to tags: from %d to %d",
|
||||
repo.FullName(), oldnum, count)
|
||||
gitRepo.Close()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -277,10 +277,12 @@ LOG_SQL = true
|
||||
DB_RETRIES = 10
|
||||
; Backoff time per DB retry (time.Duration)
|
||||
DB_RETRY_BACKOFF = 3s
|
||||
; Max idle database connections on connnection pool, default is 0
|
||||
MAX_IDLE_CONNS = 0
|
||||
; Database connection max life time, default is 3s
|
||||
; Max idle database connections on connnection pool, default is 2
|
||||
MAX_IDLE_CONNS = 2
|
||||
; Database connection max life time, default is 0 or 3s mysql (See #6804 & #7071 for reasoning)
|
||||
CONN_MAX_LIFETIME = 3s
|
||||
; Database maximum number of open connections, default is 0 meaning no maximum
|
||||
MAX_OPEN_CONNS = 0
|
||||
|
||||
[indexer]
|
||||
; Issue indexer type, currently support: bleve or db, default is bleve
|
||||
@@ -333,7 +335,8 @@ IMPORT_LOCAL_PATHS = false
|
||||
; Set to true to prevent all users (including admin) from creating custom git hooks
|
||||
DISABLE_GIT_HOOKS = false
|
||||
;Comma separated list of character classes required to pass minimum complexity.
|
||||
;If left empty or no valid values are specified, the default values (`lower,upper,digit,spec`) will be used.
|
||||
;If left empty or no valid values are specified, the default values ("lower,upper,digit,spec") will be used.
|
||||
;Use "off" to disable checking.
|
||||
PASSWORD_COMPLEXITY = lower,upper,digit,spec
|
||||
; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt"
|
||||
PASSWORD_HASH_ALGO = pbkdf2
|
||||
@@ -822,6 +825,6 @@ TOKEN =
|
||||
QUEUE_TYPE = channel
|
||||
; Task queue length, available only when `QUEUE_TYPE` is `channel`.
|
||||
QUEUE_LENGTH = 1000
|
||||
; Task queue connction string, available only when `QUEUE_TYPE` is `redis`.
|
||||
; Task queue connection string, available only when `QUEUE_TYPE` is `redis`.
|
||||
; If there is a password of redis, use `addrs=127.0.0.1:6379 password=123 db=0`.
|
||||
QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"
|
||||
QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"
|
||||
|
@@ -167,8 +167,12 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
||||
- `LOG_SQL`: **true**: Log the executed SQL.
|
||||
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.
|
||||
- `DB_RETRY_BACKOFF`: **3s**: time.Duration to wait before trying another ORM init / DB connect attempt, if failure occured.
|
||||
- `MAX_IDLE_CONNS` **0**: Max idle database connections on connnection pool, default is 0
|
||||
- `CONN_MAX_LIFETIME` **3s**: Database connection max lifetime
|
||||
- `MAX_OPEN_CONNS` **0**: Database maximum open connections - default is 0, meaning there is no limit.
|
||||
- `MAX_IDLE_CONNS` **2**: Max idle database connections on connnection pool, default is 2 - this will be capped to `MAX_OPEN_CONNS`.
|
||||
- `CONN_MAX_LIFETIME` **0 or 3s**: Sets the maximum amount of time a DB connection may be reused - default is 0, meaning there is no limit (except on MySQL where it is 3s - see #6804 & #7071).
|
||||
|
||||
Please see #8540 & #8273 for further discussion of the appropriate values for `MAX_OPEN_CONNS`, `MAX_IDLE_CONNS` & `CONN_MAX_LIFETIME` and their
|
||||
relation to port exhaustion.
|
||||
|
||||
## Indexer (`indexer`)
|
||||
|
||||
@@ -212,7 +216,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
||||
- lower - use one or more lower latin characters
|
||||
- upper - use one or more upper latin characters
|
||||
- digit - use one or more digits
|
||||
- spec - use one or more special characters as ``][!"#$%&'()*+,./:;<=>?@\^_{|}~`-`` and space symbol.
|
||||
- spec - use one or more special characters as ``!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~``
|
||||
- off - do not check password complexity
|
||||
|
||||
## OpenID (`openid`)
|
||||
|
||||
|
@@ -68,6 +68,7 @@ type Uploader interface {
|
||||
CreateComment(issueNumber int64, comment *Comment) error
|
||||
CreatePullRequest(pr *PullRequest) error
|
||||
Rollback() error
|
||||
Close()
|
||||
}
|
||||
|
||||
```
|
||||
```
|
||||
|
4
go.mod
4
go.mod
@@ -4,6 +4,7 @@ go 1.13
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.45.0 // indirect
|
||||
gitea.com/lunny/levelqueue v0.1.0
|
||||
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
|
||||
gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76
|
||||
gitea.com/macaron/captcha v0.0.0-20190822015246-daa973478bae
|
||||
@@ -67,7 +68,6 @@ require (
|
||||
github.com/lafriks/xormstore v1.3.1
|
||||
github.com/lib/pq v1.2.0
|
||||
github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96
|
||||
github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e
|
||||
github.com/mailru/easyjson v0.7.0 // indirect
|
||||
github.com/markbates/goth v1.56.0
|
||||
github.com/mattn/go-isatty v0.0.7
|
||||
@@ -104,7 +104,7 @@ require (
|
||||
github.com/urfave/cli v1.20.0
|
||||
github.com/willf/bitset v0.0.0-20180426185212-8ce1146b8621 // indirect
|
||||
github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53
|
||||
golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad
|
||||
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba
|
||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
|
||||
golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b
|
||||
|
6
go.sum
6
go.sum
@@ -12,6 +12,8 @@ cloud.google.com/go v0.45.0 h1:bALuGBSgE+BD4rxsopAYlqjcwqcQtye6pWG4bC3N/k0=
|
||||
cloud.google.com/go v0.45.0/go.mod h1:452BcPOeI9AZfbvDw0Tbo7D32wA+WX9WME8AZwMEDZU=
|
||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||
gitea.com/lunny/levelqueue v0.1.0 h1:7wMk0VH6mvKN6vZEZCy9nUDgRmdPLgeNrm1NkW8EHNk=
|
||||
gitea.com/lunny/levelqueue v0.1.0/go.mod h1:G7hVb908t0Bl0uk7zGSg14fyzNtxgtD9Shf04wkMK7s=
|
||||
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b h1:vXt85uYV17KURaUlhU7v4GbCShkqRZDSfo0TkC0YCjQ=
|
||||
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b/go.mod h1:Cxadig6POWpPYYSfg23E7jo35Yf0yvsdC1lifoKWmPo=
|
||||
gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76 h1:mMsMEg90c5KXQgRWsH8D6GHXfZIW1RAe5S9VYIb12lM=
|
||||
@@ -391,8 +393,6 @@ github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:uNwtsDp7ci48vBTTxDuwcoTXz4lwtDTe7TjCQ0noaWY=
|
||||
github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96/go.mod h1:mmIfjCSQlGYXmJ95jFN84AkQFnVABtKuJL8IrzwvUKQ=
|
||||
github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e h1:GSprKUrG9wNgwQgROvjPGXmcZrg4OLslOuZGB0uJjx8=
|
||||
github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e/go.mod h1:rQZVENnBOiVakCs97XvclbwJRTAv77CRFWcYVNDkVf8=
|
||||
github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de h1:nyxwRdWHAVxpFcDThedEgQ07DbcRc5xgNObtbTp76fk=
|
||||
github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ=
|
||||
github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af h1:UaWHNBdukWrSG3DRvHFR/hyfg681fceqQDYVTBncKfQ=
|
||||
@@ -627,6 +627,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49N
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad h1:5E5raQxcv+6CZ11RrBYQe5WRbUIWpScjh0kvHZkZIrQ=
|
||||
golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE=
|
||||
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@@ -62,3 +63,61 @@ func TestAPICreateIssue(t *testing.T) {
|
||||
Title: title,
|
||||
})
|
||||
}
|
||||
|
||||
func TestAPIEditIssue(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
|
||||
issueBefore := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 9}).(*models.Issue)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
|
||||
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
assert.NoError(t, issueBefore.LoadAttributes())
|
||||
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
|
||||
assert.Equal(t, api.StateOpen, issueBefore.State())
|
||||
|
||||
session := loginUser(t, owner.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
// update values of issue
|
||||
issueState := "closed"
|
||||
removeDeadline := time.Unix(0, 0)
|
||||
milestone := int64(4)
|
||||
body := "new content!"
|
||||
title := "new title from api set"
|
||||
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repo.Name, issueBefore.Index, token)
|
||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
State: &issueState,
|
||||
Deadline: &removeDeadline,
|
||||
Milestone: &milestone,
|
||||
Body: &body,
|
||||
Title: title,
|
||||
|
||||
// ToDo change more
|
||||
})
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
var apiIssue api.Issue
|
||||
DecodeJSON(t, resp, &apiIssue)
|
||||
|
||||
issueAfter := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 9}).(*models.Issue)
|
||||
|
||||
// check deleted user
|
||||
assert.Equal(t, int64(500), issueAfter.PosterID)
|
||||
assert.NoError(t, issueAfter.LoadAttributes())
|
||||
assert.Equal(t, int64(-1), issueAfter.PosterID)
|
||||
assert.Equal(t, int64(-1), issueBefore.PosterID)
|
||||
assert.Equal(t, int64(-1), apiIssue.Poster.ID)
|
||||
|
||||
// API response
|
||||
assert.Equal(t, api.StateClosed, apiIssue.State)
|
||||
assert.Equal(t, milestone, apiIssue.Milestone.ID)
|
||||
assert.Equal(t, body, apiIssue.Body)
|
||||
assert.True(t, apiIssue.Deadline == nil)
|
||||
assert.Equal(t, title, apiIssue.Title)
|
||||
|
||||
// in database
|
||||
assert.Equal(t, api.StateClosed, issueAfter.State())
|
||||
assert.Equal(t, milestone, issueAfter.MilestoneID)
|
||||
assert.Equal(t, int64(0), int64(issueAfter.DeadlineUnix))
|
||||
assert.Equal(t, body, issueAfter.Content)
|
||||
assert.Equal(t, title, issueAfter.Title)
|
||||
}
|
||||
|
@@ -51,6 +51,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
|
||||
|
||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
err = gitRepo.CreateTag("v0.0.1", "master")
|
||||
assert.NoError(t, err)
|
||||
@@ -112,6 +113,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
|
||||
|
||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
err = gitRepo.CreateTag("v0.0.1", "master")
|
||||
assert.NoError(t, err)
|
||||
|
@@ -30,12 +30,12 @@ func getCreateFileOptions() api.CreateFileOptions {
|
||||
NewBranchName: "master",
|
||||
Message: "Making this new file new/file.txt",
|
||||
Author: api.Identity{
|
||||
Name: "John Doe",
|
||||
Email: "johndoe@example.com",
|
||||
Name: "Anne Doe",
|
||||
Email: "annedoe@example.com",
|
||||
},
|
||||
Committer: api.Identity{
|
||||
Name: "Jane Doe",
|
||||
Email: "janedoe@example.com",
|
||||
Name: "John Doe",
|
||||
Email: "johndoe@example.com",
|
||||
},
|
||||
},
|
||||
Content: contentEncoded,
|
||||
@@ -77,8 +77,8 @@ func getExpectedFileResponseForCreate(commitID, treePath string) *api.FileRespon
|
||||
HTMLURL: setting.AppURL + "user2/repo1/commit/" + commitID,
|
||||
Author: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: "Jane Doe",
|
||||
Email: "janedoe@example.com",
|
||||
Name: "Anne Doe",
|
||||
Email: "annedoe@example.com",
|
||||
},
|
||||
},
|
||||
Committer: &api.CommitUser{
|
||||
@@ -139,6 +139,7 @@ func TestAPICreateFile(t *testing.T) {
|
||||
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
|
||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
|
||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
|
||||
gitRepo.Close()
|
||||
}
|
||||
|
||||
// Test creating a file in a new branch
|
||||
|
@@ -35,8 +35,8 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
|
||||
Email: "johndoe@example.com",
|
||||
},
|
||||
Committer: api.Identity{
|
||||
Name: "Jane Doe",
|
||||
Email: "janedoe@example.com",
|
||||
Name: "Anne Doe",
|
||||
Email: "annedoe@example.com",
|
||||
},
|
||||
},
|
||||
SHA: "103ff9234cefeee5ec5361d22b49fbb04d385885",
|
||||
@@ -80,14 +80,14 @@ func getExpectedFileResponseForUpdate(commitID, treePath string) *api.FileRespon
|
||||
HTMLURL: setting.AppURL + "user2/repo1/commit/" + commitID,
|
||||
Author: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: "Jane Doe",
|
||||
Email: "janedoe@example.com",
|
||||
Name: "John Doe",
|
||||
Email: "johndoe@example.com",
|
||||
},
|
||||
},
|
||||
Committer: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: "John Doe",
|
||||
Email: "johndoe@example.com",
|
||||
Name: "Anne Doe",
|
||||
Email: "annedoe@example.com",
|
||||
},
|
||||
},
|
||||
Message: "My update of README.md\n",
|
||||
@@ -143,6 +143,7 @@ func TestAPIUpdateFile(t *testing.T) {
|
||||
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
|
||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
|
||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
|
||||
gitRepo.Close()
|
||||
}
|
||||
|
||||
// Test updating a file in a new branch
|
||||
|
@@ -74,6 +74,8 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
|
||||
repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
|
||||
// Get the commit ID of the default branch
|
||||
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
|
||||
// Make a new tag in repo1
|
||||
newTag := "test_tag"
|
||||
|
@@ -75,6 +75,8 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
|
||||
repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
|
||||
// Get the commit ID of the default branch
|
||||
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
|
||||
// Make a new tag in repo1
|
||||
newTag := "test_tag"
|
||||
|
@@ -29,6 +29,8 @@ func TestAPIGitTags(t *testing.T) {
|
||||
git.NewCommand("config", "user.email", user.Email).RunInDir(repo.RepoPath())
|
||||
|
||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, _ := gitRepo.GetBranchCommit("master")
|
||||
lTagName := "lightweightTag"
|
||||
gitRepo.CreateTag(lTagName, commit.ID.String())
|
||||
|
@@ -334,7 +334,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
|
||||
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
|
||||
respJSON := map[string]string{}
|
||||
DecodeJSON(t, resp, &respJSON)
|
||||
assert.Equal(t, respJSON["message"], "The repository with the same name already exists.")
|
||||
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,6 @@ func TestAPITeamUser(t *testing.T) {
|
||||
var user2 *api.User
|
||||
DecodeJSON(t, resp, &user2)
|
||||
user2.Created = user2.Created.In(time.Local)
|
||||
user2.LastLogin = user2.LastLogin.In(time.Local)
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
|
||||
|
||||
assert.Equal(t, convert.ToUser(user, true, false), user2)
|
||||
|
@@ -26,7 +26,7 @@ func TestUserHeatmap(t *testing.T) {
|
||||
var heatmap []*models.UserHeatmapData
|
||||
DecodeJSON(t, resp, &heatmap)
|
||||
var dummyheatmap []*models.UserHeatmapData
|
||||
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1540080000, Contributions: 1})
|
||||
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1571616000, Contributions: 1})
|
||||
|
||||
assert.Equal(t, dummyheatmap, heatmap)
|
||||
}
|
||||
|
@@ -73,6 +73,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
opts := getDeleteRepoFileOptions(repo)
|
||||
@@ -111,6 +112,8 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
opts := getDeleteRepoFileOptions(repo)
|
||||
@@ -139,6 +142,8 @@ func TestDeleteRepoFileErrors(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
|
||||
|
@@ -191,6 +191,8 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
opts := getCreateRepoFileOptions(repo)
|
||||
@@ -201,6 +203,8 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
|
||||
// asserts
|
||||
assert.Nil(t, err)
|
||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
|
||||
expectedFileResponse := getExpectedFileResponseForRepofilesCreate(commitID)
|
||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||
@@ -220,6 +224,8 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
opts := getUpdateRepoFileOptions(repo)
|
||||
@@ -230,6 +236,8 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
|
||||
// asserts
|
||||
assert.Nil(t, err)
|
||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
|
||||
expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
|
||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||
@@ -249,6 +257,8 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
opts := getUpdateRepoFileOptions(repo)
|
||||
@@ -261,6 +271,8 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
|
||||
// asserts
|
||||
assert.Nil(t, err)
|
||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
|
||||
expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.TreePath)
|
||||
// assert that the old file no longer exists in the last commit of the branch
|
||||
@@ -288,6 +300,8 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
opts := getUpdateRepoFileOptions(repo)
|
||||
@@ -300,6 +314,8 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
|
||||
// asserts
|
||||
assert.Nil(t, err)
|
||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
||||
defer gitRepo.Close()
|
||||
|
||||
commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch)
|
||||
expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
|
||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||
@@ -315,6 +331,8 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
doer := ctx.User
|
||||
|
||||
|
@@ -19,8 +19,8 @@ func TestSignup(t *testing.T) {
|
||||
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
|
||||
"user_name": "exampleUser",
|
||||
"email": "exampleUser@example.com",
|
||||
"password": "examplePassword",
|
||||
"retype": "examplePassword",
|
||||
"password": "examplePassword!1",
|
||||
"retype": "examplePassword!1",
|
||||
})
|
||||
MakeRequest(t, req, http.StatusFound)
|
||||
|
||||
|
@@ -90,6 +90,7 @@ func TestRenameReservedUsername(t *testing.T) {
|
||||
"repo",
|
||||
"template",
|
||||
"user",
|
||||
"search",
|
||||
}
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
|
@@ -533,31 +533,44 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
|
||||
}
|
||||
refMarked[key] = true
|
||||
|
||||
// only create comments for issues if user has permission for it
|
||||
if perm.IsAdmin() || perm.IsOwner() || perm.CanWrite(UnitTypeIssues) {
|
||||
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(c.Message))
|
||||
if err = CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
|
||||
return err
|
||||
}
|
||||
// FIXME: this kind of condition is all over the code, it should be consolidated in a single place
|
||||
canclose := perm.IsAdmin() || perm.IsOwner() || perm.CanWrite(UnitTypeIssues) || refIssue.PosterID == doer.ID
|
||||
cancomment := canclose || perm.CanRead(UnitTypeIssues)
|
||||
|
||||
// Don't proceed if the user can't comment
|
||||
if !cancomment {
|
||||
continue
|
||||
}
|
||||
|
||||
// Process closing/reopening keywords
|
||||
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(c.Message))
|
||||
if err = CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Only issues can be closed/reopened this way, and user needs the correct permissions
|
||||
if refIssue.IsPull || !canclose {
|
||||
continue
|
||||
}
|
||||
|
||||
// Only process closing/reopening keywords
|
||||
if ref.Action != references.XRefActionCloses && ref.Action != references.XRefActionReopens {
|
||||
continue
|
||||
}
|
||||
|
||||
// Change issue status only if the commit has been pushed to the default branch.
|
||||
// and if the repo is configured to allow only that
|
||||
// FIXME: we should be using Issue.ref if set instead of repo.DefaultBranch
|
||||
if repo.DefaultBranch != branchName && !repo.CloseIssuesViaCommitInAnyBranch {
|
||||
continue
|
||||
if !repo.CloseIssuesViaCommitInAnyBranch {
|
||||
// If the issue was specified to be in a particular branch, don't allow commits in other branches to close it
|
||||
if refIssue.Ref != "" {
|
||||
if branchName != refIssue.Ref {
|
||||
continue
|
||||
}
|
||||
// Otherwise, only process commits to the default branch
|
||||
} else if branchName != repo.DefaultBranch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// only close issues in another repo if user has push access
|
||||
if perm.IsAdmin() || perm.IsOwner() || perm.CanWrite(UnitTypeCode) {
|
||||
if err := changeIssueStatus(refRepo, refIssue, doer, ref.Action == references.XRefActionCloses); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := changeIssueStatus(refRepo, refIssue, doer, ref.Action == references.XRefActionCloses); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -219,7 +219,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
PosterID: user.ID,
|
||||
IssueID: 1,
|
||||
}
|
||||
issueBean := &Issue{RepoID: repo.ID, Index: 2}
|
||||
issueBean := &Issue{RepoID: repo.ID, Index: 4}
|
||||
|
||||
AssertNotExistsBean(t, commentBean)
|
||||
AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
@@ -273,7 +273,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
|
||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
repo.Owner = user
|
||||
|
||||
issueBean := &Issue{RepoID: repo.ID, Index: 2}
|
||||
issueBean := &Issue{RepoID: repo.ID, Index: 4}
|
||||
|
||||
AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
|
@@ -480,6 +480,12 @@ func (deletedBranch *DeletedBranch) LoadUser() {
|
||||
deletedBranch.DeletedBy = user
|
||||
}
|
||||
|
||||
// RemoveDeletedBranch removes all deleted branches
|
||||
func RemoveDeletedBranch(repoID int64, branch string) error {
|
||||
_, err := x.Where("repo_id=? AND name=?", repoID, branch).Delete(new(DeletedBranch))
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveOldDeletedBranches removes old deleted branches
|
||||
func RemoveOldDeletedBranches() {
|
||||
log.Trace("Doing: DeletedBranchesCleanup")
|
||||
|
@@ -1104,6 +1104,21 @@ func (err ErrNewIssueInsert) Error() string {
|
||||
return err.OriginalError.Error()
|
||||
}
|
||||
|
||||
// ErrReactionAlreadyExist is used when a existing reaction was try to created
|
||||
type ErrReactionAlreadyExist struct {
|
||||
Reaction string
|
||||
}
|
||||
|
||||
// IsErrReactionAlreadyExist checks if an error is a ErrReactionAlreadyExist.
|
||||
func IsErrReactionAlreadyExist(err error) bool {
|
||||
_, ok := err.(ErrReactionAlreadyExist)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrReactionAlreadyExist) Error() string {
|
||||
return fmt.Sprintf("reaction '%s' already exists", err.Reaction)
|
||||
}
|
||||
|
||||
// __________ .__ .__ __________ __
|
||||
// \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
|
||||
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
|
||||
|
@@ -28,9 +28,9 @@ type ExternalLoginUser struct {
|
||||
Description string
|
||||
AvatarURL string
|
||||
Location string
|
||||
AccessToken string
|
||||
AccessTokenSecret string
|
||||
RefreshToken string
|
||||
AccessToken string `xorm:"TEXT"`
|
||||
AccessTokenSecret string `xorm:"TEXT"`
|
||||
RefreshToken string `xorm:"TEXT"`
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func FindExternalUsersByProvider(opts FindExternalUserOptions) ([]ExternalLoginU
|
||||
}
|
||||
|
||||
// UpdateMigrationsByType updates all migrated repositories' posterid from gitServiceType to replace originalAuthorID to posterID
|
||||
func UpdateMigrationsByType(tp structs.GitServiceType, externalUserID, userID int64) error {
|
||||
func UpdateMigrationsByType(tp structs.GitServiceType, externalUserID string, userID int64) error {
|
||||
if err := UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
act_user_id: 2
|
||||
repo_id: 2
|
||||
is_private: true
|
||||
created_unix: 1540139562
|
||||
created_unix: 1571686356
|
||||
|
||||
-
|
||||
id: 2
|
||||
|
@@ -96,4 +96,17 @@
|
||||
is_closed: false
|
||||
is_pull: true
|
||||
created_unix: 946684820
|
||||
updated_unix: 978307180
|
||||
updated_unix: 978307180
|
||||
|
||||
-
|
||||
id: 9
|
||||
repo_id: 42
|
||||
index: 1
|
||||
poster_id: 500
|
||||
name: issue from deleted account
|
||||
content: content from deleted account
|
||||
is_closed: false
|
||||
is_pull: false
|
||||
created_unix: 946684830
|
||||
updated_unix: 999307200
|
||||
deadline_unix: 1019307200
|
||||
|
@@ -21,3 +21,11 @@
|
||||
content: content3
|
||||
is_closed: true
|
||||
num_issues: 0
|
||||
|
||||
-
|
||||
id: 4
|
||||
repo_id: 42
|
||||
name: milestone of repo42
|
||||
content: content random
|
||||
is_closed: false
|
||||
num_issues: 0
|
||||
|
@@ -6,7 +6,6 @@
|
||||
index: 2
|
||||
head_repo_id: 1
|
||||
base_repo_id: 1
|
||||
head_user_name: user1
|
||||
head_branch: branch1
|
||||
base_branch: master
|
||||
merge_base: 1234567890abcdef
|
||||
@@ -21,7 +20,6 @@
|
||||
index: 3
|
||||
head_repo_id: 1
|
||||
base_repo_id: 1
|
||||
head_user_name: user1
|
||||
head_branch: branch2
|
||||
base_branch: master
|
||||
merge_base: fedcba9876543210
|
||||
@@ -35,7 +33,6 @@
|
||||
index: 1
|
||||
head_repo_id: 11
|
||||
base_repo_id: 10
|
||||
head_user_name: user13
|
||||
head_branch: branch2
|
||||
base_branch: master
|
||||
merge_base: 0abcb056019adb83
|
||||
|
@@ -547,7 +547,8 @@
|
||||
is_private: false
|
||||
num_stars: 0
|
||||
num_forks: 0
|
||||
num_issues: 0
|
||||
num_issues: 1
|
||||
num_milestones: 1
|
||||
is_mirror: false
|
||||
|
||||
-
|
||||
|
@@ -17,6 +17,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Error("Could not open repository")
|
||||
}
|
||||
defer currentRepo.Close()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
graph, err := GetCommitGraph(currentRepo)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@@ -238,6 +239,16 @@ func (issue *Issue) loadReactions(e Engine) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (issue *Issue) loadMilestone(e Engine) (err error) {
|
||||
if issue.Milestone == nil && issue.MilestoneID > 0 {
|
||||
issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
|
||||
if err != nil && !IsErrMilestoneNotExist(err) {
|
||||
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (issue *Issue) loadAttributes(e Engine) (err error) {
|
||||
if err = issue.loadRepo(e); err != nil {
|
||||
return
|
||||
@@ -251,11 +262,8 @@ func (issue *Issue) loadAttributes(e Engine) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if issue.Milestone == nil && issue.MilestoneID > 0 {
|
||||
issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
|
||||
if err != nil && !IsErrMilestoneNotExist(err) {
|
||||
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
|
||||
}
|
||||
if err = issue.loadMilestone(e); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = issue.loadAssignees(e); err != nil {
|
||||
@@ -295,6 +303,11 @@ func (issue *Issue) LoadAttributes() error {
|
||||
return issue.loadAttributes(x)
|
||||
}
|
||||
|
||||
// LoadMilestone load milestone of this issue.
|
||||
func (issue *Issue) LoadMilestone() error {
|
||||
return issue.loadMilestone(x)
|
||||
}
|
||||
|
||||
// GetIsRead load the `IsRead` field of the issue
|
||||
func (issue *Issue) GetIsRead(userID int64) error {
|
||||
issueUser := &IssueUser{IssueID: issue.ID, UID: userID}
|
||||
@@ -1072,6 +1085,10 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
|
||||
if _, err = e.Exec("UPDATE `milestone` SET num_issues=num_issues+1 WHERE id=?", opts.Issue.MilestoneID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = createMilestoneComment(e, doer, opts.Repo, opts.Issue, 0, opts.Issue.MilestoneID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the assignees
|
||||
@@ -1726,22 +1743,17 @@ func SearchIssueIDsByKeyword(kw string, repoID int64, limit, start int) (int64,
|
||||
return total, ids, nil
|
||||
}
|
||||
|
||||
func updateIssue(e Engine, issue *Issue) error {
|
||||
_, err := e.ID(issue.ID).AllCols().Update(issue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateIssue updates all fields of given issue.
|
||||
func UpdateIssue(issue *Issue) error {
|
||||
// UpdateIssueByAPI updates all allowed fields of given issue.
|
||||
func UpdateIssueByAPI(issue *Issue) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updateIssue(sess, issue); err != nil {
|
||||
if _, err := sess.ID(issue.ID).Cols(
|
||||
"name", "is_closed", "content", "milestone_id", "priority",
|
||||
"deadline_unix", "updated_unix", "closed_unix", "is_locked").
|
||||
Update(issue); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := issue.neuterCrossReferences(sess); err != nil {
|
||||
@@ -1950,7 +1962,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
|
||||
}
|
||||
|
||||
// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
|
||||
func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID, posterID int64) error {
|
||||
func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := x.Table("issue").
|
||||
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
|
||||
And("original_author_id = ?", originalAuthorID).
|
||||
|
@@ -538,6 +538,10 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
|
||||
switch opts.Type {
|
||||
case CommentTypeCode:
|
||||
if comment.ReviewID != 0 {
|
||||
// Hotfix for 1.10.0 as the Review object has not yet been committed in the other session
|
||||
if opts.Review != nil {
|
||||
comment.Review = opts.Review
|
||||
}
|
||||
if comment.Review == nil {
|
||||
if err := comment.loadReview(e); err != nil {
|
||||
return err
|
||||
@@ -596,6 +600,12 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
|
||||
if err = opts.Issue.updateClosedNum(e); err != nil {
|
||||
return err
|
||||
}
|
||||
case CommentTypeReview:
|
||||
// Hotfix for 1.10.0; make sure a dashboard entry is created
|
||||
if opts.Content == "" {
|
||||
return nil
|
||||
}
|
||||
act.OpType = ActionCommentIssue
|
||||
}
|
||||
// update the issue's updated_unix column
|
||||
if err = updateIssueCols(e, opts.Issue, "updated_unix"); err != nil {
|
||||
@@ -751,11 +761,12 @@ func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dep
|
||||
|
||||
// CreateCommentOptions defines options for creating comment
|
||||
type CreateCommentOptions struct {
|
||||
Type CommentType
|
||||
Doer *User
|
||||
Repo *Repository
|
||||
Issue *Issue
|
||||
Label *Label
|
||||
Type CommentType
|
||||
Doer *User
|
||||
Repo *Repository
|
||||
Issue *Issue
|
||||
Label *Label
|
||||
Review *Review
|
||||
|
||||
DependentIssueID int64
|
||||
OldMilestoneID int64
|
||||
@@ -1025,7 +1036,7 @@ func FetchCodeComments(issue *Issue, currentUser *User) (CodeComments, error) {
|
||||
}
|
||||
|
||||
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
|
||||
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID, posterID int64) error {
|
||||
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := x.Table("comment").
|
||||
Where(builder.In("issue_id",
|
||||
builder.Select("issue.id").
|
||||
|
@@ -306,7 +306,11 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
|
||||
}
|
||||
|
||||
m.IsClosed = isClosed
|
||||
if _, err := sess.ID(m.ID).Cols("is_closed").Update(m); err != nil {
|
||||
if isClosed {
|
||||
m.ClosedDateUnix = timeutil.TimeStampNow()
|
||||
}
|
||||
|
||||
if _, err := sess.ID(m.ID).Cols("is_closed", "closed_date_unix").Update(m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,8 @@ type Reaction struct {
|
||||
type FindReactionsOptions struct {
|
||||
IssueID int64
|
||||
CommentID int64
|
||||
UserID int64
|
||||
Reaction string
|
||||
}
|
||||
|
||||
func (opts *FindReactionsOptions) toConds() builder.Cond {
|
||||
@@ -40,6 +42,13 @@ func (opts *FindReactionsOptions) toConds() builder.Cond {
|
||||
if opts.CommentID > 0 {
|
||||
cond = cond.And(builder.Eq{"reaction.comment_id": opts.CommentID})
|
||||
}
|
||||
if opts.UserID > 0 {
|
||||
cond = cond.And(builder.Eq{"reaction.user_id": opts.UserID})
|
||||
}
|
||||
if opts.Reaction != "" {
|
||||
cond = cond.And(builder.Eq{"reaction.type": opts.Reaction})
|
||||
}
|
||||
|
||||
return cond
|
||||
}
|
||||
|
||||
@@ -57,9 +66,25 @@ func createReaction(e *xorm.Session, opts *ReactionOptions) (*Reaction, error) {
|
||||
UserID: opts.Doer.ID,
|
||||
IssueID: opts.Issue.ID,
|
||||
}
|
||||
findOpts := FindReactionsOptions{
|
||||
IssueID: opts.Issue.ID,
|
||||
CommentID: -1, // reaction to issue only
|
||||
Reaction: opts.Type,
|
||||
UserID: opts.Doer.ID,
|
||||
}
|
||||
if opts.Comment != nil {
|
||||
reaction.CommentID = opts.Comment.ID
|
||||
findOpts.CommentID = opts.Comment.ID
|
||||
}
|
||||
|
||||
existingR, err := findReactions(e, findOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(existingR) > 0 {
|
||||
return existingR[0], ErrReactionAlreadyExist{Reaction: opts.Type}
|
||||
}
|
||||
|
||||
if _, err := e.Insert(reaction); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -76,19 +101,19 @@ type ReactionOptions struct {
|
||||
}
|
||||
|
||||
// CreateReaction creates reaction for issue or comment.
|
||||
func CreateReaction(opts *ReactionOptions) (reaction *Reaction, err error) {
|
||||
func CreateReaction(opts *ReactionOptions) (*Reaction, error) {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err = sess.Begin(); err != nil {
|
||||
if err := sess.Begin(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reaction, err = createReaction(sess, opts)
|
||||
reaction, err := createReaction(sess, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return reaction, err
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
if err := sess.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return reaction, nil
|
||||
|
@@ -50,9 +50,10 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
|
||||
Type: "heart",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, reaction)
|
||||
assert.Equal(t, ErrReactionAlreadyExist{Reaction: "heart"}, err)
|
||||
|
||||
AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID})
|
||||
existingR := AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}).(*Reaction)
|
||||
assert.Equal(t, existingR.ID, reaction.ID)
|
||||
}
|
||||
|
||||
func TestIssueDeleteReaction(t *testing.T) {
|
||||
@@ -129,7 +130,6 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
||||
user4 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
|
||||
ghost := NewGhostUser()
|
||||
|
||||
issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
|
||||
@@ -139,14 +139,13 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
addReaction(t, user2, issue1, comment1, "heart")
|
||||
addReaction(t, user3, issue1, comment1, "heart")
|
||||
addReaction(t, user4, issue1, comment1, "+1")
|
||||
addReaction(t, ghost, issue1, comment1, "heart")
|
||||
|
||||
err := comment1.LoadReactions()
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, comment1.Reactions, 5)
|
||||
assert.Len(t, comment1.Reactions, 4)
|
||||
|
||||
reactions := comment1.Reactions.GroupByType()
|
||||
assert.Len(t, reactions["heart"], 4)
|
||||
assert.Len(t, reactions["heart"], 3)
|
||||
assert.Len(t, reactions["+1"], 1)
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ func TestIssueCommentReactionCount(t *testing.T) {
|
||||
comment1 := AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
|
||||
addReaction(t, user1, issue1, comment1, "heart")
|
||||
DeleteCommentReaction(user1, issue1, comment1, "heart")
|
||||
assert.NoError(t, DeleteCommentReaction(user1, issue1, comment1, "heart"))
|
||||
|
||||
AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID})
|
||||
}
|
||||
|
@@ -256,6 +256,10 @@ var migrations = []Migration{
|
||||
NewMigration("add task table and status column for repository table", addTaskTable),
|
||||
// v100 -> v101
|
||||
NewMigration("update migration repositories' service type", updateMigrationServiceTypes),
|
||||
// v101 -> v102
|
||||
NewMigration("change length of some external login users columns", changeSomeColumnsLengthOfExternalLoginUser),
|
||||
// v102 -> v103
|
||||
NewMigration("update migration repositories' service type", dropColumnHeadUserNameOnPullRequest),
|
||||
}
|
||||
|
||||
// Migrate database to current version
|
||||
|
19
models/migrations/v101.go
Normal file
19
models/migrations/v101.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func changeSomeColumnsLengthOfExternalLoginUser(x *xorm.Engine) error {
|
||||
type ExternalLoginUser struct {
|
||||
AccessToken string `xorm:"TEXT"`
|
||||
AccessTokenSecret string `xorm:"TEXT"`
|
||||
RefreshToken string `xorm:"TEXT"`
|
||||
}
|
||||
|
||||
return x.Sync2(new(ExternalLoginUser))
|
||||
}
|
15
models/migrations/v102.go
Normal file
15
models/migrations/v102.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func dropColumnHeadUserNameOnPullRequest(x *xorm.Engine) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
return dropTableColumns(sess, "pull_request", "head_user_name")
|
||||
}
|
@@ -47,6 +47,7 @@ func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error {
|
||||
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||
log.Warn("SyncReleasesWithTags: %v", err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
}
|
||||
if len(repos) < pageSize {
|
||||
break
|
||||
|
@@ -91,6 +91,7 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
gitRepoCache[release.RepoID] = gitRepo
|
||||
}
|
||||
|
||||
|
@@ -157,11 +157,9 @@ func SetEngine() (err error) {
|
||||
// so use log file to instead print to stdout.
|
||||
x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
|
||||
x.ShowSQL(setting.Database.LogSQL)
|
||||
if setting.Database.UseMySQL {
|
||||
x.SetMaxIdleConns(setting.Database.MaxIdleConns)
|
||||
x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
|
||||
}
|
||||
|
||||
x.SetMaxOpenConns(setting.Database.MaxOpenConns)
|
||||
x.SetMaxIdleConns(setting.Database.MaxIdleConns)
|
||||
x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -66,7 +66,6 @@ type PullRequest struct {
|
||||
HeadRepo *Repository `xorm:"-"`
|
||||
BaseRepoID int64 `xorm:"INDEX"`
|
||||
BaseRepo *Repository `xorm:"-"`
|
||||
HeadUserName string
|
||||
HeadBranch string
|
||||
BaseBranch string
|
||||
ProtectedBranch *ProtectedBranch `xorm:"-"`
|
||||
@@ -79,6 +78,15 @@ type PullRequest struct {
|
||||
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
|
||||
}
|
||||
|
||||
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
||||
func (pr *PullRequest) MustHeadUserName() string {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return ""
|
||||
}
|
||||
return pr.HeadRepo.MustOwnerName()
|
||||
}
|
||||
|
||||
// Note: don't try to get Issue because will end up recursive querying.
|
||||
func (pr *PullRequest) loadAttributes(e Engine) (err error) {
|
||||
if pr.HasMerged && pr.Merger == nil {
|
||||
@@ -102,6 +110,10 @@ func (pr *PullRequest) LoadAttributes() error {
|
||||
// LoadBaseRepo loads pull request base repository from database
|
||||
func (pr *PullRequest) LoadBaseRepo() error {
|
||||
if pr.BaseRepo == nil {
|
||||
if pr.HeadRepoID == pr.BaseRepoID && pr.HeadRepo != nil {
|
||||
pr.BaseRepo = pr.HeadRepo
|
||||
return nil
|
||||
}
|
||||
var repo Repository
|
||||
if has, err := x.ID(pr.BaseRepoID).Get(&repo); err != nil {
|
||||
return err
|
||||
@@ -113,6 +125,24 @@ func (pr *PullRequest) LoadBaseRepo() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadHeadRepo loads pull request head repository from database
|
||||
func (pr *PullRequest) LoadHeadRepo() error {
|
||||
if pr.HeadRepo == nil {
|
||||
if pr.HeadRepoID == pr.BaseRepoID && pr.BaseRepo != nil {
|
||||
pr.HeadRepo = pr.BaseRepo
|
||||
return nil
|
||||
}
|
||||
var repo Repository
|
||||
if has, err := x.ID(pr.HeadRepoID).Get(&repo); err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return ErrRepoNotExist{ID: pr.BaseRepoID}
|
||||
}
|
||||
pr.HeadRepo = &repo
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadIssue loads issue information from database
|
||||
func (pr *PullRequest) LoadIssue() (err error) {
|
||||
return pr.loadIssue(x)
|
||||
@@ -152,7 +182,7 @@ func (pr *PullRequest) GetDefaultMergeMessage() string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.HeadUserName, pr.HeadRepo.Name, pr.BaseBranch)
|
||||
return fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.MustHeadUserName(), pr.HeadRepo.Name, pr.BaseBranch)
|
||||
}
|
||||
|
||||
// GetDefaultSquashMessage returns default message used when squash and merging pull request
|
||||
@@ -352,6 +382,7 @@ func (pr *PullRequest) GetLastCommitStatus() (status *CommitStatus, err error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer headGitRepo.Close()
|
||||
|
||||
lastCommitID, err := headGitRepo.GetBranchCommitID(pr.HeadBranch)
|
||||
if err != nil {
|
||||
@@ -541,6 +572,7 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, err := gitRepo.GetCommit(mergeCommit[:40])
|
||||
if err != nil {
|
||||
@@ -925,6 +957,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer headGitRepo.Close()
|
||||
|
||||
// Add a temporary remote.
|
||||
tmpRemote := com.ToStr(time.Now().UnixNano())
|
||||
@@ -966,6 +999,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer headGitRepo.Close()
|
||||
|
||||
tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID)
|
||||
if err = headGitRepo.AddRemote(tmpRemoteName, pr.BaseRepo.RepoPath(), false); err != nil {
|
||||
@@ -1155,22 +1189,11 @@ func checkForInvalidation(requests PullRequestList, repoID int64, doer *User, br
|
||||
if err != nil {
|
||||
log.Error("PullRequestList.InvalidateCodeComments: %v", err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeUsernameInPullRequests changes the name of head_user_name
|
||||
func ChangeUsernameInPullRequests(oldUserName, newUserName string) error {
|
||||
pr := PullRequest{
|
||||
HeadUserName: strings.ToLower(newUserName),
|
||||
}
|
||||
_, err := x.
|
||||
Cols("head_user_name").
|
||||
Where("head_user_name = ?", strings.ToLower(oldUserName)).
|
||||
Update(pr)
|
||||
return err
|
||||
}
|
||||
|
||||
// checkAndUpdateStatus checks if pull request is possible to leaving checking status,
|
||||
// and set to be either conflict or mergeable.
|
||||
func (pr *PullRequest) checkAndUpdateStatus() {
|
||||
|
@@ -232,20 +232,6 @@ func TestPullRequestList_LoadAttributes(t *testing.T) {
|
||||
|
||||
// TODO TestAddTestPullRequestTask
|
||||
|
||||
func TestChangeUsernameInPullRequests(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
const newUsername = "newusername"
|
||||
assert.NoError(t, ChangeUsernameInPullRequests("user1", newUsername))
|
||||
|
||||
prs := make([]*PullRequest, 0, 10)
|
||||
assert.NoError(t, x.Where("head_user_name = ?", newUsername).Find(&prs))
|
||||
assert.Len(t, prs, 2)
|
||||
for _, pr := range prs {
|
||||
assert.Equal(t, newUsername, pr.HeadUserName)
|
||||
}
|
||||
CheckConsistencyFor(t, &PullRequest{})
|
||||
}
|
||||
|
||||
func TestPullRequest_IsWorkInProgress(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
|
@@ -369,7 +369,7 @@ func SyncReleasesWithTags(repo *Repository, gitRepo *git.Repository) error {
|
||||
}
|
||||
|
||||
// UpdateReleasesMigrationsByType updates all migrated repositories' releases from gitServiceType to replace originalAuthorID to posterID
|
||||
func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID, posterID int64) error {
|
||||
func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := x.Table("release").
|
||||
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
|
||||
And("original_author_id = ?", originalAuthorID).
|
||||
|
@@ -998,6 +998,7 @@ func MigrateRepositoryGitData(doer, u *User, repo *Repository, opts api.MigrateR
|
||||
if err != nil {
|
||||
return repo, fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
repo.IsEmpty, err = gitRepo.IsEmpty()
|
||||
if err != nil {
|
||||
@@ -1430,6 +1431,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
|
||||
IsFsckEnabled: !opts.IsMirror,
|
||||
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
|
||||
Status: opts.Status,
|
||||
IsEmpty: !opts.AutoInit,
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
@@ -1779,6 +1781,12 @@ func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// UpdateRepositoryStatus updates a repository's status
|
||||
func UpdateRepositoryStatus(repoID int64, status RepositoryStatus) error {
|
||||
_, err := x.Exec("UPDATE repository SET status = ? WHERE id = ?", status, repoID)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateRepositoryUpdatedTime updates a repository's updated time
|
||||
func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error {
|
||||
_, err := x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", updateTime.Unix(), repoID)
|
||||
@@ -1858,6 +1866,17 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||
}
|
||||
}
|
||||
|
||||
attachments := make([]*Attachment, 0, 20)
|
||||
if err = sess.Join("INNER", "`release`", "`release`.id = `attachment`.release_id").
|
||||
Where("`release`.repo_id = ?", repoID).
|
||||
Find(&attachments); err != nil {
|
||||
return err
|
||||
}
|
||||
releaseAttachments := make([]string, 0, len(attachments))
|
||||
for i := 0; i < len(attachments); i++ {
|
||||
releaseAttachments = append(releaseAttachments, attachments[i].LocalPath())
|
||||
}
|
||||
|
||||
if err = deleteBeans(sess,
|
||||
&Access{RepoID: repo.ID},
|
||||
&Action{RepoID: repo.ID},
|
||||
@@ -1908,13 +1927,13 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
attachmentPaths := make([]string, 0, 20)
|
||||
attachments := make([]*Attachment, 0, len(attachmentPaths))
|
||||
attachments = attachments[:0]
|
||||
if err = sess.Join("INNER", "issue", "issue.id = attachment.issue_id").
|
||||
Where("issue.repo_id = ?", repoID).
|
||||
Find(&attachments); err != nil {
|
||||
return err
|
||||
}
|
||||
attachmentPaths := make([]string, 0, len(attachments))
|
||||
for j := range attachments {
|
||||
attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
|
||||
}
|
||||
@@ -1951,11 +1970,6 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Remove attachment files.
|
||||
for i := range attachmentPaths {
|
||||
removeAllWithNotice(sess, "Delete attachment", attachmentPaths[i])
|
||||
}
|
||||
|
||||
// Remove LFS objects
|
||||
var lfsObjects []*LFSMetaObject
|
||||
if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
|
||||
@@ -1995,6 +2009,8 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
}
|
||||
|
||||
sess.Close()
|
||||
|
||||
if org.IsOrganization() {
|
||||
if err = PrepareWebhooks(repo, HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoDeleted,
|
||||
@@ -2007,6 +2023,19 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||
go HookQueue.Add(repo.ID)
|
||||
}
|
||||
|
||||
// We should always delete the files after the database transaction succeed. If
|
||||
// we delete the file but the database rollback, the repository will be borken.
|
||||
|
||||
// Remove issue attachment files.
|
||||
for i := range attachmentPaths {
|
||||
removeAllWithNotice(x, "Delete issue attachment", attachmentPaths[i])
|
||||
}
|
||||
|
||||
// Remove release attachment files.
|
||||
for i := range releaseAttachments {
|
||||
removeAllWithNotice(x, "Delete release attachment", releaseAttachments[i])
|
||||
}
|
||||
|
||||
if len(repo.Avatar) > 0 {
|
||||
avatarPath := repo.CustomAvatarPath()
|
||||
if com.IsExist(avatarPath) {
|
||||
@@ -2782,3 +2811,9 @@ func (repo *Repository) GetOriginalURLHostname() string {
|
||||
|
||||
return u.Host
|
||||
}
|
||||
|
||||
// UpdateRepositoryCols updates repository's columns
|
||||
func UpdateRepositoryCols(repo *Repository, cols ...string) error {
|
||||
_, err := x.ID(repo.ID).Cols(cols...).Update(repo)
|
||||
return err
|
||||
}
|
||||
|
@@ -64,6 +64,8 @@ func GetActivityStats(repo *Repository, timeFrom time.Time, releases, issues, pr
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FillFromGit: %v", err)
|
||||
@@ -79,6 +81,8 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
code, err := gitRepo.GetCodeActivityStats(timeFrom, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FillFromGit: %v", err)
|
||||
|
@@ -23,6 +23,7 @@ func (repo *Repository) GetBranch(branch string) (*git.Branch, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
return gitRepo.GetBranch(branch)
|
||||
}
|
||||
@@ -38,6 +39,7 @@ func (repo *Repository) CheckBranchName(name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
branches, err := repo.GetBranches()
|
||||
if err != nil {
|
||||
@@ -94,6 +96,7 @@ func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName st
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if err = gitRepo.CreateBranch(branchName, oldBranchName); err != nil {
|
||||
log.Error("Unable to create branch: %s from %s. (%v)", branchName, oldBranchName, err)
|
||||
@@ -140,6 +143,7 @@ func (repo *Repository) CreateNewBranchFromCommit(doer *User, commit, branchName
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if err = gitRepo.CreateBranch(branchName, commit); err != nil {
|
||||
log.Error("Unable to create branch: %s from %s. (%v)", branchName, commit, err)
|
||||
|
@@ -58,7 +58,7 @@ func (repo *Repository) updateIndexerStatus(sha string) error {
|
||||
}
|
||||
|
||||
type repoIndexerOperation struct {
|
||||
repo *Repository
|
||||
repoID int64
|
||||
deleted bool
|
||||
watchers []chan<- error
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func populateRepoIndexer(maxRepoID int64) {
|
||||
}
|
||||
for _, repo := range repos {
|
||||
repoIndexerOperationQueue <- repoIndexerOperation{
|
||||
repo: repo,
|
||||
repoID: repo.ID,
|
||||
deleted: false,
|
||||
}
|
||||
maxRepoID = repo.ID - 1
|
||||
@@ -131,7 +131,12 @@ func populateRepoIndexer(maxRepoID int64) {
|
||||
log.Info("Done populating the repo indexer with existing repositories")
|
||||
}
|
||||
|
||||
func updateRepoIndexer(repo *Repository) error {
|
||||
func updateRepoIndexer(repoID int64) error {
|
||||
repo, err := getRepositoryByID(x, repoID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sha, err := getDefaultBranchSha(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -172,7 +177,7 @@ type fileUpdate struct {
|
||||
}
|
||||
|
||||
func getDefaultBranchSha(repo *Repository) (string, error) {
|
||||
stdout, err := git.NewCommand("show-ref", "-s", repo.DefaultBranch).RunInDir(repo.RepoPath())
|
||||
stdout, err := git.NewCommand("show-ref", "-s", git.BranchPrefix+repo.DefaultBranch).RunInDir(repo.RepoPath())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -339,11 +344,11 @@ func processRepoIndexerOperationQueue() {
|
||||
op := <-repoIndexerOperationQueue
|
||||
var err error
|
||||
if op.deleted {
|
||||
if err = indexer.DeleteRepoFromIndexer(op.repo.ID); err != nil {
|
||||
if err = indexer.DeleteRepoFromIndexer(op.repoID); err != nil {
|
||||
log.Error("DeleteRepoFromIndexer: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err = updateRepoIndexer(op.repo); err != nil {
|
||||
if err = updateRepoIndexer(op.repoID); err != nil {
|
||||
log.Error("updateRepoIndexer: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -355,12 +360,12 @@ func processRepoIndexerOperationQueue() {
|
||||
|
||||
// DeleteRepoFromIndexer remove all of a repository's entries from the indexer
|
||||
func DeleteRepoFromIndexer(repo *Repository, watchers ...chan<- error) {
|
||||
addOperationToQueue(repoIndexerOperation{repo: repo, deleted: true, watchers: watchers})
|
||||
addOperationToQueue(repoIndexerOperation{repoID: repo.ID, deleted: true, watchers: watchers})
|
||||
}
|
||||
|
||||
// UpdateRepoIndexer update a repository's entries in the indexer
|
||||
func UpdateRepoIndexer(repo *Repository, watchers ...chan<- error) {
|
||||
addOperationToQueue(repoIndexerOperation{repo: repo, deleted: false, watchers: watchers})
|
||||
addOperationToQueue(repoIndexerOperation{repoID: repo.ID, deleted: false, watchers: watchers})
|
||||
}
|
||||
|
||||
func addOperationToQueue(op repoIndexerOperation) {
|
||||
|
@@ -1,24 +0,0 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
)
|
||||
|
||||
// GetTagsByPath returns repo tags by its path
|
||||
func GetTagsByPath(path string) ([]*git.Tag, error) {
|
||||
gitRepo, err := git.OpenRepository(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gitRepo.GetTagInfos()
|
||||
}
|
||||
|
||||
// GetTags return repo's tags
|
||||
func (repo *Repository) GetTags() ([]*git.Tag, error) {
|
||||
return GetTagsByPath(repo.RepoPath())
|
||||
}
|
@@ -135,6 +135,7 @@ func (r *Review) publish(e *xorm.Engine) error {
|
||||
Repo: review.Issue.Repo,
|
||||
Type: comm.Type,
|
||||
Content: comm.Content,
|
||||
Review: r,
|
||||
}, comm); err != nil {
|
||||
log.Warn("sendCreateCommentAction: %v", err)
|
||||
}
|
||||
|
@@ -107,7 +107,7 @@ func parseKeyString(content string) (string, error) {
|
||||
|
||||
var keyType, keyContent, keyComment string
|
||||
|
||||
if content[:len(ssh2keyStart)] == ssh2keyStart {
|
||||
if strings.HasPrefix(content, ssh2keyStart) {
|
||||
// Parse SSH2 file format.
|
||||
|
||||
// Transform all legal line endings to a single "\n".
|
||||
|
@@ -131,6 +131,19 @@ AAAAC3NzaC1lZDI1NTE5AAAAICV0MGX/W9IvLA4FXpIuUcdDcbj5KX4syHgsTy7soVgf
|
||||
_, err := CheckPublicKeyString(test.content)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
for _, invalidKeys := range []struct {
|
||||
content string
|
||||
}{
|
||||
{"test"},
|
||||
{"---- NOT A REAL KEY ----"},
|
||||
{"bad\nkey"},
|
||||
{"\t\t:)\t\r\n"},
|
||||
{"\r\ntest \r\ngitea\r\n\r\n"},
|
||||
} {
|
||||
_, err := CheckPublicKeyString(invalidKeys.content)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_calcFingerprint(t *testing.T) {
|
||||
|
@@ -196,7 +196,7 @@ func CreateMigrateTask(doer, u *User, opts base.MigrateOptions) (*Task, error) {
|
||||
repo, err := CreateRepository(doer, u, CreateRepoOptions{
|
||||
Name: opts.RepoName,
|
||||
Description: opts.Description,
|
||||
OriginalURL: opts.CloneAddr,
|
||||
OriginalURL: opts.OriginalURL,
|
||||
IsPrivate: opts.Private,
|
||||
IsMirror: opts.Mirror,
|
||||
Status: RepositoryBeingMigrated,
|
||||
|
@@ -822,6 +822,7 @@ var (
|
||||
".",
|
||||
"..",
|
||||
".well-known",
|
||||
"search",
|
||||
}
|
||||
reservedUserPatterns = []string{"*.keys", "*.gpg"}
|
||||
)
|
||||
@@ -994,10 +995,6 @@ func ChangeUserName(u *User, newUserName string) (err error) {
|
||||
return ErrUserAlreadyExist{newUserName}
|
||||
}
|
||||
|
||||
if err = ChangeUsernameInPullRequests(u.Name, newUserName); err != nil {
|
||||
return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
|
||||
}
|
||||
|
||||
// Do not fail if directory does not exist
|
||||
if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("Rename user directory: %v", err)
|
||||
|
@@ -17,7 +17,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
||||
CountResult int
|
||||
JSONResult string
|
||||
}{
|
||||
{2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
|
||||
{2, 1, `[{"timestamp":1571616000,"contributions":1}]`},
|
||||
{3, 0, `[]`},
|
||||
}
|
||||
// Prepare
|
||||
@@ -41,7 +41,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
||||
// Get the heatmap and compare
|
||||
heatmap, err := GetUserHeatmapDataByUser(user)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(actions), len(heatmap))
|
||||
assert.Equal(t, len(actions), len(heatmap), "invalid action count: did the test data became too old?")
|
||||
assert.Equal(t, tc.CountResult, len(heatmap))
|
||||
|
||||
//Test JSON rendering
|
||||
|
@@ -833,6 +833,8 @@ func (t *HookTask) deliver() error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
case http.MethodGet:
|
||||
u, err := url.Parse(t.URL)
|
||||
|
@@ -36,10 +36,11 @@ type SlackPayload struct {
|
||||
|
||||
// SlackAttachment contains the slack message
|
||||
type SlackAttachment struct {
|
||||
Fallback string `json:"fallback"`
|
||||
Color string `json:"color"`
|
||||
Title string `json:"title"`
|
||||
Text string `json:"text"`
|
||||
Fallback string `json:"fallback"`
|
||||
Color string `json:"color"`
|
||||
Title string `json:"title"`
|
||||
TitleLink string `json:"title_link"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// SetSecret sets the slack secret
|
||||
@@ -133,70 +134,78 @@ func getSlackForkPayload(p *api.ForkPayload, slack *SlackMeta) (*SlackPayload, e
|
||||
|
||||
func getSlackIssuesPayload(p *api.IssuePayload, slack *SlackMeta) (*SlackPayload, error) {
|
||||
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
|
||||
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
|
||||
fmt.Sprintf("#%d %s", p.Index, p.Issue.Title))
|
||||
var text, title, attachmentText string
|
||||
title := SlackTextFormatter(fmt.Sprintf("#%d %s", p.Index, p.Issue.Title))
|
||||
titleLink := fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Index)
|
||||
repoLink := SlackLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName)
|
||||
var text, attachmentText string
|
||||
|
||||
switch p.Action {
|
||||
case api.HookIssueOpened:
|
||||
text = fmt.Sprintf("[%s] Issue submitted by %s", p.Repository.FullName, senderLink)
|
||||
title = titleLink
|
||||
text = fmt.Sprintf("[%s] Issue opened by %s", repoLink, senderLink)
|
||||
attachmentText = SlackTextFormatter(p.Issue.Body)
|
||||
case api.HookIssueClosed:
|
||||
text = fmt.Sprintf("[%s] Issue closed: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue closed: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueReOpened:
|
||||
text = fmt.Sprintf("[%s] Issue re-opened: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue re-opened: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueEdited:
|
||||
text = fmt.Sprintf("[%s] Issue edited: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue edited: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
attachmentText = SlackTextFormatter(p.Issue.Body)
|
||||
case api.HookIssueAssigned:
|
||||
text = fmt.Sprintf("[%s] Issue assigned to %s: %s by %s", p.Repository.FullName,
|
||||
text = fmt.Sprintf("[%s] Issue assigned to %s: [%s](%s) by %s", repoLink,
|
||||
SlackLinkFormatter(setting.AppURL+p.Issue.Assignee.UserName, p.Issue.Assignee.UserName),
|
||||
titleLink, senderLink)
|
||||
title, titleLink, senderLink)
|
||||
case api.HookIssueUnassigned:
|
||||
text = fmt.Sprintf("[%s] Issue unassigned: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue unassigned: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueLabelUpdated:
|
||||
text = fmt.Sprintf("[%s] Issue labels updated: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue labels updated: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueLabelCleared:
|
||||
text = fmt.Sprintf("[%s] Issue labels cleared: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue labels cleared: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueSynchronized:
|
||||
text = fmt.Sprintf("[%s] Issue synchronized: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue synchronized: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueMilestoned:
|
||||
text = fmt.Sprintf("[%s] Issue milestoned: #%s %s", p.Repository.FullName, titleLink, senderLink)
|
||||
mileStoneLink := fmt.Sprintf("%s/milestone/%d", p.Repository.HTMLURL, p.Issue.Milestone.ID)
|
||||
text = fmt.Sprintf("[%s] Issue milestoned to [%s](%s): [%s](%s) by %s", repoLink,
|
||||
p.Issue.Milestone.Title, mileStoneLink, title, titleLink, senderLink)
|
||||
case api.HookIssueDemilestoned:
|
||||
text = fmt.Sprintf("[%s] Issue milestone cleared: #%s %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Issue milestone cleared: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
}
|
||||
|
||||
return &SlackPayload{
|
||||
pl := &SlackPayload{
|
||||
Channel: slack.Channel,
|
||||
Text: text,
|
||||
Username: slack.Username,
|
||||
IconURL: slack.IconURL,
|
||||
Attachments: []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
Text: attachmentText,
|
||||
}},
|
||||
}, nil
|
||||
}
|
||||
if attachmentText != "" {
|
||||
pl.Attachments = []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
TitleLink: titleLink,
|
||||
Text: attachmentText,
|
||||
}}
|
||||
}
|
||||
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
func getSlackIssueCommentPayload(p *api.IssueCommentPayload, slack *SlackMeta) (*SlackPayload, error) {
|
||||
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
|
||||
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)),
|
||||
fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title))
|
||||
var text, title, attachmentText string
|
||||
title := SlackTextFormatter(fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title))
|
||||
repoLink := SlackLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName)
|
||||
var text, titleLink, attachmentText string
|
||||
|
||||
switch p.Action {
|
||||
case api.HookIssueCommentCreated:
|
||||
text = fmt.Sprintf("[%s] New comment created by %s", p.Repository.FullName, senderLink)
|
||||
title = titleLink
|
||||
text = fmt.Sprintf("[%s] New comment created by %s", repoLink, senderLink)
|
||||
titleLink = fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID))
|
||||
attachmentText = SlackTextFormatter(p.Comment.Body)
|
||||
case api.HookIssueCommentEdited:
|
||||
text = fmt.Sprintf("[%s] Comment edited by %s", p.Repository.FullName, senderLink)
|
||||
title = titleLink
|
||||
text = fmt.Sprintf("[%s] Comment edited by %s", repoLink, senderLink)
|
||||
titleLink = fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID))
|
||||
attachmentText = SlackTextFormatter(p.Comment.Body)
|
||||
case api.HookIssueCommentDeleted:
|
||||
text = fmt.Sprintf("[%s] Comment deleted by %s", p.Repository.FullName, senderLink)
|
||||
title = SlackLinkFormatter(fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index),
|
||||
fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title))
|
||||
text = fmt.Sprintf("[%s] Comment deleted by %s", repoLink, senderLink)
|
||||
titleLink = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index)
|
||||
attachmentText = SlackTextFormatter(p.Comment.Body)
|
||||
}
|
||||
|
||||
@@ -206,9 +215,10 @@ func getSlackIssueCommentPayload(p *api.IssueCommentPayload, slack *SlackMeta) (
|
||||
Username: slack.Username,
|
||||
IconURL: slack.IconURL,
|
||||
Attachments: []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
Text: attachmentText,
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
TitleLink: titleLink,
|
||||
Text: attachmentText,
|
||||
}},
|
||||
}, nil
|
||||
}
|
||||
@@ -281,65 +291,75 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e
|
||||
|
||||
func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*SlackPayload, error) {
|
||||
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
|
||||
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
|
||||
fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
|
||||
var text, title, attachmentText string
|
||||
title := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
|
||||
titleLink := fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index)
|
||||
repoLink := SlackLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName)
|
||||
var text, attachmentText string
|
||||
|
||||
switch p.Action {
|
||||
case api.HookIssueOpened:
|
||||
text = fmt.Sprintf("[%s] Pull request submitted by %s", p.Repository.FullName, senderLink)
|
||||
title = titleLink
|
||||
text = fmt.Sprintf("[%s] Pull request opened by %s", repoLink, senderLink)
|
||||
attachmentText = SlackTextFormatter(p.PullRequest.Body)
|
||||
case api.HookIssueClosed:
|
||||
if p.PullRequest.HasMerged {
|
||||
text = fmt.Sprintf("[%s] Pull request merged: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request merged: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
} else {
|
||||
text = fmt.Sprintf("[%s] Pull request closed: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request closed: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
}
|
||||
case api.HookIssueReOpened:
|
||||
text = fmt.Sprintf("[%s] Pull request re-opened: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request re-opened: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueEdited:
|
||||
text = fmt.Sprintf("[%s] Pull request edited: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request edited: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
attachmentText = SlackTextFormatter(p.PullRequest.Body)
|
||||
case api.HookIssueAssigned:
|
||||
list := make([]string, len(p.PullRequest.Assignees))
|
||||
for i, user := range p.PullRequest.Assignees {
|
||||
list[i] = SlackLinkFormatter(setting.AppURL+user.UserName, user.UserName)
|
||||
}
|
||||
text = fmt.Sprintf("[%s] Pull request assigned to %s: %s by %s", p.Repository.FullName,
|
||||
text = fmt.Sprintf("[%s] Pull request assigned to %s: [%s](%s) by %s", repoLink,
|
||||
strings.Join(list, ", "),
|
||||
titleLink, senderLink)
|
||||
title, titleLink, senderLink)
|
||||
case api.HookIssueUnassigned:
|
||||
text = fmt.Sprintf("[%s] Pull request unassigned: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request unassigned: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueLabelUpdated:
|
||||
text = fmt.Sprintf("[%s] Pull request labels updated: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request labels updated: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueLabelCleared:
|
||||
text = fmt.Sprintf("[%s] Pull request labels cleared: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request labels cleared: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueSynchronized:
|
||||
text = fmt.Sprintf("[%s] Pull request synchronized: %s by %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request synchronized: [%s](%s) by %s", repoLink, title, titleLink, senderLink)
|
||||
case api.HookIssueMilestoned:
|
||||
text = fmt.Sprintf("[%s] Pull request milestoned: #%s %s", p.Repository.FullName, titleLink, senderLink)
|
||||
mileStoneLink := fmt.Sprintf("%s/milestone/%d", p.Repository.HTMLURL, p.PullRequest.Milestone.ID)
|
||||
text = fmt.Sprintf("[%s] Pull request milestoned to [%s](%s): [%s](%s) %s", repoLink,
|
||||
p.PullRequest.Milestone.Title, mileStoneLink, title, titleLink, senderLink)
|
||||
case api.HookIssueDemilestoned:
|
||||
text = fmt.Sprintf("[%s] Pull request milestone cleared: #%s %s", p.Repository.FullName, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request milestone cleared: [%s](%s) %s", repoLink, title, titleLink, senderLink)
|
||||
}
|
||||
|
||||
return &SlackPayload{
|
||||
pl := &SlackPayload{
|
||||
Channel: slack.Channel,
|
||||
Text: text,
|
||||
Username: slack.Username,
|
||||
IconURL: slack.IconURL,
|
||||
Attachments: []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
Text: attachmentText,
|
||||
}},
|
||||
}, nil
|
||||
}
|
||||
if attachmentText != "" {
|
||||
pl.Attachments = []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
TitleLink: titleLink,
|
||||
Text: attachmentText,
|
||||
}}
|
||||
}
|
||||
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackMeta, event HookEventType) (*SlackPayload, error) {
|
||||
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
|
||||
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
|
||||
fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
|
||||
var text, title, attachmentText string
|
||||
title := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
|
||||
titleLink := fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index)
|
||||
repoLink := SlackLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName)
|
||||
var text string
|
||||
|
||||
switch p.Action {
|
||||
case api.HookIssueSynchronized:
|
||||
action, err := parseHookPullRequestEventType(event)
|
||||
@@ -347,7 +367,7 @@ func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackM
|
||||
return nil, err
|
||||
}
|
||||
|
||||
text = fmt.Sprintf("[%s] Pull request review %s : %s by %s", p.Repository.FullName, action, titleLink, senderLink)
|
||||
text = fmt.Sprintf("[%s] Pull request review %s: [%s](%s) by %s", repoLink, action, title, titleLink, senderLink)
|
||||
}
|
||||
|
||||
return &SlackPayload{
|
||||
@@ -355,17 +375,13 @@ func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackM
|
||||
Text: text,
|
||||
Username: slack.Username,
|
||||
IconURL: slack.IconURL,
|
||||
Attachments: []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
Text: attachmentText,
|
||||
}},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getSlackRepositoryPayload(p *api.RepositoryPayload, slack *SlackMeta) (*SlackPayload, error) {
|
||||
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
|
||||
var text, title, attachmentText string
|
||||
|
||||
switch p.Action {
|
||||
case api.HookRepoCreated:
|
||||
text = fmt.Sprintf("[%s] Repository created by %s", p.Repository.FullName, senderLink)
|
||||
@@ -380,9 +396,10 @@ func getSlackRepositoryPayload(p *api.RepositoryPayload, slack *SlackMeta) (*Sla
|
||||
Username: slack.Username,
|
||||
IconURL: slack.IconURL,
|
||||
Attachments: []SlackAttachment{{
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
Text: attachmentText,
|
||||
Color: slack.Color,
|
||||
Title: title,
|
||||
TitleLink: title,
|
||||
Text: attachmentText,
|
||||
}},
|
||||
}, nil
|
||||
}
|
||||
|
@@ -140,6 +140,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldWikiName, newWikiName, con
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if hasMasterBranch {
|
||||
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
|
||||
@@ -276,6 +277,7 @@ func (repo *Repository) DeleteWikiPage(doer *User, wikiName string) (err error)
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
|
||||
log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
|
@@ -161,6 +161,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
|
||||
// Now need to show that the page has been added:
|
||||
gitRepo, err := git.OpenRepository(repo.WikiPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
masterTree, err := gitRepo.GetTree("master")
|
||||
assert.NoError(t, err)
|
||||
wikiPath := WikiNameToFilename(wikiName)
|
||||
@@ -214,6 +215,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
|
||||
_, err := masterTree.GetTreeEntryByPath("Home.md")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +228,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
|
||||
// Now need to show that the page has been added:
|
||||
gitRepo, err := git.OpenRepository(repo.WikiPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
masterTree, err := gitRepo.GetTree("master")
|
||||
assert.NoError(t, err)
|
||||
wikiPath := WikiNameToFilename("Home")
|
||||
|
@@ -499,9 +499,9 @@ func (f SubmitReviewForm) HasEmptyContent() bool {
|
||||
|
||||
// NewReleaseForm form for creating release
|
||||
type NewReleaseForm struct {
|
||||
TagName string `binding:"Required;GitRefName"`
|
||||
Target string `form:"tag_target" binding:"Required"`
|
||||
Title string `binding:"Required"`
|
||||
TagName string `binding:"Required;GitRefName;MaxSize(255)"`
|
||||
Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
|
||||
Title string `binding:"Required;MaxSize(255)"`
|
||||
Content string
|
||||
Draft string
|
||||
Prerelease bool
|
||||
@@ -515,7 +515,7 @@ func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) bin
|
||||
|
||||
// EditReleaseForm form for changing release
|
||||
type EditReleaseForm struct {
|
||||
Title string `form:"title" binding:"Required"`
|
||||
Title string `form:"title" binding:"Required;MaxSize(255)"`
|
||||
Content string `form:"content"`
|
||||
Draft string `form:"draft"`
|
||||
Prerelease bool `form:"prerelease"`
|
||||
|
@@ -186,7 +186,16 @@ func ReferencesGitRepo(allowEmpty bool) macaron.Handler {
|
||||
return
|
||||
}
|
||||
ctx.Repo.GitRepo = gitRepo
|
||||
// We opened it, we should close it
|
||||
defer func() {
|
||||
// If it's been set to nil then assume someone else has closed it.
|
||||
if ctx.Repo.GitRepo != nil {
|
||||
ctx.Repo.GitRepo.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -63,7 +63,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
|
||||
// Force redirection when username is actually a user.
|
||||
if !org.IsOrganization() {
|
||||
ctx.Redirect("/" + org.Name)
|
||||
ctx.Redirect(setting.AppSubURL + "/" + org.Name)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -236,7 +236,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
|
||||
if ctx.Req.URL.RawQuery != "" {
|
||||
redirectPath += "?" + ctx.Req.URL.RawQuery
|
||||
}
|
||||
ctx.Redirect(redirectPath)
|
||||
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
|
||||
}
|
||||
|
||||
func repoAssignment(ctx *Context, repo *models.Repository) {
|
||||
@@ -414,8 +414,8 @@ func RepoAssignment() macaron.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// repo is empty and display enable
|
||||
if ctx.Repo.Repository.IsEmpty || ctx.Repo.Repository.IsBeingCreated() {
|
||||
// Disable everything when the repo is being created
|
||||
if ctx.Repo.Repository.IsBeingCreated() {
|
||||
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
|
||||
return
|
||||
}
|
||||
@@ -427,6 +427,21 @@ func RepoAssignment() macaron.Handler {
|
||||
}
|
||||
ctx.Repo.GitRepo = gitRepo
|
||||
|
||||
// We opened it, we should close it
|
||||
defer func() {
|
||||
// If it's been set to nil then assume someone else has closed it.
|
||||
if ctx.Repo.GitRepo != nil {
|
||||
ctx.Repo.GitRepo.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
// Stop at this point when the repo is empty.
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
|
||||
tags, err := ctx.Repo.GitRepo.GetTags()
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTags", err)
|
||||
@@ -482,6 +497,7 @@ func RepoAssignment() macaron.Handler {
|
||||
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
|
||||
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
|
||||
}
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,6 +603,13 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
|
||||
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
||||
return
|
||||
}
|
||||
// We opened it, we should close it
|
||||
defer func() {
|
||||
// If it's been set to nil then assume someone else has closed it.
|
||||
if ctx.Repo.GitRepo != nil {
|
||||
ctx.Repo.GitRepo.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Get default branch.
|
||||
@@ -675,6 +698,8 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
|
||||
return
|
||||
}
|
||||
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
||||
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -87,10 +87,11 @@ func (r *BlameReader) Close() error {
|
||||
|
||||
// CreateBlameReader creates reader for given repository, commit and file
|
||||
func CreateBlameReader(repoPath, commitID, file string) (*BlameReader, error) {
|
||||
_, err := OpenRepository(repoPath)
|
||||
gitRepo, err := OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitRepo.Close()
|
||||
|
||||
return createBlameReader(repoPath, GitExecutable, "blame", commitID, "--porcelain", "--", file)
|
||||
}
|
||||
|
@@ -37,6 +37,8 @@ THE SOFTWARE.
|
||||
`
|
||||
repo, err := OpenRepository("../../.git")
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -55,6 +57,8 @@ func Benchmark_Blob_Data(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer repo.Close()
|
||||
|
||||
testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
|
@@ -77,6 +77,8 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
testGetCommitsInfo(t, bareRepo1)
|
||||
|
||||
clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo")
|
||||
@@ -84,6 +86,8 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
|
||||
defer os.RemoveAll(clonedPath)
|
||||
clonedRepo1, err := OpenRepository(clonedPath)
|
||||
assert.NoError(t, err)
|
||||
defer clonedRepo1.Close()
|
||||
|
||||
testGetCommitsInfo(t, clonedRepo1)
|
||||
}
|
||||
|
||||
@@ -101,13 +105,16 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
|
||||
for _, benchmark := range benchmarks {
|
||||
var commit *Commit
|
||||
var entries Entries
|
||||
var repo *Repository
|
||||
if repoPath, err := cloneRepo(benchmark.url, benchmarkReposDir, benchmark.name); err != nil {
|
||||
b.Fatal(err)
|
||||
} else if repo, err := OpenRepository(repoPath); err != nil {
|
||||
} else if repo, err = OpenRepository(repoPath); err != nil {
|
||||
b.Fatal(err)
|
||||
} else if commit, err = repo.GetBranchCommit("master"); err != nil {
|
||||
repo.Close()
|
||||
b.Fatal(err)
|
||||
} else if entries, err = commit.Tree.ListEntries(); err != nil {
|
||||
repo.Close()
|
||||
b.Fatal(err)
|
||||
}
|
||||
entries.Sort()
|
||||
@@ -120,5 +127,6 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
|
||||
}
|
||||
}
|
||||
})
|
||||
repo.Close()
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ package git
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -133,6 +134,13 @@ func Init() error {
|
||||
return fmt.Errorf("Failed to execute 'git config --global gc.writeCommitGraph true': %s", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
if _, stderr, err := process.GetManager().Exec("git.Init(git config --global core.longpaths true)",
|
||||
GitExecutable, "config", "--global", "core.longpaths", "true"); err != nil {
|
||||
return fmt.Errorf("Failed to execute 'git config --global core.longpaths true': %s", stderr)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -90,6 +90,11 @@ func (h *Hook) Update() error {
|
||||
h.IsActive = false
|
||||
return nil
|
||||
}
|
||||
d := filepath.Dir(h.path)
|
||||
if err := os.MkdirAll(d, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -15,6 +15,7 @@ func TestGetNotes(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
note := Note{}
|
||||
err = GetNote(bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
||||
@@ -27,6 +28,7 @@ func TestGetNestedNotes(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo3_notes")
|
||||
repo, err := OpenRepository(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
note := Note{}
|
||||
err = GetNote(repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
|
||||
|
@@ -17,6 +17,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
gitealog "code.gitea.io/gitea/modules/log"
|
||||
"github.com/unknwon/com"
|
||||
"gopkg.in/src-d/go-billy.v4/osfs"
|
||||
gogit "gopkg.in/src-d/go-git.v4"
|
||||
@@ -107,6 +108,21 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Close this repository, in particular close the underlying gogitStorage if this is not nil
|
||||
func (repo *Repository) Close() {
|
||||
if repo == nil || repo.gogitStorage == nil {
|
||||
return
|
||||
}
|
||||
if err := repo.gogitStorage.Close(); err != nil {
|
||||
gitealog.Error("Error closing storage: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// GoGitRepo gets the go-git repo representation
|
||||
func (repo *Repository) GoGitRepo() *gogit.Repository {
|
||||
return repo.gogitRepo
|
||||
}
|
||||
|
||||
// IsEmpty Check if repository is empty.
|
||||
func (repo *Repository) IsEmpty() (bool, error) {
|
||||
var errbuf strings.Builder
|
||||
|
@@ -17,6 +17,7 @@ func TestRepository_GetBlob_Found(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||
r, err := OpenRepository(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
testCases := []struct {
|
||||
OID string
|
||||
@@ -44,6 +45,7 @@ func TestRepository_GetBlob_NotExist(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||
r, err := OpenRepository(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
testCase := "0000000000000000000000000000000000000000"
|
||||
testError := ErrNotExist{testCase, ""}
|
||||
@@ -57,6 +59,7 @@ func TestRepository_GetBlob_NoId(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||
r, err := OpenRepository(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
testCase := ""
|
||||
testError := fmt.Errorf("Length must be 40: %s", testCase)
|
||||
|
@@ -108,6 +108,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
brs, err := gitRepo.GetBranches()
|
||||
if err != nil {
|
||||
|
@@ -15,6 +15,7 @@ func TestRepository_GetBranches(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
branches, err := bareRepo1.GetBranches()
|
||||
|
||||
@@ -29,6 +30,7 @@ func BenchmarkRepository_GetBranches(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer bareRepo1.Close()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := bareRepo1.GetBranches()
|
||||
|
@@ -15,6 +15,7 @@ func TestRepository_GetCommitBranches(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
// these test case are specific to the repo1_bare test repo
|
||||
testCases := []struct {
|
||||
@@ -41,6 +42,7 @@ func TestGetTagCommitWithSignature(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
|
||||
assert.NoError(t, err)
|
||||
@@ -54,6 +56,7 @@ func TestGetCommitWithBadCommitID(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
commit, err := bareRepo1.GetCommit("bad_branch")
|
||||
assert.Nil(t, commit)
|
||||
|
@@ -20,6 +20,7 @@ func TestGetFormatPatch(t *testing.T) {
|
||||
defer os.RemoveAll(clonedPath)
|
||||
repo, err := OpenRepository(clonedPath)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
|
||||
assert.NoError(t, err)
|
||||
patchb, err := ioutil.ReadAll(rd)
|
||||
|
@@ -15,6 +15,7 @@ func TestRepository_GetRefs(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
refs, err := bareRepo1.GetRefs()
|
||||
|
||||
@@ -38,6 +39,7 @@ func TestRepository_GetRefsFiltered(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
refs, err := bareRepo1.GetRefsFiltered(TagPrefix)
|
||||
|
||||
|
@@ -16,6 +16,7 @@ func TestRepository_GetCodeActivityStats(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00")
|
||||
assert.NoError(t, err)
|
||||
|
@@ -16,6 +16,7 @@ func TestRepository_GetTags(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
tags, err := bareRepo1.GetTagInfos()
|
||||
assert.NoError(t, err)
|
||||
@@ -34,6 +35,7 @@ func TestRepository_GetTag(t *testing.T) {
|
||||
|
||||
bareRepo1, err := OpenRepository(clonedPath)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
|
||||
lTagName := "lightweightTag"
|
||||
@@ -83,6 +85,7 @@ func TestRepository_GetAnnotatedTag(t *testing.T) {
|
||||
|
||||
bareRepo1, err := OpenRepository(clonedPath)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
|
||||
lTagName := "lightweightTag"
|
||||
|
@@ -30,6 +30,7 @@ func TestRepoIsEmpty(t *testing.T) {
|
||||
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
|
||||
repo, err := OpenRepository(emptyRepo2Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
isEmpty, err := repo.IsEmpty()
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, isEmpty)
|
||||
|
@@ -56,6 +56,7 @@ func TestEntriesCustomSort(t *testing.T) {
|
||||
func TestFollowLink(t *testing.T) {
|
||||
r, err := OpenRepository("tests/repos/repo1_bare")
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123")
|
||||
assert.NoError(t, err)
|
||||
|
@@ -123,7 +123,7 @@ func Middleware(options ...Options) macaron.Handler {
|
||||
// OK we should proxy the response writer
|
||||
// We are still not necessarily going to compress...
|
||||
proxyWriter := &ProxyResponseWriter{
|
||||
ResponseWriter: ctx.Resp,
|
||||
internal: ctx.Resp,
|
||||
}
|
||||
defer proxyWriter.Close()
|
||||
|
||||
@@ -137,19 +137,52 @@ func Middleware(options ...Options) macaron.Handler {
|
||||
}
|
||||
|
||||
ctx.Next()
|
||||
ctx.Resp = proxyWriter.internal
|
||||
}
|
||||
}
|
||||
|
||||
// ProxyResponseWriter is a wrapped macaron ResponseWriter that may compress its contents
|
||||
type ProxyResponseWriter struct {
|
||||
writer io.WriteCloser
|
||||
macaron.ResponseWriter
|
||||
stopped bool
|
||||
writer io.WriteCloser
|
||||
internal macaron.ResponseWriter
|
||||
stopped bool
|
||||
|
||||
code int
|
||||
buf []byte
|
||||
}
|
||||
|
||||
// Header returns the header map
|
||||
func (proxy *ProxyResponseWriter) Header() http.Header {
|
||||
return proxy.internal.Header()
|
||||
}
|
||||
|
||||
// Status returns the status code of the response or 0 if the response has not been written.
|
||||
func (proxy *ProxyResponseWriter) Status() int {
|
||||
if proxy.code != 0 {
|
||||
return proxy.code
|
||||
}
|
||||
return proxy.internal.Status()
|
||||
}
|
||||
|
||||
// Written returns whether or not the ResponseWriter has been written.
|
||||
func (proxy *ProxyResponseWriter) Written() bool {
|
||||
if proxy.code != 0 {
|
||||
return true
|
||||
}
|
||||
return proxy.internal.Written()
|
||||
}
|
||||
|
||||
// Size returns the size of the response body.
|
||||
func (proxy *ProxyResponseWriter) Size() int {
|
||||
return proxy.internal.Size()
|
||||
}
|
||||
|
||||
// Before allows for a function to be called before the ResponseWriter has been written to. This is
|
||||
// useful for setting headers or any other operations that must happen before a response has been written.
|
||||
func (proxy *ProxyResponseWriter) Before(before macaron.BeforeFunc) {
|
||||
proxy.internal.Before(before)
|
||||
}
|
||||
|
||||
// Write appends data to the proxied gzip writer.
|
||||
func (proxy *ProxyResponseWriter) Write(b []byte) (int, error) {
|
||||
// if writer is initialized, use the writer
|
||||
@@ -210,7 +243,7 @@ func (proxy *ProxyResponseWriter) startGzip() error {
|
||||
|
||||
// Write the header to gzip response.
|
||||
if proxy.code != 0 {
|
||||
proxy.ResponseWriter.WriteHeader(proxy.code)
|
||||
proxy.internal.WriteHeader(proxy.code)
|
||||
// Ensure that no other WriteHeader's happen
|
||||
proxy.code = 0
|
||||
}
|
||||
@@ -220,7 +253,7 @@ func (proxy *ProxyResponseWriter) startGzip() error {
|
||||
// write the gzip header even if nothing was ever written.
|
||||
if len(proxy.buf) > 0 {
|
||||
// Initialize the GZIP response.
|
||||
proxy.writer = writerPool.Get(proxy.ResponseWriter)
|
||||
proxy.writer = writerPool.Get(proxy.internal)
|
||||
|
||||
return proxy.writeBuf()
|
||||
}
|
||||
@@ -229,11 +262,11 @@ func (proxy *ProxyResponseWriter) startGzip() error {
|
||||
|
||||
func (proxy *ProxyResponseWriter) startPlain() error {
|
||||
if proxy.code != 0 {
|
||||
proxy.ResponseWriter.WriteHeader(proxy.code)
|
||||
proxy.internal.WriteHeader(proxy.code)
|
||||
proxy.code = 0
|
||||
}
|
||||
proxy.stopped = true
|
||||
proxy.writer = noopCloser{proxy.ResponseWriter}
|
||||
proxy.writer = noopCloser{proxy.internal}
|
||||
return proxy.writeBuf()
|
||||
}
|
||||
|
||||
@@ -295,13 +328,13 @@ func (proxy *ProxyResponseWriter) Flush() {
|
||||
gw.Flush()
|
||||
}
|
||||
|
||||
proxy.ResponseWriter.Flush()
|
||||
proxy.internal.Flush()
|
||||
}
|
||||
|
||||
// Hijack implements http.Hijacker. If the underlying ResponseWriter is a
|
||||
// Hijacker, its Hijack method is returned. Otherwise an error is returned.
|
||||
func (proxy *ProxyResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
hijacker, ok := proxy.ResponseWriter.(http.Hijacker)
|
||||
hijacker, ok := proxy.internal.(http.Hijacker)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface")
|
||||
}
|
||||
|
@@ -138,26 +138,31 @@ func populateIssueIndexer() {
|
||||
}
|
||||
|
||||
for _, repo := range repos {
|
||||
is, err := models.Issues(&models.IssuesOptions{
|
||||
RepoIDs: []int64{repo.ID},
|
||||
IsClosed: util.OptionalBoolNone,
|
||||
IsPull: util.OptionalBoolNone,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("Issues: %v", err)
|
||||
continue
|
||||
}
|
||||
if err = models.IssueList(is).LoadDiscussComments(); err != nil {
|
||||
log.Error("LoadComments: %v", err)
|
||||
continue
|
||||
}
|
||||
for _, issue := range is {
|
||||
UpdateIssueIndexer(issue)
|
||||
}
|
||||
UpdateRepoIndexer(repo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateRepoIndexer add/update all issues of the repositories
|
||||
func UpdateRepoIndexer(repo *models.Repository) {
|
||||
is, err := models.Issues(&models.IssuesOptions{
|
||||
RepoIDs: []int64{repo.ID},
|
||||
IsClosed: util.OptionalBoolNone,
|
||||
IsPull: util.OptionalBoolNone,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("Issues: %v", err)
|
||||
return
|
||||
}
|
||||
if err = models.IssueList(is).LoadDiscussComments(); err != nil {
|
||||
log.Error("LoadComments: %v", err)
|
||||
return
|
||||
}
|
||||
for _, issue := range is {
|
||||
UpdateIssueIndexer(issue)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateIssueIndexer add/update an issue to the issue indexer
|
||||
func UpdateIssueIndexer(issue *models.Issue) {
|
||||
var comments []string
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"github.com/lunny/levelqueue"
|
||||
"gitea.com/lunny/levelqueue"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -12,9 +12,11 @@ type Uploader interface {
|
||||
CreateTopics(topic ...string) error
|
||||
CreateMilestones(milestones ...*Milestone) error
|
||||
CreateReleases(releases ...*Release) error
|
||||
SyncTags() error
|
||||
CreateLabels(labels ...*Label) error
|
||||
CreateIssues(issues ...*Issue) error
|
||||
CreateComments(comments ...*Comment) error
|
||||
CreatePullRequests(prs ...*PullRequest) error
|
||||
Rollback() error
|
||||
Close()
|
||||
}
|
||||
|
@@ -131,6 +131,13 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
|
||||
return err
|
||||
}
|
||||
|
||||
// Close closes this uploader
|
||||
func (g *GiteaLocalUploader) Close() {
|
||||
if g.gitRepo != nil {
|
||||
g.gitRepo.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// CreateTopics creates topics
|
||||
func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
|
||||
return models.SaveTopics(g.repo.ID, topics...)
|
||||
@@ -252,37 +259,41 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
|
||||
}
|
||||
|
||||
// download attachment
|
||||
resp, err := http.Get(asset.URL)
|
||||
err = func() error {
|
||||
resp, err := http.Get(asset.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
localPath := attach.LocalPath()
|
||||
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("MkdirAll: %v", err)
|
||||
}
|
||||
|
||||
fw, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Create: %v", err)
|
||||
}
|
||||
defer fw.Close()
|
||||
|
||||
_, err = io.Copy(fw, resp.Body)
|
||||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
localPath := attach.LocalPath()
|
||||
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("MkdirAll: %v", err)
|
||||
}
|
||||
|
||||
fw, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Create: %v", err)
|
||||
}
|
||||
defer fw.Close()
|
||||
|
||||
if _, err := io.Copy(fw, resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rel.Attachments = append(rel.Attachments, &attach)
|
||||
}
|
||||
|
||||
rels = append(rels, &rel)
|
||||
}
|
||||
if err := models.InsertReleases(rels...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// sync tags to releases in database
|
||||
return models.InsertReleases(rels...)
|
||||
}
|
||||
|
||||
// SyncTags syncs releases with tags in the database
|
||||
func (g *GiteaLocalUploader) SyncTags() error {
|
||||
return models.SyncReleasesWithTags(g.repo, g.gitRepo)
|
||||
}
|
||||
|
||||
@@ -468,21 +479,24 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
||||
}
|
||||
|
||||
// download patch file
|
||||
resp, err := http.Get(pr.PatchURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
|
||||
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
err := func() error {
|
||||
resp, err := http.Get(pr.PatchURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
|
||||
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -496,8 +510,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer p.Close()
|
||||
_, err = p.WriteString(pr.Head.SHA)
|
||||
p.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -531,8 +545,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer b.Close()
|
||||
_, err = b.WriteString(pr.Head.SHA)
|
||||
b.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -579,14 +593,13 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
||||
}
|
||||
|
||||
var pullRequest = models.PullRequest{
|
||||
HeadRepoID: g.repo.ID,
|
||||
HeadBranch: head,
|
||||
HeadUserName: g.repoOwner,
|
||||
BaseRepoID: g.repo.ID,
|
||||
BaseBranch: pr.Base.Ref,
|
||||
MergeBase: pr.Base.SHA,
|
||||
Index: pr.Number,
|
||||
HasMerged: pr.Merged,
|
||||
HeadRepoID: g.repo.ID,
|
||||
HeadBranch: head,
|
||||
BaseRepoID: g.repo.ID,
|
||||
BaseBranch: pr.Base.Ref,
|
||||
MergeBase: pr.Base.SHA,
|
||||
Index: pr.Number,
|
||||
HasMerged: pr.Merged,
|
||||
|
||||
Issue: &issue,
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func assertMilestoneEqual(t *testing.T, title, dueOn, created, updated, closed, state string, ms *base.Milestone) {
|
||||
func assertMilestoneEqual(t *testing.T, description, title, dueOn, created, updated, closed, state string, ms *base.Milestone) {
|
||||
var tmPtr *time.Time
|
||||
if dueOn != "" {
|
||||
tm, err := time.Parse("2006-01-02 15:04:05 -0700 MST", dueOn)
|
||||
@@ -43,32 +43,34 @@ func assertMilestoneEqual(t *testing.T, title, dueOn, created, updated, closed,
|
||||
}
|
||||
|
||||
assert.EqualValues(t, &base.Milestone{
|
||||
Title: title,
|
||||
Deadline: tmPtr,
|
||||
State: state,
|
||||
Created: createdTM,
|
||||
Updated: updatedTM,
|
||||
Closed: closedTM,
|
||||
Description: description,
|
||||
Title: title,
|
||||
Deadline: tmPtr,
|
||||
State: state,
|
||||
Created: createdTM,
|
||||
Updated: updatedTM,
|
||||
Closed: closedTM,
|
||||
}, ms)
|
||||
}
|
||||
|
||||
func assertLabelEqual(t *testing.T, name, color string, label *base.Label) {
|
||||
func assertLabelEqual(t *testing.T, name, color, description string, label *base.Label) {
|
||||
assert.EqualValues(t, &base.Label{
|
||||
Name: name,
|
||||
Color: color,
|
||||
Name: name,
|
||||
Color: color,
|
||||
Description: description,
|
||||
}, label)
|
||||
}
|
||||
|
||||
func TestGitHubDownloadRepo(t *testing.T) {
|
||||
downloader := NewGithubDownloaderV3("", "", "go-gitea", "gitea")
|
||||
downloader := NewGithubDownloaderV3("", "", "go-gitea", "test_repo")
|
||||
repo, err := downloader.GetRepoInfo()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, &base.Repository{
|
||||
Name: "gitea",
|
||||
Name: "test_repo",
|
||||
Owner: "go-gitea",
|
||||
Description: "Git with a cup of tea, painless self-hosted git service",
|
||||
CloneURL: "https://github.com/go-gitea/gitea.git",
|
||||
OriginalURL: "https://github.com/go-gitea/gitea",
|
||||
Description: "Test repository for testing migration from github to gitea",
|
||||
CloneURL: "https://github.com/go-gitea/test_repo.git",
|
||||
OriginalURL: "https://github.com/go-gitea/test_repo",
|
||||
}, repo)
|
||||
|
||||
topics, err := downloader.GetTopics()
|
||||
@@ -77,83 +79,46 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||
|
||||
milestones, err := downloader.GetMilestones()
|
||||
assert.NoError(t, err)
|
||||
// before this tool release, we have 39 milestones on github.com/go-gitea/gitea
|
||||
assert.True(t, len(milestones) >= 39)
|
||||
assert.True(t, len(milestones) >= 2)
|
||||
|
||||
for _, milestone := range milestones {
|
||||
switch milestone.Title {
|
||||
case "1.0.0":
|
||||
assertMilestoneEqual(t, "1.0.0", "2016-12-23 08:00:00 +0000 UTC",
|
||||
"2016-11-02 18:06:55 +0000 UTC",
|
||||
"2016-12-29 10:26:00 +0000 UTC",
|
||||
"2016-12-24 00:40:56 +0000 UTC",
|
||||
assertMilestoneEqual(t, "Milestone 1.0.0", "1.0.0", "2019-11-11 08:00:00 +0000 UTC",
|
||||
"2019-11-12 19:37:08 +0000 UTC",
|
||||
"2019-11-12 21:56:17 +0000 UTC",
|
||||
"2019-11-12 19:45:49 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.1.0":
|
||||
assertMilestoneEqual(t, "1.1.0", "2017-02-24 08:00:00 +0000 UTC",
|
||||
"2016-11-03 08:40:10 +0000 UTC",
|
||||
"2017-06-15 05:04:36 +0000 UTC",
|
||||
"2017-03-09 21:22:21 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.2.0":
|
||||
assertMilestoneEqual(t, "1.2.0", "2017-04-24 07:00:00 +0000 UTC",
|
||||
"2016-11-03 08:40:15 +0000 UTC",
|
||||
"2017-12-10 02:43:29 +0000 UTC",
|
||||
"2017-10-12 08:24:28 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.3.0":
|
||||
assertMilestoneEqual(t, "1.3.0", "2017-11-29 08:00:00 +0000 UTC",
|
||||
"2017-03-03 08:08:59 +0000 UTC",
|
||||
"2017-12-04 07:48:44 +0000 UTC",
|
||||
"2017-11-29 18:39:00 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.4.0":
|
||||
assertMilestoneEqual(t, "1.4.0", "2018-01-25 08:00:00 +0000 UTC",
|
||||
"2017-08-23 11:02:37 +0000 UTC",
|
||||
"2018-03-25 20:01:56 +0000 UTC",
|
||||
"2018-03-25 20:01:56 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.5.0":
|
||||
assertMilestoneEqual(t, "1.5.0", "2018-06-15 07:00:00 +0000 UTC",
|
||||
"2017-12-30 04:21:56 +0000 UTC",
|
||||
"2018-09-05 16:34:22 +0000 UTC",
|
||||
"2018-08-11 08:45:01 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.6.0":
|
||||
assertMilestoneEqual(t, "1.6.0", "2018-09-25 07:00:00 +0000 UTC",
|
||||
"2018-05-11 05:37:01 +0000 UTC",
|
||||
"2019-01-27 19:21:22 +0000 UTC",
|
||||
"2018-11-23 13:23:16 +0000 UTC",
|
||||
"closed", milestone)
|
||||
case "1.7.0":
|
||||
assertMilestoneEqual(t, "1.7.0", "2018-12-25 08:00:00 +0000 UTC",
|
||||
"2018-08-28 14:20:14 +0000 UTC",
|
||||
"2019-01-27 11:30:24 +0000 UTC",
|
||||
"2019-01-23 08:58:23 +0000 UTC",
|
||||
assertMilestoneEqual(t, "Milestone 1.1.0", "1.1.0", "2019-11-12 08:00:00 +0000 UTC",
|
||||
"2019-11-12 19:37:25 +0000 UTC",
|
||||
"2019-11-12 21:39:27 +0000 UTC",
|
||||
"2019-11-12 19:45:46 +0000 UTC",
|
||||
"closed", milestone)
|
||||
}
|
||||
}
|
||||
|
||||
labels, err := downloader.GetLabels()
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, len(labels) >= 48)
|
||||
assert.True(t, len(labels) >= 8)
|
||||
for _, l := range labels {
|
||||
switch l.Name {
|
||||
case "backport/v1.7":
|
||||
assertLabelEqual(t, "backport/v1.7", "fbca04", l)
|
||||
case "backport/v1.8":
|
||||
assertLabelEqual(t, "backport/v1.8", "fbca04", l)
|
||||
case "kind/api":
|
||||
assertLabelEqual(t, "kind/api", "5319e7", l)
|
||||
case "kind/breaking":
|
||||
assertLabelEqual(t, "kind/breaking", "fbca04", l)
|
||||
case "kind/bug":
|
||||
assertLabelEqual(t, "kind/bug", "ee0701", l)
|
||||
case "kind/docs":
|
||||
assertLabelEqual(t, "kind/docs", "c2e0c6", l)
|
||||
case "kind/enhancement":
|
||||
assertLabelEqual(t, "kind/enhancement", "84b6eb", l)
|
||||
case "kind/feature":
|
||||
assertLabelEqual(t, "kind/feature", "006b75", l)
|
||||
case "bug":
|
||||
assertLabelEqual(t, "bug", "d73a4a", "Something isn't working", l)
|
||||
case "documentation":
|
||||
assertLabelEqual(t, "documentation", "0075ca", "Improvements or additions to documentation", l)
|
||||
case "duplicate":
|
||||
assertLabelEqual(t, "duplicate", "cfd3d7", "This issue or pull request already exists", l)
|
||||
case "enhancement":
|
||||
assertLabelEqual(t, "enhancement", "a2eeef", "New feature or request", l)
|
||||
case "good first issue":
|
||||
assertLabelEqual(t, "good first issue", "7057ff", "Good for newcomers", l)
|
||||
case "help wanted":
|
||||
assertLabelEqual(t, "help wanted", "008672", "Extra attention is needed", l)
|
||||
case "invalid":
|
||||
assertLabelEqual(t, "invalid", "e4e669", "This doesn't seem right", l)
|
||||
case "question":
|
||||
assertLabelEqual(t, "question", "d876e3", "Further information is requested", l)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,48 +128,50 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||
{
|
||||
TagName: "v0.9.99",
|
||||
TargetCommitish: "master",
|
||||
Name: "fork",
|
||||
Body: "Forked source from Gogs into Gitea\n",
|
||||
Created: time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC),
|
||||
Published: time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC),
|
||||
PublisherID: 4726179,
|
||||
PublisherName: "bkcsoft",
|
||||
Name: "First Release",
|
||||
Body: "A test release",
|
||||
Created: time.Date(2019, 11, 9, 16, 49, 21, 0, time.UTC),
|
||||
Published: time.Date(2019, 11, 12, 20, 12, 10, 0, time.UTC),
|
||||
PublisherID: 1669571,
|
||||
PublisherName: "mrsdizzie",
|
||||
},
|
||||
}, releases[len(releases)-1:])
|
||||
|
||||
// downloader.GetIssues()
|
||||
issues, isEnd, err := downloader.GetIssues(1, 8)
|
||||
issues, isEnd, err := downloader.GetIssues(1, 2)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 3, len(issues))
|
||||
assert.EqualValues(t, 2, len(issues))
|
||||
assert.False(t, isEnd)
|
||||
|
||||
var (
|
||||
closed1 = time.Date(2018, 10, 23, 02, 57, 43, 0, time.UTC)
|
||||
closed7 = time.Date(2019, 7, 8, 8, 20, 23, 0, time.UTC)
|
||||
closed1 = time.Date(2019, 11, 12, 20, 22, 22, 0, time.UTC)
|
||||
closed2 = time.Date(2019, 11, 12, 21, 1, 31, 0, time.UTC)
|
||||
)
|
||||
assert.EqualValues(t, []*base.Issue{
|
||||
{
|
||||
Number: 6,
|
||||
Title: "Contribution system: History heatmap for user",
|
||||
Content: "Hi guys,\r\n\r\nI think that is a possible feature, a history heatmap similar to github or gitlab.\r\nActually exists a plugin called Calendar HeatMap. I used this on mine project to heat application log and worked fine here.\r\nThen, is only a idea, what you think? :)\r\n\r\nhttp://cal-heatmap.com/\r\nhttps://github.com/wa0x6e/cal-heatmap\r\n\r\nReference: https://github.com/gogits/gogs/issues/1640",
|
||||
Milestone: "1.7.0",
|
||||
PosterID: 1520407,
|
||||
PosterName: "joubertredrat",
|
||||
Number: 1,
|
||||
Title: "Please add an animated gif icon to the merge button",
|
||||
Content: "I just want the merge button to hurt my eyes a little. \xF0\x9F\x98\x9D ",
|
||||
Milestone: "1.0.0",
|
||||
PosterID: 18600385,
|
||||
PosterName: "guillep2k",
|
||||
State: "closed",
|
||||
Created: time.Date(2016, 11, 02, 18, 51, 55, 0, time.UTC),
|
||||
Created: time.Date(2019, 11, 9, 17, 0, 29, 0, time.UTC),
|
||||
Labels: []*base.Label{
|
||||
{
|
||||
Name: "kind/feature",
|
||||
Color: "006b75",
|
||||
Name: "bug",
|
||||
Color: "d73a4a",
|
||||
Description: "Something isn't working",
|
||||
},
|
||||
{
|
||||
Name: "kind/ui",
|
||||
Color: "fef2c0",
|
||||
Name: "good first issue",
|
||||
Color: "7057ff",
|
||||
Description: "Good for newcomers",
|
||||
},
|
||||
},
|
||||
Reactions: &base.Reactions{
|
||||
TotalCount: 0,
|
||||
PlusOne: 0,
|
||||
TotalCount: 1,
|
||||
PlusOne: 1,
|
||||
MinusOne: 0,
|
||||
Laugh: 0,
|
||||
Confused: 0,
|
||||
@@ -214,84 +181,48 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||
Closed: &closed1,
|
||||
},
|
||||
{
|
||||
Number: 7,
|
||||
Title: "display page revisions on wiki",
|
||||
Content: "Hi guys,\r\n\r\nWiki on Gogs is very fine, I liked a lot, but I think that is good idea to be possible see other revisions from page as a page history.\r\n\r\nWhat you think?\r\n\r\nReference: https://github.com/gogits/gogs/issues/2991",
|
||||
Milestone: "1.10.0",
|
||||
PosterID: 1520407,
|
||||
PosterName: "joubertredrat",
|
||||
Number: 2,
|
||||
Title: "Test issue",
|
||||
Content: "This is test issue 2, do not touch!",
|
||||
Milestone: "1.1.0",
|
||||
PosterID: 1669571,
|
||||
PosterName: "mrsdizzie",
|
||||
State: "closed",
|
||||
Created: time.Date(2016, 11, 02, 18, 57, 32, 0, time.UTC),
|
||||
Created: time.Date(2019, 11, 12, 21, 0, 6, 0, time.UTC),
|
||||
Labels: []*base.Label{
|
||||
{
|
||||
Name: "kind/feature",
|
||||
Color: "006b75",
|
||||
},
|
||||
{
|
||||
Name: "reviewed/confirmed",
|
||||
Color: "8d9b12",
|
||||
Description: "Issue has been reviewed and confirmed to be present or accepted to be implemented",
|
||||
Name: "duplicate",
|
||||
Color: "cfd3d7",
|
||||
Description: "This issue or pull request already exists",
|
||||
},
|
||||
},
|
||||
Reactions: &base.Reactions{
|
||||
TotalCount: 6,
|
||||
PlusOne: 5,
|
||||
MinusOne: 0,
|
||||
Laugh: 0,
|
||||
PlusOne: 1,
|
||||
MinusOne: 1,
|
||||
Laugh: 1,
|
||||
Confused: 1,
|
||||
Heart: 0,
|
||||
Hooray: 0,
|
||||
},
|
||||
Closed: &closed7,
|
||||
},
|
||||
{
|
||||
Number: 8,
|
||||
Title: "audit logs",
|
||||
Content: "Hi,\r\n\r\nI think that is good idea to have user operation log to admin see what the user is doing at Gogs. Similar to example below\r\n\r\n| user | operation | information |\r\n| --- | --- | --- |\r\n| joubertredrat | repo.create | Create repo MyProjectData |\r\n| joubertredrat | user.settings | Edit settings |\r\n| tboerger | repo.fork | Create Fork from MyProjectData to ForkMyProjectData |\r\n| bkcsoft | repo.remove | Remove repo MySource |\r\n| tboerger | admin.auth | Edit auth LDAP org-connection |\r\n\r\nThis resource can be used on user page too, as user activity, set that log row is public (repo._) or private (user._, admin.*) and display only public activity.\r\n\r\nWhat you think?\r\n\r\n[Chat summary from March 14, 2017](https://github.com/go-gitea/gitea/issues/8#issuecomment-286463807)\r\n\r\nReferences:\r\nhttps://github.com/gogits/gogs/issues/3016",
|
||||
Milestone: "1.x.x",
|
||||
PosterID: 1520407,
|
||||
PosterName: "joubertredrat",
|
||||
State: "open",
|
||||
Created: time.Date(2016, 11, 02, 18, 59, 20, 0, time.UTC),
|
||||
Labels: []*base.Label{
|
||||
{
|
||||
Name: "kind/feature",
|
||||
Color: "006b75",
|
||||
},
|
||||
{
|
||||
Name: "kind/proposal",
|
||||
Color: "5319e7",
|
||||
},
|
||||
},
|
||||
Reactions: &base.Reactions{
|
||||
TotalCount: 9,
|
||||
PlusOne: 8,
|
||||
MinusOne: 0,
|
||||
Laugh: 0,
|
||||
Confused: 0,
|
||||
Heart: 1,
|
||||
Hooray: 0,
|
||||
Hooray: 1,
|
||||
},
|
||||
Closed: &closed2,
|
||||
},
|
||||
}, issues)
|
||||
|
||||
// downloader.GetComments()
|
||||
comments, err := downloader.GetComments(6)
|
||||
comments, err := downloader.GetComments(2)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 35, len(comments))
|
||||
assert.EqualValues(t, 2, len(comments))
|
||||
assert.EqualValues(t, []*base.Comment{
|
||||
{
|
||||
IssueIndex: 6,
|
||||
PosterID: 4726179,
|
||||
PosterName: "bkcsoft",
|
||||
Created: time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC),
|
||||
Content: `I would prefer a solution that is in the backend, unless it's required to have it update without reloading. Unfortunately I can't seem to find anything that does that :unamused:
|
||||
|
||||
Also this would _require_ caching, since it will fetch huge amounts of data from disk...
|
||||
`,
|
||||
IssueIndex: 2,
|
||||
PosterID: 1669571,
|
||||
PosterName: "mrsdizzie",
|
||||
Created: time.Date(2019, 11, 12, 21, 0, 13, 0, time.UTC),
|
||||
Content: "This is a comment",
|
||||
Reactions: &base.Reactions{
|
||||
TotalCount: 2,
|
||||
PlusOne: 2,
|
||||
TotalCount: 1,
|
||||
PlusOne: 1,
|
||||
MinusOne: 0,
|
||||
Laugh: 0,
|
||||
Confused: 0,
|
||||
@@ -300,14 +231,11 @@ Also this would _require_ caching, since it will fetch huge amounts of data from
|
||||
},
|
||||
},
|
||||
{
|
||||
IssueIndex: 6,
|
||||
PosterID: 1520407,
|
||||
PosterName: "joubertredrat",
|
||||
Created: time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC),
|
||||
Content: `Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this.
|
||||
|
||||
In my case I use ajax to get data, but build on frontend anyway
|
||||
`,
|
||||
IssueIndex: 2,
|
||||
PosterID: 1669571,
|
||||
PosterName: "mrsdizzie",
|
||||
Created: time.Date(2019, 11, 12, 22, 7, 14, 0, time.UTC),
|
||||
Content: "A second comment",
|
||||
Reactions: &base.Reactions{
|
||||
TotalCount: 0,
|
||||
PlusOne: 0,
|
||||
@@ -318,154 +246,85 @@ In my case I use ajax to get data, but build on frontend anyway
|
||||
Hooray: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
IssueIndex: 6,
|
||||
PosterID: 1799009,
|
||||
PosterName: "xinity",
|
||||
Created: time.Date(2016, 11, 03, 13, 04, 56, 0, time.UTC),
|
||||
Content: `following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources.
|
||||
something like in the latest 15days could be enough don't you think ?
|
||||
`,
|
||||
Reactions: &base.Reactions{
|
||||
TotalCount: 2,
|
||||
PlusOne: 2,
|
||||
MinusOne: 0,
|
||||
Laugh: 0,
|
||||
Confused: 0,
|
||||
Heart: 0,
|
||||
Hooray: 0,
|
||||
},
|
||||
},
|
||||
}, comments[:3])
|
||||
}, comments[:2])
|
||||
|
||||
// downloader.GetPullRequests()
|
||||
prs, err := downloader.GetPullRequests(1, 3)
|
||||
prs, err := downloader.GetPullRequests(1, 2)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 3, len(prs))
|
||||
assert.EqualValues(t, 2, len(prs))
|
||||
|
||||
closed1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
|
||||
var (
|
||||
closed2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
|
||||
closed3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
|
||||
)
|
||||
closed1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)
|
||||
var merged1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)
|
||||
|
||||
var (
|
||||
merged1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
|
||||
merged2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
|
||||
merged3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
|
||||
)
|
||||
assert.EqualValues(t, []*base.PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
Title: "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"",
|
||||
Content: "",
|
||||
Milestone: "1.0.0",
|
||||
PosterID: 7011819,
|
||||
PosterName: "andreynering",
|
||||
Number: 3,
|
||||
Title: "Update README.md",
|
||||
Content: "add warning to readme",
|
||||
Milestone: "1.1.0",
|
||||
PosterID: 1669571,
|
||||
PosterName: "mrsdizzie",
|
||||
State: "closed",
|
||||
Created: time.Date(2016, 11, 02, 17, 01, 19, 0, time.UTC),
|
||||
Created: time.Date(2019, 11, 12, 21, 21, 43, 0, time.UTC),
|
||||
Labels: []*base.Label{
|
||||
{
|
||||
Name: "kind/enhancement",
|
||||
Color: "84b6eb",
|
||||
},
|
||||
{
|
||||
Name: "lgtm/done",
|
||||
Color: "0e8a16",
|
||||
Name: "documentation",
|
||||
Color: "0075ca",
|
||||
Description: "Improvements or additions to documentation",
|
||||
},
|
||||
},
|
||||
PatchURL: "https://github.com/go-gitea/gitea/pull/1.patch",
|
||||
PatchURL: "https://github.com/go-gitea/test_repo/pull/3.patch",
|
||||
Head: base.PullRequestBranch{
|
||||
Ref: "import-paths",
|
||||
SHA: "1b0ec3208db8501acba44a137c009a5a126ebaa9",
|
||||
OwnerName: "andreynering",
|
||||
Ref: "master",
|
||||
CloneURL: "https://github.com/mrsdizzie/test_repo.git",
|
||||
SHA: "076160cf0b039f13e5eff19619932d181269414b",
|
||||
RepoName: "test_repo",
|
||||
|
||||
OwnerName: "mrsdizzie",
|
||||
},
|
||||
Base: base.PullRequestBranch{
|
||||
Ref: "master",
|
||||
SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
|
||||
SHA: "72866af952e98d02a73003501836074b286a78f6",
|
||||
OwnerName: "go-gitea",
|
||||
RepoName: "gitea",
|
||||
RepoName: "test_repo",
|
||||
},
|
||||
Closed: &closed1,
|
||||
Merged: true,
|
||||
MergedTime: &merged1,
|
||||
MergeCommitSHA: "142d35e8d2baec230ddb565d1265940d59141fab",
|
||||
MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
||||
},
|
||||
{
|
||||
Number: 2,
|
||||
Title: "Fix sender of issue notifications",
|
||||
Content: "It is the FROM field in mailer configuration that needs be used,\r\nnot the USER field, which is for authentication.\r\n\r\nMigrated from https://github.com/gogits/gogs/pull/3616\r\n",
|
||||
Number: 4,
|
||||
Title: "Test branch",
|
||||
Content: "do not merge this PR",
|
||||
Milestone: "1.0.0",
|
||||
PosterID: 289678,
|
||||
PosterName: "strk",
|
||||
State: "closed",
|
||||
Created: time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC),
|
||||
PosterID: 1669571,
|
||||
PosterName: "mrsdizzie",
|
||||
State: "open",
|
||||
Created: time.Date(2019, 11, 12, 21, 54, 18, 0, time.UTC),
|
||||
Labels: []*base.Label{
|
||||
{
|
||||
Name: "kind/bug",
|
||||
Color: "ee0701",
|
||||
},
|
||||
{
|
||||
Name: "lgtm/done",
|
||||
Color: "0e8a16",
|
||||
Name: "bug",
|
||||
Color: "d73a4a",
|
||||
Description: "Something isn't working",
|
||||
},
|
||||
},
|
||||
PatchURL: "https://github.com/go-gitea/gitea/pull/2.patch",
|
||||
PatchURL: "https://github.com/go-gitea/test_repo/pull/4.patch",
|
||||
Head: base.PullRequestBranch{
|
||||
Ref: "proper-from-on-issue-mail",
|
||||
SHA: "af03d00780a6ee70c58e135c6679542cde4f8d50",
|
||||
RepoName: "gogs",
|
||||
OwnerName: "strk",
|
||||
CloneURL: "https://github.com/strk/gogs.git",
|
||||
Ref: "test-branch",
|
||||
SHA: "2be9101c543658591222acbee3eb799edfc3853d",
|
||||
RepoName: "test_repo",
|
||||
OwnerName: "mrsdizzie",
|
||||
CloneURL: "https://github.com/mrsdizzie/test_repo.git",
|
||||
},
|
||||
Base: base.PullRequestBranch{
|
||||
Ref: "develop",
|
||||
SHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
|
||||
Ref: "master",
|
||||
SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
||||
OwnerName: "go-gitea",
|
||||
RepoName: "gitea",
|
||||
RepoName: "test_repo",
|
||||
},
|
||||
Closed: &closed2,
|
||||
Merged: true,
|
||||
MergedTime: &merged2,
|
||||
MergeCommitSHA: "d8de2beb5b92d02a0597ba7c7803839380666653",
|
||||
},
|
||||
{
|
||||
Number: 3,
|
||||
Title: "Use proper url for libravatar dep",
|
||||
Content: "Fetch go-libravatar from its official source, rather than from an unmaintained fork\r\n",
|
||||
Milestone: "1.0.0",
|
||||
PosterID: 289678,
|
||||
PosterName: "strk",
|
||||
State: "closed",
|
||||
Created: time.Date(2016, 11, 02, 17, 34, 31, 0, time.UTC),
|
||||
Labels: []*base.Label{
|
||||
{
|
||||
Name: "kind/enhancement",
|
||||
Color: "84b6eb",
|
||||
},
|
||||
{
|
||||
Name: "lgtm/done",
|
||||
Color: "0e8a16",
|
||||
},
|
||||
},
|
||||
PatchURL: "https://github.com/go-gitea/gitea/pull/3.patch",
|
||||
Head: base.PullRequestBranch{
|
||||
Ref: "libravatar-proper-url",
|
||||
SHA: "d59a48a2550abd4129b96d38473941b895a4859b",
|
||||
RepoName: "gogs",
|
||||
OwnerName: "strk",
|
||||
CloneURL: "https://github.com/strk/gogs.git",
|
||||
},
|
||||
Base: base.PullRequestBranch{
|
||||
Ref: "develop",
|
||||
SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
|
||||
OwnerName: "go-gitea",
|
||||
RepoName: "gitea",
|
||||
},
|
||||
Closed: &closed3,
|
||||
Merged: true,
|
||||
MergedTime: &merged3,
|
||||
MergeCommitSHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
|
||||
Merged: false,
|
||||
MergeCommitSHA: "565d1208f5fffdc1c5ae1a2436491eb9a5e4ebae",
|
||||
},
|
||||
}, prs)
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ func MigrateRepository(doer *models.User, ownerName string, opts base.MigrateOpt
|
||||
opts.PullRequests = false
|
||||
opts.GitServiceType = structs.PlainGitService
|
||||
downloader = NewPlainGitDownloader(ownerName, opts.RepoName, opts.CloneAddr)
|
||||
log.Trace("Will migrate from git: %s", opts.CloneAddr)
|
||||
log.Trace("Will migrate from git: %s", opts.OriginalURL)
|
||||
} else if opts.GitServiceType == structs.NotMigrated {
|
||||
opts.GitServiceType = theFactory.GitServiceType()
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func MigrateRepository(doer *models.User, ownerName string, opts base.MigrateOpt
|
||||
log.Error("rollback failed: %v", err1)
|
||||
}
|
||||
|
||||
if err2 := models.CreateRepositoryNotice(fmt.Sprintf("Migrate repository from %s failed: %v", opts.CloneAddr, err)); err2 != nil {
|
||||
if err2 := models.CreateRepositoryNotice(fmt.Sprintf("Migrate repository from %s failed: %v", opts.OriginalURL, err)); err2 != nil {
|
||||
log.Error("create respotiry notice failed: ", err2)
|
||||
}
|
||||
return nil, err
|
||||
@@ -94,6 +94,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
|
||||
if err := uploader.CreateRepo(repo, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
defer uploader.Close()
|
||||
|
||||
log.Trace("migrating topics")
|
||||
topics, err := downloader.GetTopics()
|
||||
@@ -164,6 +165,11 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
|
||||
}
|
||||
releases = releases[relBatchSize:]
|
||||
}
|
||||
|
||||
// Once all releases (if any) are inserted, sync any remaining non-release tags
|
||||
if err := uploader.SyncTags(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var commentBatchSize = uploader.MaxBatchInsertSize("comment")
|
||||
|
@@ -5,8 +5,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
@@ -40,11 +38,7 @@ func updateMigrationPosterIDByGitService(tp structs.GitServiceType) error {
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
externalUserID, err := strconv.ParseInt(user.ExternalID, 10, 64)
|
||||
if err != nil {
|
||||
log.Warn("Parse externalUser %#v 's userID failed: %v", user, err)
|
||||
continue
|
||||
}
|
||||
externalUserID := user.ExternalID
|
||||
if err := models.UpdateMigrationsByType(tp, externalUserID, user.UserID); err != nil {
|
||||
log.Error("UpdateMigrationsByType type %s external user id %v to local user id %v failed: %v", tp.Name(), user.ExternalID, user.UserID, err)
|
||||
}
|
||||
|
@@ -107,3 +107,8 @@ func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
|
||||
func (r *indexerNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||
issue_indexer.UpdateIssueIndexer(issue)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||
issue_indexer.UpdateRepoIndexer(repo)
|
||||
models.UpdateRepoIndexer(repo)
|
||||
}
|
||||
|
@@ -7,45 +7,60 @@ package password
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
var matchComplexities = map[string]regexp.Regexp{}
|
||||
var matchComplexityOnce sync.Once
|
||||
var validChars string
|
||||
var validComplexities = map[string]string{
|
||||
"lower": "abcdefghijklmnopqrstuvwxyz",
|
||||
"upper": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"digit": "0123456789",
|
||||
"spec": `][ !"#$%&'()*+,./:;<=>?@\^_{|}~` + "`-",
|
||||
}
|
||||
var (
|
||||
matchComplexityOnce sync.Once
|
||||
validChars string
|
||||
requiredChars []string
|
||||
|
||||
charComplexities = map[string]string{
|
||||
"lower": `abcdefghijklmnopqrstuvwxyz`,
|
||||
"upper": `ABCDEFGHIJKLMNOPQRSTUVWXYZ`,
|
||||
"digit": `0123456789`,
|
||||
"spec": ` !"#$%&'()*+,-./:;<=>?@[\]^_{|}~` + "`",
|
||||
}
|
||||
)
|
||||
|
||||
// NewComplexity for preparation
|
||||
func NewComplexity() {
|
||||
matchComplexityOnce.Do(func() {
|
||||
if len(setting.PasswordComplexity) > 0 {
|
||||
for key, val := range setting.PasswordComplexity {
|
||||
matchComplexity := regexp.MustCompile(val)
|
||||
matchComplexities[key] = *matchComplexity
|
||||
validChars += validComplexities[key]
|
||||
}
|
||||
} else {
|
||||
for _, val := range validComplexities {
|
||||
validChars += val
|
||||
}
|
||||
}
|
||||
setupComplexity(setting.PasswordComplexity)
|
||||
})
|
||||
}
|
||||
|
||||
// IsComplexEnough return True if password is Complexity
|
||||
func setupComplexity(values []string) {
|
||||
if len(values) != 1 || values[0] != "off" {
|
||||
for _, val := range values {
|
||||
if chars, ok := charComplexities[val]; ok {
|
||||
validChars += chars
|
||||
requiredChars = append(requiredChars, chars)
|
||||
}
|
||||
}
|
||||
if len(requiredChars) == 0 {
|
||||
// No valid character classes found; use all classes as default
|
||||
for _, chars := range charComplexities {
|
||||
validChars += chars
|
||||
requiredChars = append(requiredChars, chars)
|
||||
}
|
||||
}
|
||||
}
|
||||
if validChars == "" {
|
||||
// No complexities to check; provide a sensible default for password generation
|
||||
validChars = charComplexities["lower"] + charComplexities["upper"] + charComplexities["digit"]
|
||||
}
|
||||
}
|
||||
|
||||
// IsComplexEnough return True if password meets complexity settings
|
||||
func IsComplexEnough(pwd string) bool {
|
||||
if len(setting.PasswordComplexity) > 0 {
|
||||
NewComplexity()
|
||||
for _, val := range matchComplexities {
|
||||
if !val.MatchString(pwd) {
|
||||
NewComplexity()
|
||||
if len(validChars) > 0 {
|
||||
for _, req := range requiredChars {
|
||||
if !strings.ContainsAny(req, pwd) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
75
modules/password/password_test.go
Normal file
75
modules/password/password_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package password
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestComplexity_IsComplexEnough(t *testing.T) {
|
||||
matchComplexityOnce.Do(func() {})
|
||||
|
||||
testlist := []struct {
|
||||
complexity []string
|
||||
truevalues []string
|
||||
falsevalues []string
|
||||
}{
|
||||
{[]string{"lower"}, []string{"abc", "abc!"}, []string{"ABC", "123", "=!$", ""}},
|
||||
{[]string{"upper"}, []string{"ABC"}, []string{"abc", "123", "=!$", "abc!", ""}},
|
||||
{[]string{"digit"}, []string{"123"}, []string{"abc", "ABC", "=!$", "abc!", ""}},
|
||||
{[]string{"spec"}, []string{"=!$", "abc!"}, []string{"abc", "ABC", "123", ""}},
|
||||
{[]string{"off"}, []string{"abc", "ABC", "123", "=!$", "abc!", ""}, nil},
|
||||
{[]string{"lower", "spec"}, []string{"abc!"}, []string{"abc", "ABC", "123", "=!$", "abcABC123", ""}},
|
||||
{[]string{"lower", "upper", "digit"}, []string{"abcABC123"}, []string{"abc", "ABC", "123", "=!$", "abc!", ""}},
|
||||
}
|
||||
|
||||
for _, test := range testlist {
|
||||
testComplextity(test.complexity)
|
||||
for _, val := range test.truevalues {
|
||||
assert.True(t, IsComplexEnough(val))
|
||||
}
|
||||
for _, val := range test.falsevalues {
|
||||
assert.False(t, IsComplexEnough(val))
|
||||
}
|
||||
}
|
||||
|
||||
// Remove settings for other tests
|
||||
testComplextity([]string{"off"})
|
||||
}
|
||||
|
||||
func TestComplexity_Generate(t *testing.T) {
|
||||
matchComplexityOnce.Do(func() {})
|
||||
|
||||
const maxCount = 50
|
||||
const pwdLen = 50
|
||||
|
||||
test := func(t *testing.T, modes []string) {
|
||||
testComplextity(modes)
|
||||
for i := 0; i < maxCount; i++ {
|
||||
pwd, err := Generate(pwdLen)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, pwdLen, len(pwd))
|
||||
assert.True(t, IsComplexEnough(pwd), "Failed complexities with modes %+v for generated: %s", modes, pwd)
|
||||
}
|
||||
}
|
||||
|
||||
test(t, []string{"lower"})
|
||||
test(t, []string{"upper"})
|
||||
test(t, []string{"lower", "upper", "spec"})
|
||||
test(t, []string{"off"})
|
||||
test(t, []string{""})
|
||||
|
||||
// Remove settings for other tests
|
||||
testComplextity([]string{"off"})
|
||||
}
|
||||
|
||||
func testComplextity(values []string) {
|
||||
// Cleanup previous values
|
||||
validChars = ""
|
||||
requiredChars = make([]string, 0, len(values))
|
||||
setupComplexity(values)
|
||||
}
|
@@ -24,7 +24,7 @@ type Response struct {
|
||||
ErrorCodes []string `json:"error-codes"`
|
||||
}
|
||||
|
||||
const apiURL = "/api/siteverify"
|
||||
const apiURL = "api/siteverify"
|
||||
|
||||
// Verify calls Google Recaptcha API to verify token
|
||||
func Verify(response string) (bool, error) {
|
||||
|
@@ -26,7 +26,7 @@ var (
|
||||
// TODO: fix invalid linking issue
|
||||
|
||||
// mentionPattern matches all mentions in the form of "@user"
|
||||
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_\.]+)(?:\s|$|\)|\])`)
|
||||
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`)
|
||||
// issueNumericPattern matches string that references to a numeric issue, e.g. #1287
|
||||
issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`)
|
||||
// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
|
||||
|
@@ -204,14 +204,32 @@ func TestFindAllIssueReferences(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRegExp_mentionPattern(t *testing.T) {
|
||||
trueTestCases := []string{
|
||||
"@Unknwon",
|
||||
"@ANT_123",
|
||||
"@xxx-DiN0-z-A..uru..s-xxx",
|
||||
" @lol ",
|
||||
" @Te-st",
|
||||
"(@gitea)",
|
||||
"[@gitea]",
|
||||
trueTestCases := []struct {
|
||||
pat string
|
||||
exp string
|
||||
}{
|
||||
{"@Unknwon", "@Unknwon"},
|
||||
{"@ANT_123", "@ANT_123"},
|
||||
{"@xxx-DiN0-z-A..uru..s-xxx", "@xxx-DiN0-z-A..uru..s-xxx"},
|
||||
{" @lol ", "@lol"},
|
||||
{" @Te-st", "@Te-st"},
|
||||
{"(@gitea)", "@gitea"},
|
||||
{"[@gitea]", "@gitea"},
|
||||
{"@gitea! this", "@gitea"},
|
||||
{"@gitea? this", "@gitea"},
|
||||
{"@gitea. this", "@gitea"},
|
||||
{"@gitea, this", "@gitea"},
|
||||
{"@gitea; this", "@gitea"},
|
||||
{"@gitea!\nthis", "@gitea"},
|
||||
{"\n@gitea?\nthis", "@gitea"},
|
||||
{"\t@gitea.\nthis", "@gitea"},
|
||||
{"@gitea,\nthis", "@gitea"},
|
||||
{"@gitea;\nthis", "@gitea"},
|
||||
{"@gitea!", "@gitea"},
|
||||
{"@gitea?", "@gitea"},
|
||||
{"@gitea.", "@gitea"},
|
||||
{"@gitea,", "@gitea"},
|
||||
{"@gitea;", "@gitea"},
|
||||
}
|
||||
falseTestCases := []string{
|
||||
"@ 0",
|
||||
@@ -219,17 +237,24 @@ func TestRegExp_mentionPattern(t *testing.T) {
|
||||
"@",
|
||||
"",
|
||||
"ABC",
|
||||
"@.ABC",
|
||||
"/home/gitea/@gitea",
|
||||
"\"@gitea\"",
|
||||
"@@gitea",
|
||||
"@gitea!this",
|
||||
"@gitea?this",
|
||||
"@gitea,this",
|
||||
"@gitea;this",
|
||||
}
|
||||
|
||||
for _, testCase := range trueTestCases {
|
||||
res := mentionPattern.MatchString(testCase)
|
||||
assert.True(t, res)
|
||||
found := mentionPattern.FindStringSubmatch(testCase.pat)
|
||||
assert.Len(t, found, 2)
|
||||
assert.Equal(t, testCase.exp, found[1])
|
||||
}
|
||||
for _, testCase := range falseTestCases {
|
||||
res := mentionPattern.MatchString(testCase)
|
||||
assert.False(t, res)
|
||||
assert.False(t, res, "[%s] should be false", testCase)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -53,9 +53,11 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
|
||||
}
|
||||
if err := gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
|
||||
if !git.IsErrUnsupportedVersion(err) {
|
||||
gitRepo.Close()
|
||||
return err
|
||||
}
|
||||
}
|
||||
gitRepo.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +134,10 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
|
||||
|
||||
shaSum, err = gitRepo.GetBranchCommitID(refName)
|
||||
if err != nil {
|
||||
gitRepo.Close()
|
||||
log.Error("GetBranchCommitID[%s]: %v", opts.RefFullName, err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
if err = models.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
|
||||
Ref: refName,
|
||||
Sha: shaSum,
|
||||
@@ -167,8 +171,10 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
|
||||
}
|
||||
shaSum, err = gitRepo.GetTagCommitID(refName)
|
||||
if err != nil {
|
||||
gitRepo.Close()
|
||||
log.Error("GetTagCommitID[%s]: %v", opts.RefFullName, err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
if err = models.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
|
||||
Ref: refName,
|
||||
Sha: shaSum,
|
||||
|
@@ -17,6 +17,7 @@ func GetBlobBySHA(repo *models.Repository, sha string) (*api.GitBlobResponse, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
gitBlob, err := gitRepo.GetBlob(sha)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -21,6 +21,8 @@ func TestGetBlobBySHA(t *testing.T) {
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
ctx.SetParams(":id", "1")
|
||||
ctx.SetParams(":sha", sha)
|
||||
|
@@ -23,8 +23,10 @@ func CreateCommitStatus(repo *models.Repository, creator *models.User, sha strin
|
||||
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
|
||||
}
|
||||
if _, err := gitRepo.GetCommit(sha); err != nil {
|
||||
gitRepo.Close()
|
||||
return fmt.Errorf("GetCommit[%s]: %v", sha, err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
|
||||
if err := models.NewCommitStatus(models.NewCommitStatusOptions{
|
||||
Repo: repo,
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user