mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-03 08:02:36 +09:00 
			
		
		
		
	Compare commits
	
		
			43 Commits
		
	
	
		
			v1.13.0-rc
			...
			v1.10.0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					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 | 
							
								
								
									
										80
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										80
									
								
								CHANGELOG.md
									
									
									
									
									
								
							@@ -4,12 +4,18 @@ 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
 | 
					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).
 | 
					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.0](https://github.com/go-gitea/gitea/releases/tag/v1.10.0) - 2019-11-13
 | 
				
			||||||
* BREAKING
 | 
					* 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)
 | 
					  * Remove legacy handling of drone token (#8191)
 | 
				
			||||||
  * Change repo search to use exact match for topic search. (#7941)
 | 
					  * 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)
 | 
					  * 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)
 | 
					  * Implement the ability to change the ssh port to match what is in the gitea config (#7286)
 | 
				
			||||||
 | 
					* SECURITY
 | 
				
			||||||
 | 
					  * Ignore mentions for users with no access (#8395)
 | 
				
			||||||
 | 
					  * Be more strict with git arguments (#7715)
 | 
				
			||||||
 | 
					  * reserve .well-known username (#7637)
 | 
				
			||||||
* FEATURE
 | 
					* FEATURE
 | 
				
			||||||
  * Org/Members: display 2FA members states + optimize sql requests (#7621)
 | 
					  * Org/Members: display 2FA members states + optimize sql requests (#7621)
 | 
				
			||||||
  * SetDefaultBranch on pushing to empty repository (#7610)
 | 
					  * SetDefaultBranch on pushing to empty repository (#7610)
 | 
				
			||||||
@@ -19,6 +25,42 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
 | 
				
			|||||||
  * Add option to initialize repository with labels (#6061)
 | 
					  * Add option to initialize repository with labels (#6061)
 | 
				
			||||||
  * Add additional password hash algorithms (#6023)
 | 
					  * Add additional password hash algorithms (#6023)
 | 
				
			||||||
* BUGFIXES
 | 
					* 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)
 | 
				
			||||||
 | 
					  * Fix issue with user.fullname (#8903)
 | 
				
			||||||
 | 
					  * 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 errors in create org UI regarding team access permission (#8506)
 | 
				
			||||||
  * Fix bug on FindExternalUsersByProvider (#8504)
 | 
					  * Fix bug on FindExternalUsersByProvider (#8504)
 | 
				
			||||||
  * Create .ssh dir as necessary (#8486)
 | 
					  * Create .ssh dir as necessary (#8486)
 | 
				
			||||||
@@ -218,10 +260,6 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
 | 
				
			|||||||
  * Support setting cookie domain (#6288)
 | 
					  * Support setting cookie domain (#6288)
 | 
				
			||||||
  * Move migrating repository from frontend to backend (#6200)
 | 
					  * Move migrating repository from frontend to backend (#6200)
 | 
				
			||||||
  * Delete releases attachments if release is deleted (#6068)
 | 
					  * 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
 | 
					* TRANSLATION
 | 
				
			||||||
  * Latvian translation for home page (#8468)
 | 
					  * Latvian translation for home page (#8468)
 | 
				
			||||||
  * Add home template italian translation (#8352)
 | 
					  * Add home template italian translation (#8352)
 | 
				
			||||||
@@ -263,6 +301,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)
 | 
					  * 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)
 | 
					  * 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
 | 
					## [1.9.4](https://github.com/go-gitea/gitea/releases/tag/v1.9.4) - 2019-10-08
 | 
				
			||||||
* BUGFIXES
 | 
					* BUGFIXES
 | 
				
			||||||
  * Highlight issue references (#8101) (#8404)
 | 
					  * Highlight issue references (#8101) (#8404)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -375,17 +375,20 @@ func runRepoSyncReleases(c *cli.Context) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
 | 
								if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
 | 
				
			||||||
				log.Warn(" SyncReleasesWithTags: %v", err)
 | 
									log.Warn(" SyncReleasesWithTags: %v", err)
 | 
				
			||||||
 | 
									gitRepo.Close()
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			count, err = getReleaseCount(repo.ID)
 | 
								count, err = getReleaseCount(repo.ID)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				log.Warn(" GetReleaseCountByRepoID: %v", err)
 | 
									log.Warn(" GetReleaseCountByRepoID: %v", err)
 | 
				
			||||||
 | 
									gitRepo.Close()
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			log.Trace(" repo %s releases synchronized to tags: from %d to %d",
 | 
								log.Trace(" repo %s releases synchronized to tags: from %d to %d",
 | 
				
			||||||
				repo.FullName(), oldnum, count)
 | 
									repo.FullName(), oldnum, count)
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -277,10 +277,12 @@ LOG_SQL = true
 | 
				
			|||||||
DB_RETRIES = 10
 | 
					DB_RETRIES = 10
 | 
				
			||||||
; Backoff time per DB retry (time.Duration)
 | 
					; Backoff time per DB retry (time.Duration)
 | 
				
			||||||
DB_RETRY_BACKOFF = 3s
 | 
					DB_RETRY_BACKOFF = 3s
 | 
				
			||||||
; Max idle database connections on connnection pool, default is 0
 | 
					; Max idle database connections on connnection pool, default is 2
 | 
				
			||||||
MAX_IDLE_CONNS = 0
 | 
					MAX_IDLE_CONNS = 2
 | 
				
			||||||
; Database connection max life time, default is 3s
 | 
					; Database connection max life time, default is 0 or 3s mysql (See #6804 & #7071 for reasoning)
 | 
				
			||||||
CONN_MAX_LIFETIME = 3s
 | 
					CONN_MAX_LIFETIME = 3s
 | 
				
			||||||
 | 
					; Database maximum number of open connections, default is 0 meaning no maximum
 | 
				
			||||||
 | 
					MAX_OPEN_CONNS = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[indexer]
 | 
					[indexer]
 | 
				
			||||||
; Issue indexer type, currently support: bleve or db, default is bleve
 | 
					; 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
 | 
					; Set to true to prevent all users (including admin) from creating custom git hooks
 | 
				
			||||||
DISABLE_GIT_HOOKS = false
 | 
					DISABLE_GIT_HOOKS = false
 | 
				
			||||||
;Comma separated list of character classes required to pass minimum complexity.
 | 
					;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_COMPLEXITY = lower,upper,digit,spec
 | 
				
			||||||
; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt"
 | 
					; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt"
 | 
				
			||||||
PASSWORD_HASH_ALGO = pbkdf2
 | 
					PASSWORD_HASH_ALGO = pbkdf2
 | 
				
			||||||
@@ -822,6 +825,6 @@ TOKEN =
 | 
				
			|||||||
QUEUE_TYPE = channel
 | 
					QUEUE_TYPE = channel
 | 
				
			||||||
; Task queue length, available only when `QUEUE_TYPE` is `channel`.
 | 
					; Task queue length, available only when `QUEUE_TYPE` is `channel`.
 | 
				
			||||||
QUEUE_LENGTH = 1000
 | 
					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`.
 | 
					; 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.
 | 
					- `LOG_SQL`: **true**: Log the executed SQL.
 | 
				
			||||||
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.
 | 
					- `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.
 | 
					- `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
 | 
					- `MAX_OPEN_CONNS` **0**: Database maximum open connections - default is 0, meaning there is no limit.
 | 
				
			||||||
- `CONN_MAX_LIFETIME` **3s**: Database connection max lifetime
 | 
					- `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`)
 | 
					## Indexer (`indexer`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -212,7 +216,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
 | 
				
			|||||||
    - lower - use one or more lower latin characters
 | 
					    - lower - use one or more lower latin characters
 | 
				
			||||||
    - upper - use one or more upper latin characters
 | 
					    - upper - use one or more upper latin characters
 | 
				
			||||||
    - digit - use one or more digits
 | 
					    - 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`)
 | 
					## OpenID (`openid`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,6 +68,7 @@ type Uploader interface {
 | 
				
			|||||||
	CreateComment(issueNumber int64, comment *Comment) error
 | 
						CreateComment(issueNumber int64, comment *Comment) error
 | 
				
			||||||
	CreatePullRequest(pr *PullRequest) error
 | 
						CreatePullRequest(pr *PullRequest) error
 | 
				
			||||||
	Rollback() error
 | 
						Rollback() error
 | 
				
			||||||
 | 
						Close()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,6 +51,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	gitRepo, err := git.OpenRepository(repo.RepoPath())
 | 
						gitRepo, err := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = gitRepo.CreateTag("v0.0.1", "master")
 | 
						err = gitRepo.CreateTag("v0.0.1", "master")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
@@ -112,6 +113,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	gitRepo, err := git.OpenRepository(repo.RepoPath())
 | 
						gitRepo, err := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = gitRepo.CreateTag("v0.0.1", "master")
 | 
						err = gitRepo.CreateTag("v0.0.1", "master")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -139,6 +139,7 @@ func TestAPICreateFile(t *testing.T) {
 | 
				
			|||||||
			assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
 | 
								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.Email, fileResponse.Commit.Author.Email)
 | 
				
			||||||
			assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
 | 
								assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Test creating a file in a new branch
 | 
							// Test creating a file in a new branch
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -143,6 +143,7 @@ func TestAPIUpdateFile(t *testing.T) {
 | 
				
			|||||||
			assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
 | 
								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.Email, fileResponse.Commit.Author.Email)
 | 
				
			||||||
			assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
 | 
								assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Test updating a file in a new branch
 | 
							// 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)
 | 
						repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
 | 
				
			||||||
	// Get the commit ID of the default branch
 | 
						// Get the commit ID of the default branch
 | 
				
			||||||
	gitRepo, _ := git.OpenRepository(repo1.RepoPath())
 | 
						gitRepo, _ := git.OpenRepository(repo1.RepoPath())
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
 | 
						commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
 | 
				
			||||||
	// Make a new tag in repo1
 | 
						// Make a new tag in repo1
 | 
				
			||||||
	newTag := "test_tag"
 | 
						newTag := "test_tag"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,6 +75,8 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
 | 
				
			|||||||
	repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
 | 
						repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
 | 
				
			||||||
	// Get the commit ID of the default branch
 | 
						// Get the commit ID of the default branch
 | 
				
			||||||
	gitRepo, _ := git.OpenRepository(repo1.RepoPath())
 | 
						gitRepo, _ := git.OpenRepository(repo1.RepoPath())
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
 | 
						commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
 | 
				
			||||||
	// Make a new tag in repo1
 | 
						// Make a new tag in repo1
 | 
				
			||||||
	newTag := "test_tag"
 | 
						newTag := "test_tag"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,8 @@ func TestAPIGitTags(t *testing.T) {
 | 
				
			|||||||
	git.NewCommand("config", "user.email", user.Email).RunInDir(repo.RepoPath())
 | 
						git.NewCommand("config", "user.email", user.Email).RunInDir(repo.RepoPath())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
						gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commit, _ := gitRepo.GetBranchCommit("master")
 | 
						commit, _ := gitRepo.GetBranchCommit("master")
 | 
				
			||||||
	lTagName := "lightweightTag"
 | 
						lTagName := "lightweightTag"
 | 
				
			||||||
	gitRepo.CreateTag(lTagName, commit.ID.String())
 | 
						gitRepo.CreateTag(lTagName, commit.ID.String())
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,6 @@ func TestAPITeamUser(t *testing.T) {
 | 
				
			|||||||
	var user2 *api.User
 | 
						var user2 *api.User
 | 
				
			||||||
	DecodeJSON(t, resp, &user2)
 | 
						DecodeJSON(t, resp, &user2)
 | 
				
			||||||
	user2.Created = user2.Created.In(time.Local)
 | 
						user2.Created = user2.Created.In(time.Local)
 | 
				
			||||||
	user2.LastLogin = user2.LastLogin.In(time.Local)
 | 
					 | 
				
			||||||
	user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
 | 
						user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assert.Equal(t, convert.ToUser(user, true, false), user2)
 | 
						assert.Equal(t, convert.ToUser(user, true, false), user2)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,7 @@ func TestUserHeatmap(t *testing.T) {
 | 
				
			|||||||
	var heatmap []*models.UserHeatmapData
 | 
						var heatmap []*models.UserHeatmapData
 | 
				
			||||||
	DecodeJSON(t, resp, &heatmap)
 | 
						DecodeJSON(t, resp, &heatmap)
 | 
				
			||||||
	var dummyheatmap []*models.UserHeatmapData
 | 
						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)
 | 
						assert.Equal(t, dummyheatmap, heatmap)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,6 +73,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
	repo := ctx.Repo.Repository
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
	doer := ctx.User
 | 
						doer := ctx.User
 | 
				
			||||||
	opts := getDeleteRepoFileOptions(repo)
 | 
						opts := getDeleteRepoFileOptions(repo)
 | 
				
			||||||
@@ -111,6 +112,8 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := ctx.Repo.Repository
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
	doer := ctx.User
 | 
						doer := ctx.User
 | 
				
			||||||
	opts := getDeleteRepoFileOptions(repo)
 | 
						opts := getDeleteRepoFileOptions(repo)
 | 
				
			||||||
@@ -139,6 +142,8 @@ func TestDeleteRepoFileErrors(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := ctx.Repo.Repository
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
	doer := ctx.User
 | 
						doer := ctx.User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -191,6 +191,8 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
 | 
				
			|||||||
		test.LoadRepoCommit(t, ctx)
 | 
							test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
		test.LoadUser(t, ctx, 2)
 | 
							test.LoadUser(t, ctx, 2)
 | 
				
			||||||
		test.LoadGitRepo(t, ctx)
 | 
							test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
							defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		repo := ctx.Repo.Repository
 | 
							repo := ctx.Repo.Repository
 | 
				
			||||||
		doer := ctx.User
 | 
							doer := ctx.User
 | 
				
			||||||
		opts := getCreateRepoFileOptions(repo)
 | 
							opts := getCreateRepoFileOptions(repo)
 | 
				
			||||||
@@ -201,6 +203,8 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
 | 
				
			|||||||
		// asserts
 | 
							// asserts
 | 
				
			||||||
		assert.Nil(t, err)
 | 
							assert.Nil(t, err)
 | 
				
			||||||
		gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
							gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
 | 
							defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
 | 
							commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
 | 
				
			||||||
		expectedFileResponse := getExpectedFileResponseForRepofilesCreate(commitID)
 | 
							expectedFileResponse := getExpectedFileResponseForRepofilesCreate(commitID)
 | 
				
			||||||
		assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
 | 
							assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
 | 
				
			||||||
@@ -220,6 +224,8 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
 | 
				
			|||||||
		test.LoadRepoCommit(t, ctx)
 | 
							test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
		test.LoadUser(t, ctx, 2)
 | 
							test.LoadUser(t, ctx, 2)
 | 
				
			||||||
		test.LoadGitRepo(t, ctx)
 | 
							test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
							defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		repo := ctx.Repo.Repository
 | 
							repo := ctx.Repo.Repository
 | 
				
			||||||
		doer := ctx.User
 | 
							doer := ctx.User
 | 
				
			||||||
		opts := getUpdateRepoFileOptions(repo)
 | 
							opts := getUpdateRepoFileOptions(repo)
 | 
				
			||||||
@@ -230,6 +236,8 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
 | 
				
			|||||||
		// asserts
 | 
							// asserts
 | 
				
			||||||
		assert.Nil(t, err)
 | 
							assert.Nil(t, err)
 | 
				
			||||||
		gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
							gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
 | 
							defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
 | 
							commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
 | 
				
			||||||
		expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
 | 
							expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
 | 
				
			||||||
		assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
 | 
							assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
 | 
				
			||||||
@@ -249,6 +257,8 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
 | 
				
			|||||||
		test.LoadRepoCommit(t, ctx)
 | 
							test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
		test.LoadUser(t, ctx, 2)
 | 
							test.LoadUser(t, ctx, 2)
 | 
				
			||||||
		test.LoadGitRepo(t, ctx)
 | 
							test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
							defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		repo := ctx.Repo.Repository
 | 
							repo := ctx.Repo.Repository
 | 
				
			||||||
		doer := ctx.User
 | 
							doer := ctx.User
 | 
				
			||||||
		opts := getUpdateRepoFileOptions(repo)
 | 
							opts := getUpdateRepoFileOptions(repo)
 | 
				
			||||||
@@ -261,6 +271,8 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
 | 
				
			|||||||
		// asserts
 | 
							// asserts
 | 
				
			||||||
		assert.Nil(t, err)
 | 
							assert.Nil(t, err)
 | 
				
			||||||
		gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
							gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
 | 
							defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
 | 
							commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
 | 
				
			||||||
		expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.TreePath)
 | 
							expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.TreePath)
 | 
				
			||||||
		// assert that the old file no longer exists in the last commit of the branch
 | 
							// 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.LoadRepoCommit(t, ctx)
 | 
				
			||||||
		test.LoadUser(t, ctx, 2)
 | 
							test.LoadUser(t, ctx, 2)
 | 
				
			||||||
		test.LoadGitRepo(t, ctx)
 | 
							test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
							defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		repo := ctx.Repo.Repository
 | 
							repo := ctx.Repo.Repository
 | 
				
			||||||
		doer := ctx.User
 | 
							doer := ctx.User
 | 
				
			||||||
		opts := getUpdateRepoFileOptions(repo)
 | 
							opts := getUpdateRepoFileOptions(repo)
 | 
				
			||||||
@@ -300,6 +314,8 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
 | 
				
			|||||||
		// asserts
 | 
							// asserts
 | 
				
			||||||
		assert.Nil(t, err)
 | 
							assert.Nil(t, err)
 | 
				
			||||||
		gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
							gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
 | 
							defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch)
 | 
							commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch)
 | 
				
			||||||
		expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
 | 
							expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
 | 
				
			||||||
		assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
 | 
							assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
 | 
				
			||||||
@@ -315,6 +331,8 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
 | 
				
			|||||||
		test.LoadRepoCommit(t, ctx)
 | 
							test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
		test.LoadUser(t, ctx, 2)
 | 
							test.LoadUser(t, ctx, 2)
 | 
				
			||||||
		test.LoadGitRepo(t, ctx)
 | 
							test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
							defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		repo := ctx.Repo.Repository
 | 
							repo := ctx.Repo.Repository
 | 
				
			||||||
		doer := ctx.User
 | 
							doer := ctx.User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,8 +19,8 @@ func TestSignup(t *testing.T) {
 | 
				
			|||||||
	req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
 | 
						req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
 | 
				
			||||||
		"user_name": "exampleUser",
 | 
							"user_name": "exampleUser",
 | 
				
			||||||
		"email":     "exampleUser@example.com",
 | 
							"email":     "exampleUser@example.com",
 | 
				
			||||||
		"password":  "examplePassword",
 | 
							"password":  "examplePassword!1",
 | 
				
			||||||
		"retype":    "examplePassword",
 | 
							"retype":    "examplePassword!1",
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	MakeRequest(t, req, http.StatusFound)
 | 
						MakeRequest(t, req, http.StatusFound)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,9 +28,9 @@ type ExternalLoginUser struct {
 | 
				
			|||||||
	Description       string
 | 
						Description       string
 | 
				
			||||||
	AvatarURL         string
 | 
						AvatarURL         string
 | 
				
			||||||
	Location          string
 | 
						Location          string
 | 
				
			||||||
	AccessToken       string
 | 
						AccessToken       string `xorm:"TEXT"`
 | 
				
			||||||
	AccessTokenSecret string
 | 
						AccessTokenSecret string `xorm:"TEXT"`
 | 
				
			||||||
	RefreshToken      string
 | 
						RefreshToken      string `xorm:"TEXT"`
 | 
				
			||||||
	ExpiresAt         time.Time
 | 
						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
 | 
					// 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 {
 | 
						if err := UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
  act_user_id: 2
 | 
					  act_user_id: 2
 | 
				
			||||||
  repo_id: 2
 | 
					  repo_id: 2
 | 
				
			||||||
  is_private: true
 | 
					  is_private: true
 | 
				
			||||||
  created_unix: 1540139562
 | 
					  created_unix: 1571686356
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-
 | 
					-
 | 
				
			||||||
  id: 2
 | 
					  id: 2
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@
 | 
				
			|||||||
  index: 2
 | 
					  index: 2
 | 
				
			||||||
  head_repo_id: 1
 | 
					  head_repo_id: 1
 | 
				
			||||||
  base_repo_id: 1
 | 
					  base_repo_id: 1
 | 
				
			||||||
  head_user_name: user1
 | 
					 | 
				
			||||||
  head_branch: branch1
 | 
					  head_branch: branch1
 | 
				
			||||||
  base_branch: master
 | 
					  base_branch: master
 | 
				
			||||||
  merge_base: 1234567890abcdef
 | 
					  merge_base: 1234567890abcdef
 | 
				
			||||||
@@ -21,7 +20,6 @@
 | 
				
			|||||||
  index: 3
 | 
					  index: 3
 | 
				
			||||||
  head_repo_id: 1
 | 
					  head_repo_id: 1
 | 
				
			||||||
  base_repo_id: 1
 | 
					  base_repo_id: 1
 | 
				
			||||||
  head_user_name: user1
 | 
					 | 
				
			||||||
  head_branch: branch2
 | 
					  head_branch: branch2
 | 
				
			||||||
  base_branch: master
 | 
					  base_branch: master
 | 
				
			||||||
  merge_base: fedcba9876543210
 | 
					  merge_base: fedcba9876543210
 | 
				
			||||||
@@ -35,7 +33,6 @@
 | 
				
			|||||||
  index: 1
 | 
					  index: 1
 | 
				
			||||||
  head_repo_id: 11
 | 
					  head_repo_id: 11
 | 
				
			||||||
  base_repo_id: 10
 | 
					  base_repo_id: 10
 | 
				
			||||||
  head_user_name: user13
 | 
					 | 
				
			||||||
  head_branch: branch2
 | 
					  head_branch: branch2
 | 
				
			||||||
  base_branch: master
 | 
					  base_branch: master
 | 
				
			||||||
  merge_base: 0abcb056019adb83
 | 
					  merge_base: 0abcb056019adb83
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		b.Error("Could not open repository")
 | 
							b.Error("Could not open repository")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer currentRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i := 0; i < b.N; i++ {
 | 
						for i := 0; i < b.N; i++ {
 | 
				
			||||||
		graph, err := GetCommitGraph(currentRepo)
 | 
							graph, err := GetCommitGraph(currentRepo)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1072,6 +1072,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 {
 | 
							if _, err = e.Exec("UPDATE `milestone` SET num_issues=num_issues+1 WHERE id=?", opts.Issue.MilestoneID); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if _, err = createMilestoneComment(e, doer, opts.Repo, opts.Issue, 0, opts.Issue.MilestoneID); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Insert the assignees
 | 
						// Insert the assignees
 | 
				
			||||||
@@ -1950,7 +1954,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
 | 
					// 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").
 | 
						_, err := x.Table("issue").
 | 
				
			||||||
		Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
 | 
							Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
 | 
				
			||||||
		And("original_author_id = ?", originalAuthorID).
 | 
							And("original_author_id = ?", originalAuthorID).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -538,6 +538,10 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
 | 
				
			|||||||
	switch opts.Type {
 | 
						switch opts.Type {
 | 
				
			||||||
	case CommentTypeCode:
 | 
						case CommentTypeCode:
 | 
				
			||||||
		if comment.ReviewID != 0 {
 | 
							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 comment.Review == nil {
 | 
				
			||||||
				if err := comment.loadReview(e); err != nil {
 | 
									if err := comment.loadReview(e); err != nil {
 | 
				
			||||||
					return err
 | 
										return err
 | 
				
			||||||
@@ -596,6 +600,12 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
 | 
				
			|||||||
		if err = opts.Issue.updateClosedNum(e); err != nil {
 | 
							if err = opts.Issue.updateClosedNum(e); err != nil {
 | 
				
			||||||
			return err
 | 
								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
 | 
						// update the issue's updated_unix column
 | 
				
			||||||
	if err = updateIssueCols(e, opts.Issue, "updated_unix"); err != nil {
 | 
						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
 | 
					// CreateCommentOptions defines options for creating comment
 | 
				
			||||||
type CreateCommentOptions struct {
 | 
					type CreateCommentOptions struct {
 | 
				
			||||||
	Type  CommentType
 | 
						Type   CommentType
 | 
				
			||||||
	Doer  *User
 | 
						Doer   *User
 | 
				
			||||||
	Repo  *Repository
 | 
						Repo   *Repository
 | 
				
			||||||
	Issue *Issue
 | 
						Issue  *Issue
 | 
				
			||||||
	Label *Label
 | 
						Label  *Label
 | 
				
			||||||
 | 
						Review *Review
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DependentIssueID int64
 | 
						DependentIssueID int64
 | 
				
			||||||
	OldMilestoneID   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
 | 
					// 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").
 | 
						_, err := x.Table("comment").
 | 
				
			||||||
		Where(builder.In("issue_id",
 | 
							Where(builder.In("issue_id",
 | 
				
			||||||
			builder.Select("issue.id").
 | 
								builder.Select("issue.id").
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -306,7 +306,11 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m.IsClosed = isClosed
 | 
						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
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -256,6 +256,10 @@ var migrations = []Migration{
 | 
				
			|||||||
	NewMigration("add task table and status column for repository table", addTaskTable),
 | 
						NewMigration("add task table and status column for repository table", addTaskTable),
 | 
				
			||||||
	// v100 -> v101
 | 
						// v100 -> v101
 | 
				
			||||||
	NewMigration("update migration repositories' service type", updateMigrationServiceTypes),
 | 
						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
 | 
					// 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 {
 | 
								if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
 | 
				
			||||||
				log.Warn("SyncReleasesWithTags: %v", err)
 | 
									log.Warn("SyncReleasesWithTags: %v", err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if len(repos) < pageSize {
 | 
							if len(repos) < pageSize {
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,6 +91,7 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error {
 | 
				
			|||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					return err
 | 
										return err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									defer gitRepo.Close()
 | 
				
			||||||
				gitRepoCache[release.RepoID] = gitRepo
 | 
									gitRepoCache[release.RepoID] = gitRepo
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -157,11 +157,9 @@ func SetEngine() (err error) {
 | 
				
			|||||||
	// so use log file to instead print to stdout.
 | 
						// so use log file to instead print to stdout.
 | 
				
			||||||
	x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
 | 
						x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
 | 
				
			||||||
	x.ShowSQL(setting.Database.LogSQL)
 | 
						x.ShowSQL(setting.Database.LogSQL)
 | 
				
			||||||
	if setting.Database.UseMySQL {
 | 
						x.SetMaxOpenConns(setting.Database.MaxOpenConns)
 | 
				
			||||||
		x.SetMaxIdleConns(setting.Database.MaxIdleConns)
 | 
						x.SetMaxIdleConns(setting.Database.MaxIdleConns)
 | 
				
			||||||
		x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
 | 
						x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,7 +66,6 @@ type PullRequest struct {
 | 
				
			|||||||
	HeadRepo        *Repository `xorm:"-"`
 | 
						HeadRepo        *Repository `xorm:"-"`
 | 
				
			||||||
	BaseRepoID      int64       `xorm:"INDEX"`
 | 
						BaseRepoID      int64       `xorm:"INDEX"`
 | 
				
			||||||
	BaseRepo        *Repository `xorm:"-"`
 | 
						BaseRepo        *Repository `xorm:"-"`
 | 
				
			||||||
	HeadUserName    string
 | 
					 | 
				
			||||||
	HeadBranch      string
 | 
						HeadBranch      string
 | 
				
			||||||
	BaseBranch      string
 | 
						BaseBranch      string
 | 
				
			||||||
	ProtectedBranch *ProtectedBranch `xorm:"-"`
 | 
						ProtectedBranch *ProtectedBranch `xorm:"-"`
 | 
				
			||||||
@@ -79,6 +78,15 @@ type PullRequest struct {
 | 
				
			|||||||
	MergedUnix     timeutil.TimeStamp `xorm:"updated INDEX"`
 | 
						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.
 | 
					// Note: don't try to get Issue because will end up recursive querying.
 | 
				
			||||||
func (pr *PullRequest) loadAttributes(e Engine) (err error) {
 | 
					func (pr *PullRequest) loadAttributes(e Engine) (err error) {
 | 
				
			||||||
	if pr.HasMerged && pr.Merger == nil {
 | 
						if pr.HasMerged && pr.Merger == nil {
 | 
				
			||||||
@@ -102,6 +110,10 @@ func (pr *PullRequest) LoadAttributes() error {
 | 
				
			|||||||
// LoadBaseRepo loads pull request base repository from database
 | 
					// LoadBaseRepo loads pull request base repository from database
 | 
				
			||||||
func (pr *PullRequest) LoadBaseRepo() error {
 | 
					func (pr *PullRequest) LoadBaseRepo() error {
 | 
				
			||||||
	if pr.BaseRepo == nil {
 | 
						if pr.BaseRepo == nil {
 | 
				
			||||||
 | 
							if pr.HeadRepoID == pr.BaseRepoID && pr.HeadRepo != nil {
 | 
				
			||||||
 | 
								pr.BaseRepo = pr.HeadRepo
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		var repo Repository
 | 
							var repo Repository
 | 
				
			||||||
		if has, err := x.ID(pr.BaseRepoID).Get(&repo); err != nil {
 | 
							if has, err := x.ID(pr.BaseRepoID).Get(&repo); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
@@ -113,6 +125,24 @@ func (pr *PullRequest) LoadBaseRepo() error {
 | 
				
			|||||||
	return nil
 | 
						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
 | 
					// LoadIssue loads issue information from database
 | 
				
			||||||
func (pr *PullRequest) LoadIssue() (err error) {
 | 
					func (pr *PullRequest) LoadIssue() (err error) {
 | 
				
			||||||
	return pr.loadIssue(x)
 | 
						return pr.loadIssue(x)
 | 
				
			||||||
@@ -152,7 +182,7 @@ func (pr *PullRequest) GetDefaultMergeMessage() string {
 | 
				
			|||||||
			return ""
 | 
								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
 | 
					// 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 {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer headGitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lastCommitID, err := headGitRepo.GetBranchCommitID(pr.HeadBranch)
 | 
						lastCommitID, err := headGitRepo.GetBranchCommitID(pr.HeadBranch)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -541,6 +572,7 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("OpenRepository: %v", err)
 | 
							return nil, fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commit, err := gitRepo.GetCommit(mergeCommit[:40])
 | 
						commit, err := gitRepo.GetCommit(mergeCommit[:40])
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -925,6 +957,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("OpenRepository: %v", err)
 | 
							return fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer headGitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Add a temporary remote.
 | 
						// Add a temporary remote.
 | 
				
			||||||
	tmpRemote := com.ToStr(time.Now().UnixNano())
 | 
						tmpRemote := com.ToStr(time.Now().UnixNano())
 | 
				
			||||||
@@ -966,6 +999,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("OpenRepository: %v", err)
 | 
							return fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer headGitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID)
 | 
						tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID)
 | 
				
			||||||
	if err = headGitRepo.AddRemote(tmpRemoteName, pr.BaseRepo.RepoPath(), false); err != nil {
 | 
						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 {
 | 
							if err != nil {
 | 
				
			||||||
			log.Error("PullRequestList.InvalidateCodeComments: %v", err)
 | 
								log.Error("PullRequestList.InvalidateCodeComments: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							gitRepo.Close()
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
	return nil
 | 
						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,
 | 
					// checkAndUpdateStatus checks if pull request is possible to leaving checking status,
 | 
				
			||||||
// and set to be either conflict or mergeable.
 | 
					// and set to be either conflict or mergeable.
 | 
				
			||||||
func (pr *PullRequest) checkAndUpdateStatus() {
 | 
					func (pr *PullRequest) checkAndUpdateStatus() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -232,20 +232,6 @@ func TestPullRequestList_LoadAttributes(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// TODO TestAddTestPullRequestTask
 | 
					// 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) {
 | 
					func TestPullRequest_IsWorkInProgress(t *testing.T) {
 | 
				
			||||||
	assert.NoError(t, PrepareTestDatabase())
 | 
						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
 | 
					// 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").
 | 
						_, err := x.Table("release").
 | 
				
			||||||
		Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
 | 
							Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
 | 
				
			||||||
		And("original_author_id = ?", originalAuthorID).
 | 
							And("original_author_id = ?", originalAuthorID).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -998,6 +998,7 @@ func MigrateRepositoryGitData(doer, u *User, repo *Repository, opts api.MigrateR
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return repo, fmt.Errorf("OpenRepository: %v", err)
 | 
							return repo, fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo.IsEmpty, err = gitRepo.IsEmpty()
 | 
						repo.IsEmpty, err = gitRepo.IsEmpty()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -1430,6 +1431,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
 | 
				
			|||||||
		IsFsckEnabled:                   !opts.IsMirror,
 | 
							IsFsckEnabled:                   !opts.IsMirror,
 | 
				
			||||||
		CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
 | 
							CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
 | 
				
			||||||
		Status:                          opts.Status,
 | 
							Status:                          opts.Status,
 | 
				
			||||||
 | 
							IsEmpty:                         !opts.AutoInit,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sess := x.NewSession()
 | 
						sess := x.NewSession()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,6 +64,8 @@ func GetActivityStats(repo *Repository, timeFrom time.Time, releases, issues, pr
 | 
				
			|||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, fmt.Errorf("OpenRepository: %v", err)
 | 
								return nil, fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch)
 | 
							code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, fmt.Errorf("FillFromGit: %v", err)
 | 
								return nil, fmt.Errorf("FillFromGit: %v", err)
 | 
				
			||||||
@@ -79,6 +81,8 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("OpenRepository: %v", err)
 | 
							return nil, fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	code, err := gitRepo.GetCodeActivityStats(timeFrom, "")
 | 
						code, err := gitRepo.GetCodeActivityStats(timeFrom, "")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("FillFromGit: %v", err)
 | 
							return nil, fmt.Errorf("FillFromGit: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,7 @@ func (repo *Repository) GetBranch(branch string) (*git.Branch, error) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return gitRepo.GetBranch(branch)
 | 
						return gitRepo.GetBranch(branch)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -38,6 +39,7 @@ func (repo *Repository) CheckBranchName(name string) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	branches, err := repo.GetBranches()
 | 
						branches, err := repo.GetBranches()
 | 
				
			||||||
	if err != nil {
 | 
						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)
 | 
							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)
 | 
							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 {
 | 
						if err = gitRepo.CreateBranch(branchName, oldBranchName); err != nil {
 | 
				
			||||||
		log.Error("Unable to create branch: %s from %s. (%v)", branchName, oldBranchName, err)
 | 
							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)
 | 
							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)
 | 
							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 {
 | 
						if err = gitRepo.CreateBranch(branchName, commit); err != nil {
 | 
				
			||||||
		log.Error("Unable to create branch: %s from %s. (%v)", branchName, commit, err)
 | 
							log.Error("Unable to create branch: %s from %s. (%v)", branchName, commit, err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,
 | 
											Repo:    review.Issue.Repo,
 | 
				
			||||||
						Type:    comm.Type,
 | 
											Type:    comm.Type,
 | 
				
			||||||
						Content: comm.Content,
 | 
											Content: comm.Content,
 | 
				
			||||||
 | 
											Review:  r,
 | 
				
			||||||
					}, comm); err != nil {
 | 
										}, comm); err != nil {
 | 
				
			||||||
						log.Warn("sendCreateCommentAction: %v", err)
 | 
											log.Warn("sendCreateCommentAction: %v", err)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -107,7 +107,7 @@ func parseKeyString(content string) (string, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var keyType, keyContent, keyComment string
 | 
						var keyType, keyContent, keyComment string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if content[:len(ssh2keyStart)] == ssh2keyStart {
 | 
						if strings.HasPrefix(content, ssh2keyStart) {
 | 
				
			||||||
		// Parse SSH2 file format.
 | 
							// Parse SSH2 file format.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Transform all legal line endings to a single "\n".
 | 
							// Transform all legal line endings to a single "\n".
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -131,6 +131,19 @@ AAAAC3NzaC1lZDI1NTE5AAAAICV0MGX/W9IvLA4FXpIuUcdDcbj5KX4syHgsTy7soVgf
 | 
				
			|||||||
		_, err := CheckPublicKeyString(test.content)
 | 
							_, err := CheckPublicKeyString(test.content)
 | 
				
			||||||
		assert.NoError(t, err)
 | 
							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) {
 | 
					func Test_calcFingerprint(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -994,10 +994,6 @@ func ChangeUserName(u *User, newUserName string) (err error) {
 | 
				
			|||||||
		return ErrUserAlreadyExist{newUserName}
 | 
							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
 | 
						// Do not fail if directory does not exist
 | 
				
			||||||
	if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
 | 
						if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
 | 
				
			||||||
		return fmt.Errorf("Rename user directory: %v", err)
 | 
							return fmt.Errorf("Rename user directory: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
 | 
				
			|||||||
		CountResult int
 | 
							CountResult int
 | 
				
			||||||
		JSONResult  string
 | 
							JSONResult  string
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
 | 
							{2, 1, `[{"timestamp":1571616000,"contributions":1}]`},
 | 
				
			||||||
		{3, 0, `[]`},
 | 
							{3, 0, `[]`},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Prepare
 | 
						// Prepare
 | 
				
			||||||
@@ -41,7 +41,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
 | 
				
			|||||||
		// Get the heatmap and compare
 | 
							// Get the heatmap and compare
 | 
				
			||||||
		heatmap, err := GetUserHeatmapDataByUser(user)
 | 
							heatmap, err := GetUserHeatmapDataByUser(user)
 | 
				
			||||||
		assert.NoError(t, err)
 | 
							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))
 | 
							assert.Equal(t, tc.CountResult, len(heatmap))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Test JSON rendering
 | 
							//Test JSON rendering
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -833,6 +833,8 @@ func (t *HookTask) deliver() error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case http.MethodGet:
 | 
						case http.MethodGet:
 | 
				
			||||||
		u, err := url.Parse(t.URL)
 | 
							u, err := url.Parse(t.URL)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -140,6 +140,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldWikiName, newWikiName, con
 | 
				
			|||||||
		log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
 | 
							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)
 | 
							return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if hasMasterBranch {
 | 
						if hasMasterBranch {
 | 
				
			||||||
		if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
 | 
							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)
 | 
							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)
 | 
							return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
 | 
						if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
 | 
				
			||||||
		log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
 | 
							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:
 | 
								// Now need to show that the page has been added:
 | 
				
			||||||
			gitRepo, err := git.OpenRepository(repo.WikiPath())
 | 
								gitRepo, err := git.OpenRepository(repo.WikiPath())
 | 
				
			||||||
			assert.NoError(t, err)
 | 
								assert.NoError(t, err)
 | 
				
			||||||
 | 
								defer gitRepo.Close()
 | 
				
			||||||
			masterTree, err := gitRepo.GetTree("master")
 | 
								masterTree, err := gitRepo.GetTree("master")
 | 
				
			||||||
			assert.NoError(t, err)
 | 
								assert.NoError(t, err)
 | 
				
			||||||
			wikiPath := WikiNameToFilename(wikiName)
 | 
								wikiPath := WikiNameToFilename(wikiName)
 | 
				
			||||||
@@ -214,6 +215,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
 | 
				
			|||||||
			_, err := masterTree.GetTreeEntryByPath("Home.md")
 | 
								_, err := masterTree.GetTreeEntryByPath("Home.md")
 | 
				
			||||||
			assert.Error(t, err)
 | 
								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:
 | 
						// Now need to show that the page has been added:
 | 
				
			||||||
	gitRepo, err := git.OpenRepository(repo.WikiPath())
 | 
						gitRepo, err := git.OpenRepository(repo.WikiPath())
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
	masterTree, err := gitRepo.GetTree("master")
 | 
						masterTree, err := gitRepo.GetTree("master")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	wikiPath := WikiNameToFilename("Home")
 | 
						wikiPath := WikiNameToFilename("Home")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -186,7 +186,16 @@ func ReferencesGitRepo(allowEmpty bool) macaron.Handler {
 | 
				
			|||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			ctx.Repo.GitRepo = gitRepo
 | 
								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.
 | 
						// Force redirection when username is actually a user.
 | 
				
			||||||
	if !org.IsOrganization() {
 | 
						if !org.IsOrganization() {
 | 
				
			||||||
		ctx.Redirect("/" + org.Name)
 | 
							ctx.Redirect(setting.AppSubURL + "/" + org.Name)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -236,7 +236,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
 | 
				
			|||||||
	if ctx.Req.URL.RawQuery != "" {
 | 
						if ctx.Req.URL.RawQuery != "" {
 | 
				
			||||||
		redirectPath += "?" + 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) {
 | 
					func repoAssignment(ctx *Context, repo *models.Repository) {
 | 
				
			||||||
@@ -414,8 +414,8 @@ func RepoAssignment() macaron.Handler {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// repo is empty and display enable
 | 
							// Disable everything when the repo is being created
 | 
				
			||||||
		if ctx.Repo.Repository.IsEmpty || ctx.Repo.Repository.IsBeingCreated() {
 | 
							if ctx.Repo.Repository.IsBeingCreated() {
 | 
				
			||||||
			ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
 | 
								ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -427,6 +427,21 @@ func RepoAssignment() macaron.Handler {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		ctx.Repo.GitRepo = gitRepo
 | 
							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()
 | 
							tags, err := ctx.Repo.GitRepo.GetTags()
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			ctx.ServerError("GetTags", err)
 | 
								ctx.ServerError("GetTags", err)
 | 
				
			||||||
@@ -482,6 +497,7 @@ func RepoAssignment() macaron.Handler {
 | 
				
			|||||||
			ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
 | 
								ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
 | 
				
			||||||
			ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
 | 
								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)
 | 
									ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
 | 
				
			||||||
				return
 | 
									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.
 | 
							// Get default branch.
 | 
				
			||||||
@@ -675,6 +698,8 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
 | 
							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
 | 
					// CreateBlameReader creates reader for given repository, commit and file
 | 
				
			||||||
func CreateBlameReader(repoPath, commitID, file string) (*BlameReader, error) {
 | 
					func CreateBlameReader(repoPath, commitID, file string) (*BlameReader, error) {
 | 
				
			||||||
	_, err := OpenRepository(repoPath)
 | 
						gitRepo, err := OpenRepository(repoPath)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return createBlameReader(repoPath, GitExecutable, "blame", commitID, "--porcelain", "--", file)
 | 
						return createBlameReader(repoPath, GitExecutable, "blame", commitID, "--porcelain", "--", file)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,6 +37,8 @@ THE SOFTWARE.
 | 
				
			|||||||
`
 | 
					`
 | 
				
			||||||
	repo, err := OpenRepository("../../.git")
 | 
						repo, err := OpenRepository("../../.git")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer repo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
 | 
						testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,6 +57,8 @@ func Benchmark_Blob_Data(b *testing.B) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		b.Fatal(err)
 | 
							b.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer repo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
 | 
						testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		b.Fatal(err)
 | 
							b.Fatal(err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,6 +77,8 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testGetCommitsInfo(t, bareRepo1)
 | 
						testGetCommitsInfo(t, bareRepo1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo")
 | 
						clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo")
 | 
				
			||||||
@@ -84,6 +86,8 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
 | 
				
			|||||||
	defer os.RemoveAll(clonedPath)
 | 
						defer os.RemoveAll(clonedPath)
 | 
				
			||||||
	clonedRepo1, err := OpenRepository(clonedPath)
 | 
						clonedRepo1, err := OpenRepository(clonedPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer clonedRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testGetCommitsInfo(t, clonedRepo1)
 | 
						testGetCommitsInfo(t, clonedRepo1)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -101,13 +105,16 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
 | 
				
			|||||||
	for _, benchmark := range benchmarks {
 | 
						for _, benchmark := range benchmarks {
 | 
				
			||||||
		var commit *Commit
 | 
							var commit *Commit
 | 
				
			||||||
		var entries Entries
 | 
							var entries Entries
 | 
				
			||||||
 | 
							var repo *Repository
 | 
				
			||||||
		if repoPath, err := cloneRepo(benchmark.url, benchmarkReposDir, benchmark.name); err != nil {
 | 
							if repoPath, err := cloneRepo(benchmark.url, benchmarkReposDir, benchmark.name); err != nil {
 | 
				
			||||||
			b.Fatal(err)
 | 
								b.Fatal(err)
 | 
				
			||||||
		} else if repo, err := OpenRepository(repoPath); err != nil {
 | 
							} else if repo, err = OpenRepository(repoPath); err != nil {
 | 
				
			||||||
			b.Fatal(err)
 | 
								b.Fatal(err)
 | 
				
			||||||
		} else if commit, err = repo.GetBranchCommit("master"); err != nil {
 | 
							} else if commit, err = repo.GetBranchCommit("master"); err != nil {
 | 
				
			||||||
 | 
								repo.Close()
 | 
				
			||||||
			b.Fatal(err)
 | 
								b.Fatal(err)
 | 
				
			||||||
		} else if entries, err = commit.Tree.ListEntries(); err != nil {
 | 
							} else if entries, err = commit.Tree.ListEntries(); err != nil {
 | 
				
			||||||
 | 
								repo.Close()
 | 
				
			||||||
			b.Fatal(err)
 | 
								b.Fatal(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		entries.Sort()
 | 
							entries.Sort()
 | 
				
			||||||
@@ -120,5 +127,6 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
							repo.Close()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ package git
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -133,6 +134,13 @@ func Init() error {
 | 
				
			|||||||
			return fmt.Errorf("Failed to execute 'git config --global gc.writeCommitGraph true': %s", stderr)
 | 
								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
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,6 +90,11 @@ func (h *Hook) Update() error {
 | 
				
			|||||||
		h.IsActive = false
 | 
							h.IsActive = false
 | 
				
			||||||
		return nil
 | 
							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)
 | 
						err := ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ func TestGetNotes(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	note := Note{}
 | 
						note := Note{}
 | 
				
			||||||
	err = GetNote(bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
 | 
						err = GetNote(bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
 | 
				
			||||||
@@ -27,6 +28,7 @@ func TestGetNestedNotes(t *testing.T) {
 | 
				
			|||||||
	repoPath := filepath.Join(testReposDir, "repo3_notes")
 | 
						repoPath := filepath.Join(testReposDir, "repo3_notes")
 | 
				
			||||||
	repo, err := OpenRepository(repoPath)
 | 
						repo, err := OpenRepository(repoPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer repo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	note := Note{}
 | 
						note := Note{}
 | 
				
			||||||
	err = GetNote(repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
 | 
						err = GetNote(repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gitealog "code.gitea.io/gitea/modules/log"
 | 
				
			||||||
	"github.com/unknwon/com"
 | 
						"github.com/unknwon/com"
 | 
				
			||||||
	"gopkg.in/src-d/go-billy.v4/osfs"
 | 
						"gopkg.in/src-d/go-billy.v4/osfs"
 | 
				
			||||||
	gogit "gopkg.in/src-d/go-git.v4"
 | 
						gogit "gopkg.in/src-d/go-git.v4"
 | 
				
			||||||
@@ -107,6 +108,21 @@ func OpenRepository(repoPath string) (*Repository, error) {
 | 
				
			|||||||
	}, nil
 | 
						}, 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.
 | 
					// IsEmpty Check if repository is empty.
 | 
				
			||||||
func (repo *Repository) IsEmpty() (bool, error) {
 | 
					func (repo *Repository) IsEmpty() (bool, error) {
 | 
				
			||||||
	var errbuf strings.Builder
 | 
						var errbuf strings.Builder
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ func TestRepository_GetBlob_Found(t *testing.T) {
 | 
				
			|||||||
	repoPath := filepath.Join(testReposDir, "repo1_bare")
 | 
						repoPath := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	r, err := OpenRepository(repoPath)
 | 
						r, err := OpenRepository(repoPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer r.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testCases := []struct {
 | 
						testCases := []struct {
 | 
				
			||||||
		OID  string
 | 
							OID  string
 | 
				
			||||||
@@ -44,6 +45,7 @@ func TestRepository_GetBlob_NotExist(t *testing.T) {
 | 
				
			|||||||
	repoPath := filepath.Join(testReposDir, "repo1_bare")
 | 
						repoPath := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	r, err := OpenRepository(repoPath)
 | 
						r, err := OpenRepository(repoPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer r.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testCase := "0000000000000000000000000000000000000000"
 | 
						testCase := "0000000000000000000000000000000000000000"
 | 
				
			||||||
	testError := ErrNotExist{testCase, ""}
 | 
						testError := ErrNotExist{testCase, ""}
 | 
				
			||||||
@@ -57,6 +59,7 @@ func TestRepository_GetBlob_NoId(t *testing.T) {
 | 
				
			|||||||
	repoPath := filepath.Join(testReposDir, "repo1_bare")
 | 
						repoPath := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	r, err := OpenRepository(repoPath)
 | 
						r, err := OpenRepository(repoPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer r.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testCase := ""
 | 
						testCase := ""
 | 
				
			||||||
	testError := fmt.Errorf("Length must be 40: %s", testCase)
 | 
						testError := fmt.Errorf("Length must be 40: %s", testCase)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,6 +108,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	brs, err := gitRepo.GetBranches()
 | 
						brs, err := gitRepo.GetBranches()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ func TestRepository_GetBranches(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	branches, err := bareRepo1.GetBranches()
 | 
						branches, err := bareRepo1.GetBranches()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -29,6 +30,7 @@ func BenchmarkRepository_GetBranches(b *testing.B) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		b.Fatal(err)
 | 
							b.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i := 0; i < b.N; i++ {
 | 
						for i := 0; i < b.N; i++ {
 | 
				
			||||||
		_, err := bareRepo1.GetBranches()
 | 
							_, err := bareRepo1.GetBranches()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ func TestRepository_GetCommitBranches(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// these test case are specific to the repo1_bare test repo
 | 
						// these test case are specific to the repo1_bare test repo
 | 
				
			||||||
	testCases := []struct {
 | 
						testCases := []struct {
 | 
				
			||||||
@@ -41,6 +42,7 @@ func TestGetTagCommitWithSignature(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
 | 
						commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
@@ -54,6 +56,7 @@ func TestGetCommitWithBadCommitID(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commit, err := bareRepo1.GetCommit("bad_branch")
 | 
						commit, err := bareRepo1.GetCommit("bad_branch")
 | 
				
			||||||
	assert.Nil(t, commit)
 | 
						assert.Nil(t, commit)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@ func TestGetFormatPatch(t *testing.T) {
 | 
				
			|||||||
	defer os.RemoveAll(clonedPath)
 | 
						defer os.RemoveAll(clonedPath)
 | 
				
			||||||
	repo, err := OpenRepository(clonedPath)
 | 
						repo, err := OpenRepository(clonedPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer repo.Close()
 | 
				
			||||||
	rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
 | 
						rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	patchb, err := ioutil.ReadAll(rd)
 | 
						patchb, err := ioutil.ReadAll(rd)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ func TestRepository_GetRefs(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	refs, err := bareRepo1.GetRefs()
 | 
						refs, err := bareRepo1.GetRefs()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -38,6 +39,7 @@ func TestRepository_GetRefsFiltered(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	refs, err := bareRepo1.GetRefsFiltered(TagPrefix)
 | 
						refs, err := bareRepo1.GetRefsFiltered(TagPrefix)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,7 @@ func TestRepository_GetCodeActivityStats(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00")
 | 
						timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,7 @@ func TestRepository_GetTags(t *testing.T) {
 | 
				
			|||||||
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
	bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tags, err := bareRepo1.GetTagInfos()
 | 
						tags, err := bareRepo1.GetTagInfos()
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
@@ -34,6 +35,7 @@ func TestRepository_GetTag(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	bareRepo1, err := OpenRepository(clonedPath)
 | 
						bareRepo1, err := OpenRepository(clonedPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
 | 
						lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
 | 
				
			||||||
	lTagName := "lightweightTag"
 | 
						lTagName := "lightweightTag"
 | 
				
			||||||
@@ -83,6 +85,7 @@ func TestRepository_GetAnnotatedTag(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	bareRepo1, err := OpenRepository(clonedPath)
 | 
						bareRepo1, err := OpenRepository(clonedPath)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
 | 
						lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
 | 
				
			||||||
	lTagName := "lightweightTag"
 | 
						lTagName := "lightweightTag"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,6 +30,7 @@ func TestRepoIsEmpty(t *testing.T) {
 | 
				
			|||||||
	emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
 | 
						emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
 | 
				
			||||||
	repo, err := OpenRepository(emptyRepo2Path)
 | 
						repo, err := OpenRepository(emptyRepo2Path)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer repo.Close()
 | 
				
			||||||
	isEmpty, err := repo.IsEmpty()
 | 
						isEmpty, err := repo.IsEmpty()
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.True(t, isEmpty)
 | 
						assert.True(t, isEmpty)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,6 +56,7 @@ func TestEntriesCustomSort(t *testing.T) {
 | 
				
			|||||||
func TestFollowLink(t *testing.T) {
 | 
					func TestFollowLink(t *testing.T) {
 | 
				
			||||||
	r, err := OpenRepository("tests/repos/repo1_bare")
 | 
						r, err := OpenRepository("tests/repos/repo1_bare")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer r.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123")
 | 
						commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123")
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,4 +17,5 @@ type Uploader interface {
 | 
				
			|||||||
	CreateComments(comments ...*Comment) error
 | 
						CreateComments(comments ...*Comment) error
 | 
				
			||||||
	CreatePullRequests(prs ...*PullRequest) error
 | 
						CreatePullRequests(prs ...*PullRequest) error
 | 
				
			||||||
	Rollback() error
 | 
						Rollback() error
 | 
				
			||||||
 | 
						Close()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -131,6 +131,13 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
 | 
				
			|||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Close closes this uploader
 | 
				
			||||||
 | 
					func (g *GiteaLocalUploader) Close() {
 | 
				
			||||||
 | 
						if g.gitRepo != nil {
 | 
				
			||||||
 | 
							g.gitRepo.Close()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CreateTopics creates topics
 | 
					// CreateTopics creates topics
 | 
				
			||||||
func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
 | 
					func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
 | 
				
			||||||
	return models.SaveTopics(g.repo.ID, topics...)
 | 
						return models.SaveTopics(g.repo.ID, topics...)
 | 
				
			||||||
@@ -252,27 +259,30 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// download attachment
 | 
								// 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 {
 | 
								if err != nil {
 | 
				
			||||||
				return err
 | 
									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)
 | 
								rel.Attachments = append(rel.Attachments, &attach)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -468,21 +478,24 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// download patch file
 | 
						// download patch file
 | 
				
			||||||
	resp, err := http.Get(pr.PatchURL)
 | 
						err := func() error {
 | 
				
			||||||
	if err != nil {
 | 
							resp, err := http.Get(pr.PatchURL)
 | 
				
			||||||
		return nil, err
 | 
							if err != nil {
 | 
				
			||||||
	}
 | 
								return err
 | 
				
			||||||
	defer resp.Body.Close()
 | 
							}
 | 
				
			||||||
	pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
 | 
							defer resp.Body.Close()
 | 
				
			||||||
	if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
 | 
							pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
 | 
				
			||||||
		return nil, err
 | 
							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 {
 | 
							f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
 | 
				
			||||||
		return nil, err
 | 
							if err != nil {
 | 
				
			||||||
	}
 | 
								return err
 | 
				
			||||||
	defer f.Close()
 | 
							}
 | 
				
			||||||
	_, err = io.Copy(f, resp.Body)
 | 
							defer f.Close()
 | 
				
			||||||
 | 
							_, err = io.Copy(f, resp.Body)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -496,8 +509,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer p.Close()
 | 
					 | 
				
			||||||
	_, err = p.WriteString(pr.Head.SHA)
 | 
						_, err = p.WriteString(pr.Head.SHA)
 | 
				
			||||||
 | 
						p.Close()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -531,8 +544,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
 | 
				
			|||||||
					if err != nil {
 | 
										if err != nil {
 | 
				
			||||||
						return nil, err
 | 
											return nil, err
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					defer b.Close()
 | 
					 | 
				
			||||||
					_, err = b.WriteString(pr.Head.SHA)
 | 
										_, err = b.WriteString(pr.Head.SHA)
 | 
				
			||||||
 | 
										b.Close()
 | 
				
			||||||
					if err != nil {
 | 
										if err != nil {
 | 
				
			||||||
						return nil, err
 | 
											return nil, err
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
@@ -579,14 +592,13 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var pullRequest = models.PullRequest{
 | 
						var pullRequest = models.PullRequest{
 | 
				
			||||||
		HeadRepoID:   g.repo.ID,
 | 
							HeadRepoID: g.repo.ID,
 | 
				
			||||||
		HeadBranch:   head,
 | 
							HeadBranch: head,
 | 
				
			||||||
		HeadUserName: g.repoOwner,
 | 
							BaseRepoID: g.repo.ID,
 | 
				
			||||||
		BaseRepoID:   g.repo.ID,
 | 
							BaseBranch: pr.Base.Ref,
 | 
				
			||||||
		BaseBranch:   pr.Base.Ref,
 | 
							MergeBase:  pr.Base.SHA,
 | 
				
			||||||
		MergeBase:    pr.Base.SHA,
 | 
							Index:      pr.Number,
 | 
				
			||||||
		Index:        pr.Number,
 | 
							HasMerged:  pr.Merged,
 | 
				
			||||||
		HasMerged:    pr.Merged,
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Issue: &issue,
 | 
							Issue: &issue,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ import (
 | 
				
			|||||||
	"github.com/stretchr/testify/assert"
 | 
						"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
 | 
						var tmPtr *time.Time
 | 
				
			||||||
	if dueOn != "" {
 | 
						if dueOn != "" {
 | 
				
			||||||
		tm, err := time.Parse("2006-01-02 15:04:05 -0700 MST", 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{
 | 
						assert.EqualValues(t, &base.Milestone{
 | 
				
			||||||
		Title:    title,
 | 
							Description: description,
 | 
				
			||||||
		Deadline: tmPtr,
 | 
							Title:       title,
 | 
				
			||||||
		State:    state,
 | 
							Deadline:    tmPtr,
 | 
				
			||||||
		Created:  createdTM,
 | 
							State:       state,
 | 
				
			||||||
		Updated:  updatedTM,
 | 
							Created:     createdTM,
 | 
				
			||||||
		Closed:   closedTM,
 | 
							Updated:     updatedTM,
 | 
				
			||||||
 | 
							Closed:      closedTM,
 | 
				
			||||||
	}, ms)
 | 
						}, 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{
 | 
						assert.EqualValues(t, &base.Label{
 | 
				
			||||||
		Name:  name,
 | 
							Name:        name,
 | 
				
			||||||
		Color: color,
 | 
							Color:       color,
 | 
				
			||||||
 | 
							Description: description,
 | 
				
			||||||
	}, label)
 | 
						}, label)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGitHubDownloadRepo(t *testing.T) {
 | 
					func TestGitHubDownloadRepo(t *testing.T) {
 | 
				
			||||||
	downloader := NewGithubDownloaderV3("", "", "go-gitea", "gitea")
 | 
						downloader := NewGithubDownloaderV3("", "", "go-gitea", "test_repo")
 | 
				
			||||||
	repo, err := downloader.GetRepoInfo()
 | 
						repo, err := downloader.GetRepoInfo()
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.EqualValues(t, &base.Repository{
 | 
						assert.EqualValues(t, &base.Repository{
 | 
				
			||||||
		Name:        "gitea",
 | 
							Name:        "test_repo",
 | 
				
			||||||
		Owner:       "go-gitea",
 | 
							Owner:       "go-gitea",
 | 
				
			||||||
		Description: "Git with a cup of tea, painless self-hosted git service",
 | 
							Description: "Test repository for testing migration from github to gitea",
 | 
				
			||||||
		CloneURL:    "https://github.com/go-gitea/gitea.git",
 | 
							CloneURL:    "https://github.com/go-gitea/test_repo.git",
 | 
				
			||||||
		OriginalURL: "https://github.com/go-gitea/gitea",
 | 
							OriginalURL: "https://github.com/go-gitea/test_repo",
 | 
				
			||||||
	}, repo)
 | 
						}, repo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	topics, err := downloader.GetTopics()
 | 
						topics, err := downloader.GetTopics()
 | 
				
			||||||
@@ -77,83 +79,46 @@ func TestGitHubDownloadRepo(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	milestones, err := downloader.GetMilestones()
 | 
						milestones, err := downloader.GetMilestones()
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	// before this tool release, we have 39 milestones on github.com/go-gitea/gitea
 | 
						assert.True(t, len(milestones) >= 2)
 | 
				
			||||||
	assert.True(t, len(milestones) >= 39)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, milestone := range milestones {
 | 
						for _, milestone := range milestones {
 | 
				
			||||||
		switch milestone.Title {
 | 
							switch milestone.Title {
 | 
				
			||||||
		case "1.0.0":
 | 
							case "1.0.0":
 | 
				
			||||||
			assertMilestoneEqual(t, "1.0.0", "2016-12-23 08:00:00 +0000 UTC",
 | 
								assertMilestoneEqual(t, "Milestone 1.0.0", "1.0.0", "2019-11-11 08:00:00 +0000 UTC",
 | 
				
			||||||
				"2016-11-02 18:06:55 +0000 UTC",
 | 
									"2019-11-12 19:37:08 +0000 UTC",
 | 
				
			||||||
				"2016-12-29 10:26:00 +0000 UTC",
 | 
									"2019-11-12 21:56:17 +0000 UTC",
 | 
				
			||||||
				"2016-12-24 00:40:56 +0000 UTC",
 | 
									"2019-11-12 19:45:49 +0000 UTC",
 | 
				
			||||||
				"closed", milestone)
 | 
									"closed", milestone)
 | 
				
			||||||
		case "1.1.0":
 | 
							case "1.1.0":
 | 
				
			||||||
			assertMilestoneEqual(t, "1.1.0", "2017-02-24 08:00:00 +0000 UTC",
 | 
								assertMilestoneEqual(t, "Milestone 1.1.0", "1.1.0", "2019-11-12 08:00:00 +0000 UTC",
 | 
				
			||||||
				"2016-11-03 08:40:10 +0000 UTC",
 | 
									"2019-11-12 19:37:25 +0000 UTC",
 | 
				
			||||||
				"2017-06-15 05:04:36 +0000 UTC",
 | 
									"2019-11-12 21:39:27 +0000 UTC",
 | 
				
			||||||
				"2017-03-09 21:22:21 +0000 UTC",
 | 
									"2019-11-12 19:45:46 +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",
 | 
					 | 
				
			||||||
				"closed", milestone)
 | 
									"closed", milestone)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	labels, err := downloader.GetLabels()
 | 
						labels, err := downloader.GetLabels()
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.True(t, len(labels) >= 48)
 | 
						assert.True(t, len(labels) >= 8)
 | 
				
			||||||
	for _, l := range labels {
 | 
						for _, l := range labels {
 | 
				
			||||||
		switch l.Name {
 | 
							switch l.Name {
 | 
				
			||||||
		case "backport/v1.7":
 | 
							case "bug":
 | 
				
			||||||
			assertLabelEqual(t, "backport/v1.7", "fbca04", l)
 | 
								assertLabelEqual(t, "bug", "d73a4a", "Something isn't working", l)
 | 
				
			||||||
		case "backport/v1.8":
 | 
							case "documentation":
 | 
				
			||||||
			assertLabelEqual(t, "backport/v1.8", "fbca04", l)
 | 
								assertLabelEqual(t, "documentation", "0075ca", "Improvements or additions to documentation", l)
 | 
				
			||||||
		case "kind/api":
 | 
							case "duplicate":
 | 
				
			||||||
			assertLabelEqual(t, "kind/api", "5319e7", l)
 | 
								assertLabelEqual(t, "duplicate", "cfd3d7", "This issue or pull request already exists", l)
 | 
				
			||||||
		case "kind/breaking":
 | 
							case "enhancement":
 | 
				
			||||||
			assertLabelEqual(t, "kind/breaking", "fbca04", l)
 | 
								assertLabelEqual(t, "enhancement", "a2eeef", "New feature or request", l)
 | 
				
			||||||
		case "kind/bug":
 | 
							case "good first issue":
 | 
				
			||||||
			assertLabelEqual(t, "kind/bug", "ee0701", l)
 | 
								assertLabelEqual(t, "good first issue", "7057ff", "Good for newcomers", l)
 | 
				
			||||||
		case "kind/docs":
 | 
							case "help wanted":
 | 
				
			||||||
			assertLabelEqual(t, "kind/docs", "c2e0c6", l)
 | 
								assertLabelEqual(t, "help wanted", "008672", "Extra attention is needed", l)
 | 
				
			||||||
		case "kind/enhancement":
 | 
							case "invalid":
 | 
				
			||||||
			assertLabelEqual(t, "kind/enhancement", "84b6eb", l)
 | 
								assertLabelEqual(t, "invalid", "e4e669", "This doesn't seem right", l)
 | 
				
			||||||
		case "kind/feature":
 | 
							case "question":
 | 
				
			||||||
			assertLabelEqual(t, "kind/feature", "006b75", l)
 | 
								assertLabelEqual(t, "question", "d876e3", "Further information is requested", l)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -163,48 +128,50 @@ func TestGitHubDownloadRepo(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			TagName:         "v0.9.99",
 | 
								TagName:         "v0.9.99",
 | 
				
			||||||
			TargetCommitish: "master",
 | 
								TargetCommitish: "master",
 | 
				
			||||||
			Name:            "fork",
 | 
								Name:            "First Release",
 | 
				
			||||||
			Body:            "Forked source from Gogs into Gitea\n",
 | 
								Body:            "A test release",
 | 
				
			||||||
			Created:         time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC),
 | 
								Created:         time.Date(2019, 11, 9, 16, 49, 21, 0, time.UTC),
 | 
				
			||||||
			Published:       time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC),
 | 
								Published:       time.Date(2019, 11, 12, 20, 12, 10, 0, time.UTC),
 | 
				
			||||||
			PublisherID:     4726179,
 | 
								PublisherID:     1669571,
 | 
				
			||||||
			PublisherName:   "bkcsoft",
 | 
								PublisherName:   "mrsdizzie",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}, releases[len(releases)-1:])
 | 
						}, releases[len(releases)-1:])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// downloader.GetIssues()
 | 
						// downloader.GetIssues()
 | 
				
			||||||
	issues, isEnd, err := downloader.GetIssues(1, 8)
 | 
						issues, isEnd, err := downloader.GetIssues(1, 2)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.EqualValues(t, 3, len(issues))
 | 
						assert.EqualValues(t, 2, len(issues))
 | 
				
			||||||
	assert.False(t, isEnd)
 | 
						assert.False(t, isEnd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		closed1 = time.Date(2018, 10, 23, 02, 57, 43, 0, time.UTC)
 | 
							closed1 = time.Date(2019, 11, 12, 20, 22, 22, 0, time.UTC)
 | 
				
			||||||
		closed7 = time.Date(2019, 7, 8, 8, 20, 23, 0, time.UTC)
 | 
							closed2 = time.Date(2019, 11, 12, 21, 1, 31, 0, time.UTC)
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	assert.EqualValues(t, []*base.Issue{
 | 
						assert.EqualValues(t, []*base.Issue{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Number:     6,
 | 
								Number:     1,
 | 
				
			||||||
			Title:      "Contribution system: History heatmap for user",
 | 
								Title:      "Please add an animated gif icon to the merge button",
 | 
				
			||||||
			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",
 | 
								Content:    "I just want the merge button to hurt my eyes a little. \xF0\x9F\x98\x9D ",
 | 
				
			||||||
			Milestone:  "1.7.0",
 | 
								Milestone:  "1.0.0",
 | 
				
			||||||
			PosterID:   1520407,
 | 
								PosterID:   18600385,
 | 
				
			||||||
			PosterName: "joubertredrat",
 | 
								PosterName: "guillep2k",
 | 
				
			||||||
			State:      "closed",
 | 
								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{
 | 
								Labels: []*base.Label{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Name:  "kind/feature",
 | 
										Name:        "bug",
 | 
				
			||||||
					Color: "006b75",
 | 
										Color:       "d73a4a",
 | 
				
			||||||
 | 
										Description: "Something isn't working",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Name:  "kind/ui",
 | 
										Name:        "good first issue",
 | 
				
			||||||
					Color: "fef2c0",
 | 
										Color:       "7057ff",
 | 
				
			||||||
 | 
										Description: "Good for newcomers",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Reactions: &base.Reactions{
 | 
								Reactions: &base.Reactions{
 | 
				
			||||||
				TotalCount: 0,
 | 
									TotalCount: 1,
 | 
				
			||||||
				PlusOne:    0,
 | 
									PlusOne:    1,
 | 
				
			||||||
				MinusOne:   0,
 | 
									MinusOne:   0,
 | 
				
			||||||
				Laugh:      0,
 | 
									Laugh:      0,
 | 
				
			||||||
				Confused:   0,
 | 
									Confused:   0,
 | 
				
			||||||
@@ -214,84 +181,48 @@ func TestGitHubDownloadRepo(t *testing.T) {
 | 
				
			|||||||
			Closed: &closed1,
 | 
								Closed: &closed1,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Number:     7,
 | 
								Number:     2,
 | 
				
			||||||
			Title:      "display page revisions on wiki",
 | 
								Title:      "Test issue",
 | 
				
			||||||
			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",
 | 
								Content:    "This is test issue 2, do not touch!",
 | 
				
			||||||
			Milestone:  "1.10.0",
 | 
								Milestone:  "1.1.0",
 | 
				
			||||||
			PosterID:   1520407,
 | 
								PosterID:   1669571,
 | 
				
			||||||
			PosterName: "joubertredrat",
 | 
								PosterName: "mrsdizzie",
 | 
				
			||||||
			State:      "closed",
 | 
								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{
 | 
								Labels: []*base.Label{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Name:  "kind/feature",
 | 
										Name:        "duplicate",
 | 
				
			||||||
					Color: "006b75",
 | 
										Color:       "cfd3d7",
 | 
				
			||||||
				},
 | 
										Description: "This issue or pull request already exists",
 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					Name:        "reviewed/confirmed",
 | 
					 | 
				
			||||||
					Color:       "8d9b12",
 | 
					 | 
				
			||||||
					Description: "Issue has been reviewed and confirmed to be present or accepted to be implemented",
 | 
					 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Reactions: &base.Reactions{
 | 
								Reactions: &base.Reactions{
 | 
				
			||||||
				TotalCount: 6,
 | 
									TotalCount: 6,
 | 
				
			||||||
				PlusOne:    5,
 | 
									PlusOne:    1,
 | 
				
			||||||
				MinusOne:   0,
 | 
									MinusOne:   1,
 | 
				
			||||||
				Laugh:      0,
 | 
									Laugh:      1,
 | 
				
			||||||
				Confused:   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,
 | 
									Heart:      1,
 | 
				
			||||||
				Hooray:     0,
 | 
									Hooray:     1,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
 | 
								Closed: &closed2,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}, issues)
 | 
						}, issues)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// downloader.GetComments()
 | 
						// downloader.GetComments()
 | 
				
			||||||
	comments, err := downloader.GetComments(6)
 | 
						comments, err := downloader.GetComments(2)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.EqualValues(t, 35, len(comments))
 | 
						assert.EqualValues(t, 2, len(comments))
 | 
				
			||||||
	assert.EqualValues(t, []*base.Comment{
 | 
						assert.EqualValues(t, []*base.Comment{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			IssueIndex: 6,
 | 
								IssueIndex: 2,
 | 
				
			||||||
			PosterID:   4726179,
 | 
								PosterID:   1669571,
 | 
				
			||||||
			PosterName: "bkcsoft",
 | 
								PosterName: "mrsdizzie",
 | 
				
			||||||
			Created:    time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC),
 | 
								Created:    time.Date(2019, 11, 12, 21, 0, 13, 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: 
 | 
								Content:    "This is a comment",
 | 
				
			||||||
 | 
					 | 
				
			||||||
Also this would _require_ caching, since it will fetch huge amounts of data from disk...
 | 
					 | 
				
			||||||
`,
 | 
					 | 
				
			||||||
			Reactions: &base.Reactions{
 | 
								Reactions: &base.Reactions{
 | 
				
			||||||
				TotalCount: 2,
 | 
									TotalCount: 1,
 | 
				
			||||||
				PlusOne:    2,
 | 
									PlusOne:    1,
 | 
				
			||||||
				MinusOne:   0,
 | 
									MinusOne:   0,
 | 
				
			||||||
				Laugh:      0,
 | 
									Laugh:      0,
 | 
				
			||||||
				Confused:   0,
 | 
									Confused:   0,
 | 
				
			||||||
@@ -300,14 +231,11 @@ Also this would _require_ caching, since it will fetch huge amounts of data from
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			IssueIndex: 6,
 | 
								IssueIndex: 2,
 | 
				
			||||||
			PosterID:   1520407,
 | 
								PosterID:   1669571,
 | 
				
			||||||
			PosterName: "joubertredrat",
 | 
								PosterName: "mrsdizzie",
 | 
				
			||||||
			Created:    time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC),
 | 
								Created:    time.Date(2019, 11, 12, 22, 7, 14, 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.
 | 
								Content:    "A second comment",
 | 
				
			||||||
 | 
					 | 
				
			||||||
In my case I use ajax to get data, but build on frontend anyway
 | 
					 | 
				
			||||||
`,
 | 
					 | 
				
			||||||
			Reactions: &base.Reactions{
 | 
								Reactions: &base.Reactions{
 | 
				
			||||||
				TotalCount: 0,
 | 
									TotalCount: 0,
 | 
				
			||||||
				PlusOne:    0,
 | 
									PlusOne:    0,
 | 
				
			||||||
@@ -318,154 +246,85 @@ In my case I use ajax to get data, but build on frontend anyway
 | 
				
			|||||||
				Hooray:     0,
 | 
									Hooray:     0,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
						}, comments[:2])
 | 
				
			||||||
			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])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// downloader.GetPullRequests()
 | 
						// downloader.GetPullRequests()
 | 
				
			||||||
	prs, err := downloader.GetPullRequests(1, 3)
 | 
						prs, err := downloader.GetPullRequests(1, 2)
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						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)
 | 
						closed1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)
 | 
				
			||||||
	var (
 | 
						var merged1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)
 | 
				
			||||||
		closed2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
 | 
					 | 
				
			||||||
		closed3 = time.Date(2016, 11, 02, 18, 22, 31, 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{
 | 
						assert.EqualValues(t, []*base.PullRequest{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Number:     1,
 | 
								Number:     3,
 | 
				
			||||||
			Title:      "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"",
 | 
								Title:      "Update README.md",
 | 
				
			||||||
			Content:    "",
 | 
								Content:    "add warning to readme",
 | 
				
			||||||
			Milestone:  "1.0.0",
 | 
								Milestone:  "1.1.0",
 | 
				
			||||||
			PosterID:   7011819,
 | 
								PosterID:   1669571,
 | 
				
			||||||
			PosterName: "andreynering",
 | 
								PosterName: "mrsdizzie",
 | 
				
			||||||
			State:      "closed",
 | 
								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{
 | 
								Labels: []*base.Label{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Name:  "kind/enhancement",
 | 
										Name:        "documentation",
 | 
				
			||||||
					Color: "84b6eb",
 | 
										Color:       "0075ca",
 | 
				
			||||||
				},
 | 
										Description: "Improvements or additions to documentation",
 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					Name:  "lgtm/done",
 | 
					 | 
				
			||||||
					Color: "0e8a16",
 | 
					 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			PatchURL: "https://github.com/go-gitea/gitea/pull/1.patch",
 | 
								PatchURL: "https://github.com/go-gitea/test_repo/pull/3.patch",
 | 
				
			||||||
			Head: base.PullRequestBranch{
 | 
								Head: base.PullRequestBranch{
 | 
				
			||||||
				Ref:       "import-paths",
 | 
									Ref:      "master",
 | 
				
			||||||
				SHA:       "1b0ec3208db8501acba44a137c009a5a126ebaa9",
 | 
									CloneURL: "https://github.com/mrsdizzie/test_repo.git",
 | 
				
			||||||
				OwnerName: "andreynering",
 | 
									SHA:      "076160cf0b039f13e5eff19619932d181269414b",
 | 
				
			||||||
 | 
									RepoName: "test_repo",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									OwnerName: "mrsdizzie",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Base: base.PullRequestBranch{
 | 
								Base: base.PullRequestBranch{
 | 
				
			||||||
				Ref:       "master",
 | 
									Ref:       "master",
 | 
				
			||||||
				SHA:       "6bcff7828f117af8d51285ce3acba01a7e40a867",
 | 
									SHA:       "72866af952e98d02a73003501836074b286a78f6",
 | 
				
			||||||
				OwnerName: "go-gitea",
 | 
									OwnerName: "go-gitea",
 | 
				
			||||||
				RepoName:  "gitea",
 | 
									RepoName:  "test_repo",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Closed:         &closed1,
 | 
								Closed:         &closed1,
 | 
				
			||||||
			Merged:         true,
 | 
								Merged:         true,
 | 
				
			||||||
			MergedTime:     &merged1,
 | 
								MergedTime:     &merged1,
 | 
				
			||||||
			MergeCommitSHA: "142d35e8d2baec230ddb565d1265940d59141fab",
 | 
								MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Number:     2,
 | 
								Number:     4,
 | 
				
			||||||
			Title:      "Fix sender of issue notifications",
 | 
								Title:      "Test branch",
 | 
				
			||||||
			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",
 | 
								Content:    "do not merge this PR",
 | 
				
			||||||
			Milestone:  "1.0.0",
 | 
								Milestone:  "1.0.0",
 | 
				
			||||||
			PosterID:   289678,
 | 
								PosterID:   1669571,
 | 
				
			||||||
			PosterName: "strk",
 | 
								PosterName: "mrsdizzie",
 | 
				
			||||||
			State:      "closed",
 | 
								State:      "open",
 | 
				
			||||||
			Created:    time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC),
 | 
								Created:    time.Date(2019, 11, 12, 21, 54, 18, 0, time.UTC),
 | 
				
			||||||
			Labels: []*base.Label{
 | 
								Labels: []*base.Label{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Name:  "kind/bug",
 | 
										Name:        "bug",
 | 
				
			||||||
					Color: "ee0701",
 | 
										Color:       "d73a4a",
 | 
				
			||||||
				},
 | 
										Description: "Something isn't working",
 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					Name:  "lgtm/done",
 | 
					 | 
				
			||||||
					Color: "0e8a16",
 | 
					 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			PatchURL: "https://github.com/go-gitea/gitea/pull/2.patch",
 | 
								PatchURL: "https://github.com/go-gitea/test_repo/pull/4.patch",
 | 
				
			||||||
			Head: base.PullRequestBranch{
 | 
								Head: base.PullRequestBranch{
 | 
				
			||||||
				Ref:       "proper-from-on-issue-mail",
 | 
									Ref:       "test-branch",
 | 
				
			||||||
				SHA:       "af03d00780a6ee70c58e135c6679542cde4f8d50",
 | 
									SHA:       "2be9101c543658591222acbee3eb799edfc3853d",
 | 
				
			||||||
				RepoName:  "gogs",
 | 
									RepoName:  "test_repo",
 | 
				
			||||||
				OwnerName: "strk",
 | 
									OwnerName: "mrsdizzie",
 | 
				
			||||||
				CloneURL:  "https://github.com/strk/gogs.git",
 | 
									CloneURL:  "https://github.com/mrsdizzie/test_repo.git",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Base: base.PullRequestBranch{
 | 
								Base: base.PullRequestBranch{
 | 
				
			||||||
				Ref:       "develop",
 | 
									Ref:       "master",
 | 
				
			||||||
				SHA:       "5c5424301443ffa3659737d12de48ab1dfe39a00",
 | 
									SHA:       "f32b0a9dfd09a60f616f29158f772cedd89942d2",
 | 
				
			||||||
				OwnerName: "go-gitea",
 | 
									OwnerName: "go-gitea",
 | 
				
			||||||
				RepoName:  "gitea",
 | 
									RepoName:  "test_repo",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Closed:         &closed2,
 | 
								Merged:         false,
 | 
				
			||||||
			Merged:         true,
 | 
								MergeCommitSHA: "565d1208f5fffdc1c5ae1a2436491eb9a5e4ebae",
 | 
				
			||||||
			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",
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}, prs)
 | 
						}, prs)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,6 +94,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
 | 
				
			|||||||
	if err := uploader.CreateRepo(repo, opts); err != nil {
 | 
						if err := uploader.CreateRepo(repo, opts); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer uploader.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Trace("migrating topics")
 | 
						log.Trace("migrating topics")
 | 
				
			||||||
	topics, err := downloader.GetTopics()
 | 
						topics, err := downloader.GetTopics()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,6 @@
 | 
				
			|||||||
package migrations
 | 
					package migrations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"code.gitea.io/gitea/models"
 | 
						"code.gitea.io/gitea/models"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/log"
 | 
						"code.gitea.io/gitea/modules/log"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/structs"
 | 
						"code.gitea.io/gitea/modules/structs"
 | 
				
			||||||
@@ -40,11 +38,7 @@ func updateMigrationPosterIDByGitService(tp structs.GitServiceType) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for _, user := range users {
 | 
							for _, user := range users {
 | 
				
			||||||
			externalUserID, err := strconv.ParseInt(user.ExternalID, 10, 64)
 | 
								externalUserID := user.ExternalID
 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				log.Warn("Parse externalUser %#v 's userID failed: %v", user, err)
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if err := models.UpdateMigrationsByType(tp, externalUserID, user.UserID); err != nil {
 | 
								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)
 | 
									log.Error("UpdateMigrationsByType type %s external user id %v to local user id %v failed: %v", tp.Name(), user.ExternalID, user.UserID, err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,45 +7,60 @@ package password
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"crypto/rand"
 | 
						"crypto/rand"
 | 
				
			||||||
	"math/big"
 | 
						"math/big"
 | 
				
			||||||
	"regexp"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"code.gitea.io/gitea/modules/setting"
 | 
						"code.gitea.io/gitea/modules/setting"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var matchComplexities = map[string]regexp.Regexp{}
 | 
					var (
 | 
				
			||||||
var matchComplexityOnce sync.Once
 | 
						matchComplexityOnce sync.Once
 | 
				
			||||||
var validChars string
 | 
						validChars          string
 | 
				
			||||||
var validComplexities = map[string]string{
 | 
						requiredChars       []string
 | 
				
			||||||
	"lower": "abcdefghijklmnopqrstuvwxyz",
 | 
					
 | 
				
			||||||
	"upper": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
 | 
						charComplexities = map[string]string{
 | 
				
			||||||
	"digit": "0123456789",
 | 
							"lower": `abcdefghijklmnopqrstuvwxyz`,
 | 
				
			||||||
	"spec":  `][ !"#$%&'()*+,./:;<=>?@\^_{|}~` + "`-",
 | 
							"upper": `ABCDEFGHIJKLMNOPQRSTUVWXYZ`,
 | 
				
			||||||
}
 | 
							"digit": `0123456789`,
 | 
				
			||||||
 | 
							"spec":  ` !"#$%&'()*+,-./:;<=>?@[\]^_{|}~` + "`",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewComplexity for preparation
 | 
					// NewComplexity for preparation
 | 
				
			||||||
func NewComplexity() {
 | 
					func NewComplexity() {
 | 
				
			||||||
	matchComplexityOnce.Do(func() {
 | 
						matchComplexityOnce.Do(func() {
 | 
				
			||||||
		if len(setting.PasswordComplexity) > 0 {
 | 
							setupComplexity(setting.PasswordComplexity)
 | 
				
			||||||
			for key, val := range setting.PasswordComplexity {
 | 
					 | 
				
			||||||
				matchComplexity := regexp.MustCompile(val)
 | 
					 | 
				
			||||||
				matchComplexities[key] = *matchComplexity
 | 
					 | 
				
			||||||
				validChars += validComplexities[key]
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			for _, val := range validComplexities {
 | 
					 | 
				
			||||||
				validChars += val
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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 {
 | 
					func IsComplexEnough(pwd string) bool {
 | 
				
			||||||
	if len(setting.PasswordComplexity) > 0 {
 | 
						NewComplexity()
 | 
				
			||||||
		NewComplexity()
 | 
						if len(validChars) > 0 {
 | 
				
			||||||
		for _, val := range matchComplexities {
 | 
							for _, req := range requiredChars {
 | 
				
			||||||
			if !val.MatchString(pwd) {
 | 
								if !strings.ContainsAny(req, pwd) {
 | 
				
			||||||
				return false
 | 
									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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -26,7 +26,7 @@ var (
 | 
				
			|||||||
	// TODO: fix invalid linking issue
 | 
						// TODO: fix invalid linking issue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// mentionPattern matches all mentions in the form of "@user"
 | 
						// 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 matches string that references to a numeric issue, e.g. #1287
 | 
				
			||||||
	issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`)
 | 
						issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`)
 | 
				
			||||||
	// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
 | 
						// 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) {
 | 
					func TestRegExp_mentionPattern(t *testing.T) {
 | 
				
			||||||
	trueTestCases := []string{
 | 
						trueTestCases := []struct {
 | 
				
			||||||
		"@Unknwon",
 | 
							pat string
 | 
				
			||||||
		"@ANT_123",
 | 
							exp string
 | 
				
			||||||
		"@xxx-DiN0-z-A..uru..s-xxx",
 | 
						}{
 | 
				
			||||||
		"   @lol   ",
 | 
							{"@Unknwon", "@Unknwon"},
 | 
				
			||||||
		" @Te-st",
 | 
							{"@ANT_123", "@ANT_123"},
 | 
				
			||||||
		"(@gitea)",
 | 
							{"@xxx-DiN0-z-A..uru..s-xxx", "@xxx-DiN0-z-A..uru..s-xxx"},
 | 
				
			||||||
		"[@gitea]",
 | 
							{"   @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{
 | 
						falseTestCases := []string{
 | 
				
			||||||
		"@ 0",
 | 
							"@ 0",
 | 
				
			||||||
@@ -219,17 +237,24 @@ func TestRegExp_mentionPattern(t *testing.T) {
 | 
				
			|||||||
		"@",
 | 
							"@",
 | 
				
			||||||
		"",
 | 
							"",
 | 
				
			||||||
		"ABC",
 | 
							"ABC",
 | 
				
			||||||
 | 
							"@.ABC",
 | 
				
			||||||
		"/home/gitea/@gitea",
 | 
							"/home/gitea/@gitea",
 | 
				
			||||||
		"\"@gitea\"",
 | 
							"\"@gitea\"",
 | 
				
			||||||
 | 
							"@@gitea",
 | 
				
			||||||
 | 
							"@gitea!this",
 | 
				
			||||||
 | 
							"@gitea?this",
 | 
				
			||||||
 | 
							"@gitea,this",
 | 
				
			||||||
 | 
							"@gitea;this",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, testCase := range trueTestCases {
 | 
						for _, testCase := range trueTestCases {
 | 
				
			||||||
		res := mentionPattern.MatchString(testCase)
 | 
							found := mentionPattern.FindStringSubmatch(testCase.pat)
 | 
				
			||||||
		assert.True(t, res)
 | 
							assert.Len(t, found, 2)
 | 
				
			||||||
 | 
							assert.Equal(t, testCase.exp, found[1])
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, testCase := range falseTestCases {
 | 
						for _, testCase := range falseTestCases {
 | 
				
			||||||
		res := mentionPattern.MatchString(testCase)
 | 
							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 err := gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
 | 
				
			||||||
				if !git.IsErrUnsupportedVersion(err) {
 | 
									if !git.IsErrUnsupportedVersion(err) {
 | 
				
			||||||
 | 
										gitRepo.Close()
 | 
				
			||||||
					return err
 | 
										return err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -132,8 +134,10 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			shaSum, err = gitRepo.GetBranchCommitID(refName)
 | 
								shaSum, err = gitRepo.GetBranchCommitID(refName)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
 | 
									gitRepo.Close()
 | 
				
			||||||
				log.Error("GetBranchCommitID[%s]: %v", opts.RefFullName, err)
 | 
									log.Error("GetBranchCommitID[%s]: %v", opts.RefFullName, err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
			if err = models.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
 | 
								if err = models.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
 | 
				
			||||||
				Ref:     refName,
 | 
									Ref:     refName,
 | 
				
			||||||
				Sha:     shaSum,
 | 
									Sha:     shaSum,
 | 
				
			||||||
@@ -167,8 +171,10 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		shaSum, err = gitRepo.GetTagCommitID(refName)
 | 
							shaSum, err = gitRepo.GetTagCommitID(refName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								gitRepo.Close()
 | 
				
			||||||
			log.Error("GetTagCommitID[%s]: %v", opts.RefFullName, err)
 | 
								log.Error("GetTagCommitID[%s]: %v", opts.RefFullName, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							gitRepo.Close()
 | 
				
			||||||
		if err = models.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
 | 
							if err = models.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
 | 
				
			||||||
			Ref:     refName,
 | 
								Ref:     refName,
 | 
				
			||||||
			Sha:     shaSum,
 | 
								Sha:     shaSum,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ func GetBlobBySHA(repo *models.Repository, sha string) (*api.GitBlobResponse, er
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
	gitBlob, err := gitRepo.GetBlob(sha)
 | 
						gitBlob, err := gitRepo.GetBlob(sha)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,8 @@ func TestGetBlobBySHA(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
 | 
						sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
 | 
				
			||||||
	ctx.SetParams(":id", "1")
 | 
						ctx.SetParams(":id", "1")
 | 
				
			||||||
	ctx.SetParams(":sha", sha)
 | 
						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)
 | 
							return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if _, err := gitRepo.GetCommit(sha); err != nil {
 | 
						if _, err := gitRepo.GetCommit(sha); err != nil {
 | 
				
			||||||
 | 
							gitRepo.Close()
 | 
				
			||||||
		return fmt.Errorf("GetCommit[%s]: %v", sha, err)
 | 
							return fmt.Errorf("GetCommit[%s]: %v", sha, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := models.NewCommitStatus(models.NewCommitStatusOptions{
 | 
						if err := models.NewCommitStatus(models.NewCommitStatusOptions{
 | 
				
			||||||
		Repo:         repo,
 | 
							Repo:         repo,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,9 @@ func (ct *ContentType) String() string {
 | 
				
			|||||||
// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
 | 
					// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
 | 
				
			||||||
// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
 | 
					// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
 | 
				
			||||||
func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
 | 
					func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
 | 
				
			||||||
 | 
						if repo.IsEmpty {
 | 
				
			||||||
 | 
							return make([]interface{}, 0), nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if ref == "" {
 | 
						if ref == "" {
 | 
				
			||||||
		ref = repo.DefaultBranch
 | 
							ref = repo.DefaultBranch
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -56,6 +59,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get the commit object for the ref
 | 
						// Get the commit object for the ref
 | 
				
			||||||
	commit, err := gitRepo.GetCommit(ref)
 | 
						commit, err := gitRepo.GetCommit(ref)
 | 
				
			||||||
@@ -114,6 +118,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get the commit object for the ref
 | 
						// Get the commit object for the ref
 | 
				
			||||||
	commit, err := gitRepo.GetCommit(ref)
 | 
						commit, err := gitRepo.GetCommit(ref)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,6 +56,8 @@ func TestGetContents(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	ref := ctx.Repo.Repository.DefaultBranch
 | 
						ref := ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -82,6 +84,8 @@ func TestGetContentsOrListForDir(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	treePath := "" // root dir
 | 
						treePath := "" // root dir
 | 
				
			||||||
	ref := ctx.Repo.Repository.DefaultBranch
 | 
						ref := ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -115,6 +119,8 @@ func TestGetContentsOrListForFile(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	ref := ctx.Repo.Repository.DefaultBranch
 | 
						ref := ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -141,6 +147,8 @@ func TestGetContentsErrors(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := ctx.Repo.Repository
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	ref := repo.DefaultBranch
 | 
						ref := repo.DefaultBranch
 | 
				
			||||||
@@ -170,6 +178,8 @@ func TestGetContentsOrListErrors(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := ctx.Repo.Repository
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	ref := repo.DefaultBranch
 | 
						ref := repo.DefaultBranch
 | 
				
			||||||
@@ -190,3 +200,21 @@ func TestGetContentsOrListErrors(t *testing.T) {
 | 
				
			|||||||
		assert.Nil(t, fileContentResponse)
 | 
							assert.Nil(t, fileContentResponse)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
 | 
				
			||||||
 | 
						models.PrepareTestEnv(t)
 | 
				
			||||||
 | 
						ctx := test.MockContext(t, "user2/repo15")
 | 
				
			||||||
 | 
						ctx.SetParams(":id", "15")
 | 
				
			||||||
 | 
						test.LoadRepo(t, ctx, 15)
 | 
				
			||||||
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("empty repo", func(t *testing.T) {
 | 
				
			||||||
 | 
							contents, err := GetContentsOrList(repo, "", "")
 | 
				
			||||||
 | 
							assert.NoError(t, err)
 | 
				
			||||||
 | 
							assert.Empty(t, contents)
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,8 @@ func TestGetDiffPreview(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	branch := ctx.Repo.Repository.DefaultBranch
 | 
						branch := ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	content := "# repo1\n\nDescription for repo1\nthis is a new line"
 | 
						content := "# repo1\n\nDescription for repo1\nthis is a new line"
 | 
				
			||||||
@@ -119,6 +121,8 @@ func TestGetDiffPreviewErrors(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	branch := ctx.Repo.Repository.DefaultBranch
 | 
						branch := ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	content := "# repo1\n\nDescription for repo1\nthis is a new line"
 | 
						content := "# repo1\n\nDescription for repo1\nthis is a new line"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,10 +88,13 @@ func TestGetFileResponseFromCommit(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := ctx.Repo.Repository
 | 
						repo := ctx.Repo.Repository
 | 
				
			||||||
	branch := repo.DefaultBranch
 | 
						branch := repo.DefaultBranch
 | 
				
			||||||
	treePath := "README.md"
 | 
						treePath := "README.md"
 | 
				
			||||||
	gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
						gitRepo, _ := git.OpenRepository(repo.RepoPath())
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
	commit, _ := gitRepo.GetBranchCommit(branch)
 | 
						commit, _ := gitRepo.GetBranchCommit(branch)
 | 
				
			||||||
	expectedFileResponse := getExpectedFileResponse()
 | 
						expectedFileResponse := getExpectedFileResponse()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,6 +44,7 @@ func NewTemporaryUploadRepository(repo *models.Repository) (*TemporaryUploadRepo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Close the repository cleaning up all files
 | 
					// Close the repository cleaning up all files
 | 
				
			||||||
func (t *TemporaryUploadRepository) Close() {
 | 
					func (t *TemporaryUploadRepository) Close() {
 | 
				
			||||||
 | 
						defer t.gitRepo.Close()
 | 
				
			||||||
	if err := models.RemoveTemporaryPath(t.basePath); err != nil {
 | 
						if err := models.RemoveTemporaryPath(t.basePath); err != nil {
 | 
				
			||||||
		log.Error("Failed to remove temporary path %s: %v", t.basePath, err)
 | 
							log.Error("Failed to remove temporary path %s: %v", t.basePath, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
	gitTree, err := gitRepo.GetTree(sha)
 | 
						gitTree, err := gitRepo.GetTree(sha)
 | 
				
			||||||
	if err != nil || gitTree == nil {
 | 
						if err != nil || gitTree == nil {
 | 
				
			||||||
		return nil, models.ErrSHANotFound{
 | 
							return nil, models.ErrSHANotFound{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,8 @@ func TestGetTreeBySHA(t *testing.T) {
 | 
				
			|||||||
	test.LoadRepoCommit(t, ctx)
 | 
						test.LoadRepoCommit(t, ctx)
 | 
				
			||||||
	test.LoadUser(t, ctx, 2)
 | 
						test.LoadUser(t, ctx, 2)
 | 
				
			||||||
	test.LoadGitRepo(t, ctx)
 | 
						test.LoadGitRepo(t, ctx)
 | 
				
			||||||
 | 
						defer ctx.Repo.GitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sha := ctx.Repo.Repository.DefaultBranch
 | 
						sha := ctx.Repo.Repository.DefaultBranch
 | 
				
			||||||
	page := 1
 | 
						page := 1
 | 
				
			||||||
	perPage := 10
 | 
						perPage := 10
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -429,6 +429,7 @@ func PushUpdate(repo *models.Repository, branch string, opts models.PushUpdateOp
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("OpenRepository: %v", err)
 | 
							return fmt.Errorf("OpenRepository: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = repo.UpdateSize(); err != nil {
 | 
						if err = repo.UpdateSize(); err != nil {
 | 
				
			||||||
		log.Error("Failed to update size for repository: %v", err)
 | 
							log.Error("Failed to update size for repository: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,12 +42,11 @@ var (
 | 
				
			|||||||
		DBConnectRetries  int
 | 
							DBConnectRetries  int
 | 
				
			||||||
		DBConnectBackoff  time.Duration
 | 
							DBConnectBackoff  time.Duration
 | 
				
			||||||
		MaxIdleConns      int
 | 
							MaxIdleConns      int
 | 
				
			||||||
 | 
							MaxOpenConns      int
 | 
				
			||||||
		ConnMaxLifetime   time.Duration
 | 
							ConnMaxLifetime   time.Duration
 | 
				
			||||||
		IterateBufferSize int
 | 
							IterateBufferSize int
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		Timeout:         500,
 | 
							Timeout: 500,
 | 
				
			||||||
		MaxIdleConns:    0,
 | 
					 | 
				
			||||||
		ConnMaxLifetime: 3 * time.Second,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,8 +79,13 @@ func InitDBConfig() {
 | 
				
			|||||||
	Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"})
 | 
						Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"})
 | 
				
			||||||
	Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
 | 
						Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
 | 
				
			||||||
	Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
 | 
						Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
 | 
				
			||||||
	Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(0)
 | 
						Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)
 | 
				
			||||||
	Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFE_TIME").MustDuration(3 * time.Second)
 | 
						if Database.UseMySQL {
 | 
				
			||||||
 | 
							Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFE_TIME").MustDuration(3 * time.Second)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFE_TIME").MustDuration(0)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						Database.MaxOpenConns = sec.Key("MAX_OPEN_CONNS").MustInt(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Database.IterateBufferSize = sec.Key("ITERATE_BUFFER_SIZE").MustInt(50)
 | 
						Database.IterateBufferSize = sec.Key("ITERATE_BUFFER_SIZE").MustInt(50)
 | 
				
			||||||
	Database.LogSQL = sec.Key("LOG_SQL").MustBool(true)
 | 
						Database.LogSQL = sec.Key("LOG_SQL").MustBool(true)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -146,7 +146,7 @@ var (
 | 
				
			|||||||
	MinPasswordLength     int
 | 
						MinPasswordLength     int
 | 
				
			||||||
	ImportLocalPaths      bool
 | 
						ImportLocalPaths      bool
 | 
				
			||||||
	DisableGitHooks       bool
 | 
						DisableGitHooks       bool
 | 
				
			||||||
	PasswordComplexity    map[string]string
 | 
						PasswordComplexity    []string
 | 
				
			||||||
	PasswordHashAlgo      string
 | 
						PasswordHashAlgo      string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// UI settings
 | 
						// UI settings
 | 
				
			||||||
@@ -775,26 +775,14 @@ func NewContext() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	InternalToken = loadInternalToken(sec)
 | 
						InternalToken = loadInternalToken(sec)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var dictPC = map[string]string{
 | 
					 | 
				
			||||||
		"lower": "[a-z]+",
 | 
					 | 
				
			||||||
		"upper": "[A-Z]+",
 | 
					 | 
				
			||||||
		"digit": "[0-9]+",
 | 
					 | 
				
			||||||
		"spec":  `][ !"#$%&'()*+,./:;<=>?@\\^_{|}~` + "`-",
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	PasswordComplexity = make(map[string]string)
 | 
					 | 
				
			||||||
	cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
 | 
						cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
 | 
				
			||||||
	for _, y := range cfgdata {
 | 
						PasswordComplexity = make([]string, 0, len(cfgdata))
 | 
				
			||||||
		ts := strings.TrimSpace(y)
 | 
						for _, name := range cfgdata {
 | 
				
			||||||
		for a := range dictPC {
 | 
							name := strings.ToLower(strings.Trim(name, `"`))
 | 
				
			||||||
			if strings.ToLower(ts) == a {
 | 
							if name != "" {
 | 
				
			||||||
				PasswordComplexity[ts] = dictPC[ts]
 | 
								PasswordComplexity = append(PasswordComplexity, name)
 | 
				
			||||||
				break
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(PasswordComplexity) == 0 {
 | 
					 | 
				
			||||||
		PasswordComplexity = dictPC
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sec = Cfg.Section("attachment")
 | 
						sec = Cfg.Section("attachment")
 | 
				
			||||||
	AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))
 | 
						AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ import (
 | 
				
			|||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
						"unicode"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"code.gitea.io/gitea/models"
 | 
						"code.gitea.io/gitea/models"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/base"
 | 
						"code.gitea.io/gitea/modules/base"
 | 
				
			||||||
@@ -331,34 +332,46 @@ func RenderCommitMessageLink(msg, urlPrefix, urlDefault string, metas map[string
 | 
				
			|||||||
// RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to
 | 
					// RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to
 | 
				
			||||||
// the provided default url, handling for special links without email to links.
 | 
					// the provided default url, handling for special links without email to links.
 | 
				
			||||||
func RenderCommitMessageLinkSubject(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML {
 | 
					func RenderCommitMessageLinkSubject(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML {
 | 
				
			||||||
	cleanMsg := template.HTMLEscapeString(msg)
 | 
						msgLine := strings.TrimLeftFunc(msg, unicode.IsSpace)
 | 
				
			||||||
	// we can safely assume that it will not return any error, since there
 | 
						lineEnd := strings.IndexByte(msgLine, '\n')
 | 
				
			||||||
	// shouldn't be any special HTML.
 | 
						if lineEnd > 0 {
 | 
				
			||||||
	fullMessage, err := markup.RenderCommitMessageSubject([]byte(cleanMsg), urlPrefix, urlDefault, metas)
 | 
							msgLine = msgLine[:lineEnd]
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		log.Error("RenderCommitMessageSubject: %v", err)
 | 
					 | 
				
			||||||
		return ""
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	msgLines := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
 | 
						msgLine = strings.TrimRightFunc(msgLine, unicode.IsSpace)
 | 
				
			||||||
	if len(msgLines) == 0 {
 | 
						if len(msgLine) == 0 {
 | 
				
			||||||
		return template.HTML("")
 | 
							return template.HTML("")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return template.HTML(msgLines[0])
 | 
					
 | 
				
			||||||
 | 
						// we can safely assume that it will not return any error, since there
 | 
				
			||||||
 | 
						// shouldn't be any special HTML.
 | 
				
			||||||
 | 
						renderedMessage, err := markup.RenderCommitMessageSubject([]byte(template.HTMLEscapeString(msgLine)), urlPrefix, urlDefault, metas)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Error("RenderCommitMessageSubject: %v", err)
 | 
				
			||||||
 | 
							return template.HTML("")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return template.HTML(renderedMessage)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// RenderCommitBody extracts the body of a commit message without its title.
 | 
					// RenderCommitBody extracts the body of a commit message without its title.
 | 
				
			||||||
func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
 | 
					func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
 | 
				
			||||||
	cleanMsg := template.HTMLEscapeString(msg)
 | 
						msgLine := strings.TrimRightFunc(msg, unicode.IsSpace)
 | 
				
			||||||
	fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas)
 | 
						lineEnd := strings.IndexByte(msgLine, '\n')
 | 
				
			||||||
 | 
						if lineEnd > 0 {
 | 
				
			||||||
 | 
							msgLine = msgLine[lineEnd+1:]
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return template.HTML("")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						msgLine = strings.TrimLeftFunc(msgLine, unicode.IsSpace)
 | 
				
			||||||
 | 
						if len(msgLine) == 0 {
 | 
				
			||||||
 | 
							return template.HTML("")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						renderedMessage, err := markup.RenderCommitMessage([]byte(template.HTMLEscapeString(msgLine)), urlPrefix, "", metas)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Error("RenderCommitMessage: %v", err)
 | 
							log.Error("RenderCommitMessage: %v", err)
 | 
				
			||||||
		return ""
 | 
							return ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	body := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
 | 
						return template.HTML(renderedMessage)
 | 
				
			||||||
	if len(body) == 0 {
 | 
					 | 
				
			||||||
		return template.HTML("")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return template.HTML(strings.Join(body[1:], "\n"))
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// RenderNote renders the contents of a git-notes file as a commit message.
 | 
					// RenderNote renders the contents of a git-notes file as a commit message.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,6 +55,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
 | 
				
			|||||||
func LoadRepoCommit(t *testing.T, ctx *context.Context) {
 | 
					func LoadRepoCommit(t *testing.T, ctx *context.Context) {
 | 
				
			||||||
	gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
						gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
	branch, err := gitRepo.GetHEADBranch()
 | 
						branch, err := gitRepo.GetHEADBranch()
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name)
 | 
						ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -315,7 +315,7 @@ team_no_units_error = Allow access to at least one repository section.
 | 
				
			|||||||
email_been_used = The email address is already used.
 | 
					email_been_used = The email address is already used.
 | 
				
			||||||
openid_been_used = The OpenID address '%s' is already used.
 | 
					openid_been_used = The OpenID address '%s' is already used.
 | 
				
			||||||
username_password_incorrect = Username or password is incorrect.
 | 
					username_password_incorrect = Username or password is incorrect.
 | 
				
			||||||
password_complexity =  Password does not pass complexity requirements.
 | 
					password_complexity = Password does not pass complexity requirements.
 | 
				
			||||||
enterred_invalid_repo_name = The repository name you entered is incorrect.
 | 
					enterred_invalid_repo_name = The repository name you entered is incorrect.
 | 
				
			||||||
enterred_invalid_owner_name = The new owner name is not valid.
 | 
					enterred_invalid_owner_name = The new owner name is not valid.
 | 
				
			||||||
enterred_invalid_password = The password you entered is incorrect.
 | 
					enterred_invalid_password = The password you entered is incorrect.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -239,7 +239,7 @@ footer .ui.left,footer .ui.right{line-height:40px}
 | 
				
			|||||||
.lines-commit .ui.avatar.image{height:18px;width:18px}
 | 
					.lines-commit .ui.avatar.image{height:18px;width:18px}
 | 
				
			||||||
.lines-code .bottom-line,.lines-commit .bottom-line,.lines-num .bottom-line{border-bottom:1px solid #eaecef}
 | 
					.lines-code .bottom-line,.lines-commit .bottom-line,.lines-num .bottom-line{border-bottom:1px solid #eaecef}
 | 
				
			||||||
.code-view{overflow:auto;overflow-x:auto;overflow-y:hidden}
 | 
					.code-view{overflow:auto;overflow-x:auto;overflow-y:hidden}
 | 
				
			||||||
.code-view *{font-size:12px;font-family:'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace;line-height:20px}
 | 
					.code-view :not(.fa):not(.octicon):not(.icon){font-size:12px;font-family:'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace;line-height:20px}
 | 
				
			||||||
.code-view table{width:100%}
 | 
					.code-view table{width:100%}
 | 
				
			||||||
.code-view .active{background:#fff866}
 | 
					.code-view .active{background:#fff866}
 | 
				
			||||||
.markdown:not(code){overflow:hidden;font-size:16px;line-height:1.6!important;word-wrap:break-word}
 | 
					.markdown:not(code){overflow:hidden;font-size:16px;line-height:1.6!important;word-wrap:break-word}
 | 
				
			||||||
@@ -659,8 +659,6 @@ footer .ui.left,footer .ui.right{line-height:40px}
 | 
				
			|||||||
.repository #commits-table td.sha .sha.label.isSigned.isVerified:hover,.repository #repo-files-table .sha.label.isSigned.isVerified:hover{background:rgba(33,186,69,.3)!important}
 | 
					.repository #commits-table td.sha .sha.label.isSigned.isVerified:hover,.repository #repo-files-table .sha.label.isSigned.isVerified:hover{background:rgba(33,186,69,.3)!important}
 | 
				
			||||||
.repository .diff-detail-box{padding:7px 0;background:#fff;line-height:30px}
 | 
					.repository .diff-detail-box{padding:7px 0;background:#fff;line-height:30px}
 | 
				
			||||||
.repository .diff-detail-box>div:after{clear:both;content:"";display:block}
 | 
					.repository .diff-detail-box>div:after{clear:both;content:"";display:block}
 | 
				
			||||||
.repository .diff-detail-box ol{clear:both;padding-left:0;margin-top:5px;margin-bottom:28px}
 | 
					 | 
				
			||||||
.repository .diff-detail-box ol li{list-style:none;padding-bottom:4px;margin-bottom:4px;border-bottom:1px dashed #ddd;padding-left:6px}
 | 
					 | 
				
			||||||
.repository .diff-detail-box span.status{display:inline-block;width:12px;height:12px;margin-right:8px;vertical-align:middle}
 | 
					.repository .diff-detail-box span.status{display:inline-block;width:12px;height:12px;margin-right:8px;vertical-align:middle}
 | 
				
			||||||
.repository .diff-detail-box span.status.modify{background-color:#f0db88}
 | 
					.repository .diff-detail-box span.status.modify{background-color:#f0db88}
 | 
				
			||||||
.repository .diff-detail-box span.status.add{background-color:#b4e2b4}
 | 
					.repository .diff-detail-box span.status.add{background-color:#b4e2b4}
 | 
				
			||||||
@@ -697,6 +695,11 @@ footer .ui.left,footer .ui.right{line-height:40px}
 | 
				
			|||||||
.repository .diff-file-box.file-content{clear:right}
 | 
					.repository .diff-file-box.file-content{clear:right}
 | 
				
			||||||
.repository .diff-file-box.file-content img{max-width:100%;padding:5px 5px 0 5px}
 | 
					.repository .diff-file-box.file-content img{max-width:100%;padding:5px 5px 0 5px}
 | 
				
			||||||
.repository .diff-file-box.file-content img.emoji{padding:0}
 | 
					.repository .diff-file-box.file-content img.emoji{padding:0}
 | 
				
			||||||
 | 
					.repository .diff-stats{clear:both;margin-bottom:5px;max-height:400px;overflow:auto;padding-left:0}
 | 
				
			||||||
 | 
					.repository .diff-stats li{list-style:none;padding-bottom:4px;margin-bottom:4px;border-bottom:1px dashed #ddd;padding-left:6px}
 | 
				
			||||||
 | 
					.repository .diff-stats .diff-counter{margin-right:15px}
 | 
				
			||||||
 | 
					.repository .diff-stats .diff-counter .del{color:red}
 | 
				
			||||||
 | 
					.repository .diff-stats .diff-counter .add{color:green}
 | 
				
			||||||
.repository .repo-search-result{padding-top:10px;padding-bottom:10px}
 | 
					.repository .repo-search-result{padding-top:10px;padding-bottom:10px}
 | 
				
			||||||
.repository .repo-search-result .lines-num a{color:inherit}
 | 
					.repository .repo-search-result .lines-num a{color:inherit}
 | 
				
			||||||
.repository.quickstart .guide .item{padding:1em}
 | 
					.repository.quickstart .guide .item{padding:1em}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -306,7 +306,7 @@ function initReactionSelector(parent) {
 | 
				
			|||||||
            if (resp && (resp.html || resp.empty)) {
 | 
					            if (resp && (resp.html || resp.empty)) {
 | 
				
			||||||
                const content = $(vm).closest('.content');
 | 
					                const content = $(vm).closest('.content');
 | 
				
			||||||
                let react = content.find('.segment.reactions');
 | 
					                let react = content.find('.segment.reactions');
 | 
				
			||||||
                if (react.length > 0) {
 | 
					                if (!resp.empty && react.length > 0) {
 | 
				
			||||||
                    react.remove();
 | 
					                    react.remove();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (!resp.empty) {
 | 
					                if (!resp.empty) {
 | 
				
			||||||
@@ -2873,7 +2873,8 @@ function initFilterBranchTagDropdown(selector) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(".commit-button").click(function() {
 | 
					$(".commit-button").click(function(e) {
 | 
				
			||||||
 | 
					    e.preventDefault();
 | 
				
			||||||
    $(this).parent().find('.commit-body').toggle();
 | 
					    $(this).parent().find('.commit-body').toggle();
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1047,7 +1047,7 @@ footer {
 | 
				
			|||||||
    overflow-x: auto;
 | 
					    overflow-x: auto;
 | 
				
			||||||
    overflow-y: hidden;
 | 
					    overflow-y: hidden;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    * {
 | 
					    *:not(.fa):not(.octicon):not(.icon) {
 | 
				
			||||||
        font-size: 12px;
 | 
					        font-size: 12px;
 | 
				
			||||||
        font-family: @monospaced-fonts, monospace;
 | 
					        font-family: @monospaced-fonts, monospace;
 | 
				
			||||||
        line-height: 20px;
 | 
					        line-height: 20px;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1237,21 +1237,6 @@
 | 
				
			|||||||
            display: block;
 | 
					            display: block;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ol {
 | 
					 | 
				
			||||||
            clear: both;
 | 
					 | 
				
			||||||
            padding-left: 0;
 | 
					 | 
				
			||||||
            margin-top: 5px;
 | 
					 | 
				
			||||||
            margin-bottom: 28px;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            li {
 | 
					 | 
				
			||||||
                list-style: none;
 | 
					 | 
				
			||||||
                padding-bottom: 4px;
 | 
					 | 
				
			||||||
                margin-bottom: 4px;
 | 
					 | 
				
			||||||
                border-bottom: 1px dashed #dddddd;
 | 
					 | 
				
			||||||
                padding-left: 6px;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        span.status {
 | 
					        span.status {
 | 
				
			||||||
            display: inline-block;
 | 
					            display: inline-block;
 | 
				
			||||||
            width: 12px;
 | 
					            width: 12px;
 | 
				
			||||||
@@ -1466,6 +1451,34 @@
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .diff-stats {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        clear: both;
 | 
				
			||||||
 | 
					        margin-bottom: 5px;
 | 
				
			||||||
 | 
					        max-height: 400px;
 | 
				
			||||||
 | 
					        overflow: auto;
 | 
				
			||||||
 | 
					        padding-left: 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        li {
 | 
				
			||||||
 | 
					            list-style: none;
 | 
				
			||||||
 | 
					            padding-bottom: 4px;
 | 
				
			||||||
 | 
					            margin-bottom: 4px;
 | 
				
			||||||
 | 
					            border-bottom: 1px dashed #dddddd;
 | 
				
			||||||
 | 
					            padding-left: 6px;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .diff-counter {
 | 
				
			||||||
 | 
					            margin-right: 15px;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            .del {
 | 
				
			||||||
 | 
					                color: red;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            .add {
 | 
				
			||||||
 | 
					                color: green;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    .repo-search-result {
 | 
					    .repo-search-result {
 | 
				
			||||||
        padding-top: 10px;
 | 
					        padding-top: 10px;
 | 
				
			||||||
        padding-bottom: 10px;
 | 
					        padding-bottom: 10px;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,12 +79,11 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u := &models.User{
 | 
						u := &models.User{
 | 
				
			||||||
		Name:               form.UserName,
 | 
							Name:      form.UserName,
 | 
				
			||||||
		Email:              form.Email,
 | 
							Email:     form.Email,
 | 
				
			||||||
		Passwd:             form.Password,
 | 
							Passwd:    form.Password,
 | 
				
			||||||
		IsActive:           true,
 | 
							IsActive:  true,
 | 
				
			||||||
		LoginType:          models.LoginPlain,
 | 
							LoginType: models.LoginPlain,
 | 
				
			||||||
		MustChangePassword: form.MustChangePassword,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(form.LoginType) > 0 {
 | 
						if len(form.LoginType) > 0 {
 | 
				
			||||||
@@ -95,9 +94,12 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
 | 
				
			|||||||
			u.LoginName = form.LoginName
 | 
								u.LoginName = form.LoginName
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !password.IsComplexEnough(form.Password) {
 | 
						if u.LoginType == models.LoginPlain {
 | 
				
			||||||
		ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
 | 
							if !password.IsComplexEnough(form.Password) {
 | 
				
			||||||
		return
 | 
								ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							u.MustChangePassword = form.MustChangePassword
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := models.CreateUser(u); err != nil {
 | 
						if err := models.CreateUser(u); err != nil {
 | 
				
			||||||
		switch {
 | 
							switch {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
 | 
				
			|||||||
		LoginName:          "local",
 | 
							LoginName:          "local",
 | 
				
			||||||
		UserName:           username,
 | 
							UserName:           username,
 | 
				
			||||||
		Email:              email,
 | 
							Email:              email,
 | 
				
			||||||
		Password:           "xxxxxxxx",
 | 
							Password:           "abc123ABC!=$",
 | 
				
			||||||
		SendNotify:         false,
 | 
							SendNotify:         false,
 | 
				
			||||||
		MustChangePassword: true,
 | 
							MustChangePassword: true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -71,7 +71,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
 | 
				
			|||||||
		LoginName:          "local",
 | 
							LoginName:          "local",
 | 
				
			||||||
		UserName:           username,
 | 
							UserName:           username,
 | 
				
			||||||
		Email:              email,
 | 
							Email:              email,
 | 
				
			||||||
		Password:           "xxxxxxxx",
 | 
							Password:           "abc123ABC!=$",
 | 
				
			||||||
		SendNotify:         false,
 | 
							SendNotify:         false,
 | 
				
			||||||
		MustChangePassword: false,
 | 
							MustChangePassword: false,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -638,7 +638,7 @@ func RegisterRoutes(m *macaron.Macaron) {
 | 
				
			|||||||
				}, reqRepoReader(models.UnitTypeCode))
 | 
									}, reqRepoReader(models.UnitTypeCode))
 | 
				
			||||||
				m.Group("/tags", func() {
 | 
									m.Group("/tags", func() {
 | 
				
			||||||
					m.Get("", repo.ListTags)
 | 
										m.Get("", repo.ListTags)
 | 
				
			||||||
				}, reqRepoReader(models.UnitTypeCode))
 | 
									}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
 | 
				
			||||||
				m.Group("/keys", func() {
 | 
									m.Group("/keys", func() {
 | 
				
			||||||
					m.Combo("").Get(repo.ListDeployKeys).
 | 
										m.Combo("").Get(repo.ListDeployKeys).
 | 
				
			||||||
						Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
 | 
											Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -232,12 +232,9 @@ func ToTeam(team *models.Team) *api.Team {
 | 
				
			|||||||
// ToUser convert models.User to api.User
 | 
					// ToUser convert models.User to api.User
 | 
				
			||||||
func ToUser(user *models.User, signed, authed bool) *api.User {
 | 
					func ToUser(user *models.User, signed, authed bool) *api.User {
 | 
				
			||||||
	result := &api.User{
 | 
						result := &api.User{
 | 
				
			||||||
		ID:        user.ID,
 | 
					 | 
				
			||||||
		UserName:  user.Name,
 | 
							UserName:  user.Name,
 | 
				
			||||||
		AvatarURL: user.AvatarLink(),
 | 
							AvatarURL: user.AvatarLink(),
 | 
				
			||||||
		FullName:  markup.Sanitize(user.FullName),
 | 
							FullName:  markup.Sanitize(user.FullName),
 | 
				
			||||||
		IsAdmin:   user.IsAdmin,
 | 
					 | 
				
			||||||
		LastLogin: user.LastLoginUnix.AsTime(),
 | 
					 | 
				
			||||||
		Created:   user.CreatedUnix.AsTime(),
 | 
							Created:   user.CreatedUnix.AsTime(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// hide primary email if API caller isn't user itself or an admin
 | 
						// hide primary email if API caller isn't user itself or an admin
 | 
				
			||||||
@@ -245,8 +242,11 @@ func ToUser(user *models.User, signed, authed bool) *api.User {
 | 
				
			|||||||
		result.Email = ""
 | 
							result.Email = ""
 | 
				
			||||||
	} else if user.KeepEmailPrivate && !authed {
 | 
						} else if user.KeepEmailPrivate && !authed {
 | 
				
			||||||
		result.Email = user.GetEmail()
 | 
							result.Email = user.GetEmail()
 | 
				
			||||||
	} else {
 | 
						} else { // only user himself and admin could visit these information
 | 
				
			||||||
 | 
							result.ID = user.ID
 | 
				
			||||||
		result.Email = user.Email
 | 
							result.Email = user.Email
 | 
				
			||||||
 | 
							result.IsAdmin = user.IsAdmin
 | 
				
			||||||
 | 
							result.LastLogin = user.LastLoginUnix.AsTime()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result
 | 
						return result
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,6 +51,7 @@ func GetSingleCommit(ctx *context.APIContext) {
 | 
				
			|||||||
		ctx.ServerError("OpenRepository", err)
 | 
							ctx.ServerError("OpenRepository", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
	commit, err := gitRepo.GetCommit(ctx.Params(":sha"))
 | 
						commit, err := gitRepo.GetCommit(ctx.Params(":sha"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err)
 | 
							ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err)
 | 
				
			||||||
@@ -113,6 +114,7 @@ func GetAllCommits(ctx *context.APIContext) {
 | 
				
			|||||||
		ctx.ServerError("OpenRepository", err)
 | 
							ctx.ServerError("OpenRepository", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	page := ctx.QueryInt("page")
 | 
						page := ctx.QueryInt("page")
 | 
				
			||||||
	if page <= 0 {
 | 
						if page <= 0 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -95,6 +95,7 @@ func GetArchive(ctx *context.APIContext) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ctx.Repo.GitRepo = gitRepo
 | 
						ctx.Repo.GitRepo = gitRepo
 | 
				
			||||||
 | 
						defer gitRepo.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo.Download(ctx.Context)
 | 
						repo.Download(ctx.Context)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user