You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2205 lines
61 KiB

10 years ago
10 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
4 years ago
8 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
4 years ago
8 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
8 years ago
8 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
4 years ago
8 years ago
8 years ago
8 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
8 years ago
Add a storage layer for attachments (#11387) * Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
3 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
4 years ago
7 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
5 years ago
Support unicode emojis and remove emojify.js (#11032) * Support unicode emojis and remove emojify.js This PR replaces all use of emojify.js and adds unicode emoji support to various areas of gitea. This works in a few ways: First it adds emoji parsing support into gitea itself. This allows us to * Render emojis from valid alias (:smile:) * Detect unicode emojis and let us put them in their own class with proper aria-labels and styling * Easily allow for custom "emoji" * Support all emoji rendering and features without javascript * Uses plain unicode and lets the system render in appropriate emoji font * Doesn't leave us relying on external sources for updates/fixes/features That same list of emoji is also used to create a json file which replaces the part of emojify.js that populates the emoji search tribute. This file is about 35KB with GZIP turned on and I've set it to load after the page renders to not hinder page load time (and this removes loading emojify.js also) For custom "emoji" it uses a pretty simple scheme of just looking for /emojis/img/name.png where name is something a user has put in the "allowed reactions" setting we already have. The gitea reaction that was previously hard coded into a forked copy of emojify.js is included and works as a custom reaction under this method. The emoji data sourced here is from https://github.com/github/gemoji which is the gem library Github uses for their emoji rendering (and a data source for other sites). So we should be able to easily render any emoji and :alias: that Github can, removing any errors from migrated content. They also update it as well, so we can sync when there are new unicode emoji lists released. I've included a slimmed down and slightly modified forked copy of https://github.com/knq/emoji to make up our own emoji module. The code is pretty straight forward and again allows us to have a lot of flexibility in what happens. I had seen a few comments about performance in some of the other threads if we render this ourselves, but there doesn't seem to be any issue here. In a test it can parse, convert, and render 1,000 emojis inside of a large markdown table in about 100ms on my laptop (which is many more emojis than will ever be in any normal issue). This also prevents any flickering and other weirdness from using javascript to render some things while using go for others. Not included here are image fall back URLS. I don't really think they are necessary for anything new being written in 2020. However, managing the emoji ourselves would allow us to add these as a feature later on if it seems necessary. Fixes: https://github.com/go-gitea/gitea/issues/9182 Fixes: https://github.com/go-gitea/gitea/issues/8974 Fixes: https://github.com/go-gitea/gitea/issues/8953 Fixes: https://github.com/go-gitea/gitea/issues/6628 Fixes: https://github.com/go-gitea/gitea/issues/5130 * add new shared function emojiHTML * don't increase emoji size in issue title * Update templates/repo/issue/view_content/add_reaction.tmpl Co-Authored-By: 6543 <6543@obermui.de> * Support for emoji rendering in various templates * Render code and review comments as they should be * Better way to handle mail subjects * insert unicode from tribute selection * Add template helper for plain text when needed * Use existing replace function I forgot about * Don't include emoji greater than Unicode Version 12 Only include emoji and aliases in JSON * Update build/generate-emoji.go * Tweak regex slightly to really match everything including random invisible characters. Run tests for every emoji we have * final updates * code review * code review * hard code gitea custom emoji to match previous behavior * Update .eslintrc Co-Authored-By: silverwind <me@silverwind.io> * disable preempt Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
4 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
5 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
5 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Add configurable Trust Models (#11712) * Add configurable Trust Models Gitea's default signature verification model differs from GitHub. GitHub uses signatures to verify that the committer is who they say they are - meaning that when GitHub makes a signed commit it must be the committer. The GitHub model prevents re-publishing of commits after revocation of a key and prevents re-signing of other people's commits to create a completely trusted repository signed by one key or a set of trusted keys. The default behaviour of Gitea in contrast is to always display the avatar and information related to a signature. This allows signatures to be decoupled from the committer. That being said, allowing arbitary users to present other peoples commits as theirs is not necessarily desired therefore we have a trust model whereby signatures from collaborators are marked trusted, signatures matching the commit line are marked untrusted and signatures that match a user in the db but not the committer line are marked unmatched. The problem with this model is that this conflicts with Github therefore we need to provide an option to allow users to choose the Github model should they wish to. Signed-off-by: Andrew Thornton <art27@cantab.net> * Adjust locale strings Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Co-authored-by: 6543 <6543@obermui.de> * Update models/gpg_key.go * Add migration for repository Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
3 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Add a storage layer for attachments (#11387) * Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
3 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
8 years ago
8 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
5 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
5 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "bytes"
  8. "errors"
  9. "fmt"
  10. "io/ioutil"
  11. "net/http"
  12. "path"
  13. "strconv"
  14. "strings"
  15. "code.gitea.io/gitea/models"
  16. "code.gitea.io/gitea/modules/auth"
  17. "code.gitea.io/gitea/modules/base"
  18. "code.gitea.io/gitea/modules/context"
  19. "code.gitea.io/gitea/modules/git"
  20. issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/markup"
  23. "code.gitea.io/gitea/modules/markup/markdown"
  24. "code.gitea.io/gitea/modules/setting"
  25. api "code.gitea.io/gitea/modules/structs"
  26. "code.gitea.io/gitea/modules/util"
  27. comment_service "code.gitea.io/gitea/services/comments"
  28. issue_service "code.gitea.io/gitea/services/issue"
  29. pull_service "code.gitea.io/gitea/services/pull"
  30. "github.com/unknwon/com"
  31. )
  32. const (
  33. tplAttachment base.TplName = "repo/issue/view_content/attachments"
  34. tplIssues base.TplName = "repo/issue/list"
  35. tplIssueNew base.TplName = "repo/issue/new"
  36. tplIssueChoose base.TplName = "repo/issue/choose"
  37. tplIssueView base.TplName = "repo/issue/view"
  38. tplReactions base.TplName = "repo/issue/view_content/reactions"
  39. issueTemplateKey = "IssueTemplate"
  40. issueTemplateTitleKey = "IssueTemplateTitle"
  41. )
  42. var (
  43. // ErrTooManyFiles upload too many files
  44. ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
  45. // IssueTemplateCandidates issue templates
  46. IssueTemplateCandidates = []string{
  47. "ISSUE_TEMPLATE.md",
  48. "issue_template.md",
  49. ".gitea/ISSUE_TEMPLATE.md",
  50. ".gitea/issue_template.md",
  51. ".github/ISSUE_TEMPLATE.md",
  52. ".github/issue_template.md",
  53. }
  54. )
  55. // MustAllowUserComment checks to make sure if an issue is locked.
  56. // If locked and user has permissions to write to the repository,
  57. // then the comment is allowed, else it is blocked
  58. func MustAllowUserComment(ctx *context.Context) {
  59. issue := GetActionIssue(ctx)
  60. if ctx.Written() {
  61. return
  62. }
  63. if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.User.IsAdmin {
  64. ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
  65. ctx.Redirect(issue.HTMLURL())
  66. return
  67. }
  68. }
  69. // MustEnableIssues check if repository enable internal issues
  70. func MustEnableIssues(ctx *context.Context) {
  71. if !ctx.Repo.CanRead(models.UnitTypeIssues) &&
  72. !ctx.Repo.CanRead(models.UnitTypeExternalTracker) {
  73. ctx.NotFound("MustEnableIssues", nil)
  74. return
  75. }
  76. unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
  77. if err == nil {
  78. ctx.Redirect(unit.ExternalTrackerConfig().ExternalTrackerURL)
  79. return
  80. }
  81. }
  82. // MustAllowPulls check if repository enable pull requests and user have right to do that
  83. func MustAllowPulls(ctx *context.Context) {
  84. if !ctx.Repo.Repository.CanEnablePulls() || !ctx.Repo.CanRead(models.UnitTypePullRequests) {
  85. ctx.NotFound("MustAllowPulls", nil)
  86. return
  87. }
  88. // User can send pull request if owns a forked repository.
  89. if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
  90. ctx.Repo.PullRequest.Allowed = true
  91. ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName
  92. }
  93. }
  94. func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption util.OptionalBool) {
  95. var err error
  96. viewType := ctx.Query("type")
  97. sortType := ctx.Query("sort")
  98. types := []string{"all", "your_repositories", "assigned", "created_by", "mentioned"}
  99. if !com.IsSliceContainsStr(types, viewType) {
  100. viewType = "all"
  101. }
  102. var (
  103. assigneeID = ctx.QueryInt64("assignee")
  104. posterID int64
  105. mentionedID int64
  106. forceEmpty bool
  107. )
  108. if ctx.IsSigned {
  109. switch viewType {
  110. case "created_by":
  111. posterID = ctx.User.ID
  112. case "mentioned":
  113. mentionedID = ctx.User.ID
  114. }
  115. }
  116. repo := ctx.Repo.Repository
  117. var labelIDs []int64
  118. selectLabels := ctx.Query("labels")
  119. if len(selectLabels) > 0 && selectLabels != "0" {
  120. labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ","))
  121. if err != nil {
  122. ctx.ServerError("StringsToInt64s", err)
  123. return
  124. }
  125. }
  126. keyword := strings.Trim(ctx.Query("q"), " ")
  127. if bytes.Contains([]byte(keyword), []byte{0x00}) {
  128. keyword = ""
  129. }
  130. var issueIDs []int64
  131. if len(keyword) > 0 {
  132. issueIDs, err = issue_indexer.SearchIssuesByKeyword([]int64{repo.ID}, keyword)
  133. if err != nil {
  134. ctx.ServerError("issueIndexer.Search", err)
  135. return
  136. }
  137. if len(issueIDs) == 0 {
  138. forceEmpty = true
  139. }
  140. }
  141. var issueStats *models.IssueStats
  142. if forceEmpty {
  143. issueStats = &models.IssueStats{}
  144. } else {
  145. issueStats, err = models.GetIssueStats(&models.IssueStatsOptions{
  146. RepoID: repo.ID,
  147. Labels: selectLabels,
  148. MilestoneID: milestoneID,
  149. AssigneeID: assigneeID,
  150. MentionedID: mentionedID,
  151. PosterID: posterID,
  152. IsPull: isPullOption,
  153. IssueIDs: issueIDs,
  154. })
  155. if err != nil {
  156. ctx.ServerError("GetIssueStats", err)
  157. return
  158. }
  159. }
  160. isShowClosed := ctx.Query("state") == "closed"
  161. // if open issues are zero and close don't, use closed as default
  162. if len(ctx.Query("state")) == 0 && issueStats.OpenCount == 0 && issueStats.ClosedCount != 0 {
  163. isShowClosed = true
  164. }
  165. page := ctx.QueryInt("page")
  166. if page <= 1 {
  167. page = 1
  168. }
  169. var total int
  170. if !isShowClosed {
  171. total = int(issueStats.OpenCount)
  172. } else {
  173. total = int(issueStats.ClosedCount)
  174. }
  175. pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5)
  176. var mileIDs []int64
  177. if milestoneID > 0 {
  178. mileIDs = []int64{milestoneID}
  179. }
  180. var issues []*models.Issue
  181. if forceEmpty {
  182. issues = []*models.Issue{}
  183. } else {
  184. issues, err = models.Issues(&models.IssuesOptions{
  185. ListOptions: models.ListOptions{
  186. Page: pager.Paginater.Current(),
  187. PageSize: setting.UI.IssuePagingNum,
  188. },
  189. RepoIDs: []int64{repo.ID},
  190. AssigneeID: assigneeID,
  191. PosterID: posterID,
  192. MentionedID: mentionedID,
  193. MilestoneIDs: mileIDs,
  194. ProjectID: projectID,
  195. IsClosed: util.OptionalBoolOf(isShowClosed),
  196. IsPull: isPullOption,
  197. LabelIDs: labelIDs,
  198. SortType: sortType,
  199. IssueIDs: issueIDs,
  200. })
  201. if err != nil {
  202. ctx.ServerError("Issues", err)
  203. return
  204. }
  205. }
  206. approvalCounts, err := models.IssueList(issues).GetApprovalCounts()
  207. if err != nil {
  208. ctx.ServerError("ApprovalCounts", err)
  209. return
  210. }
  211. var commitStatus = make(map[int64]*models.CommitStatus, len(issues))
  212. // Get posters.
  213. for i := range issues {
  214. // Check read status
  215. if !ctx.IsSigned {
  216. issues[i].IsRead = true
  217. } else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
  218. ctx.ServerError("GetIsRead", err)
  219. return
  220. }
  221. if issues[i].IsPull {
  222. if err := issues[i].LoadPullRequest(); err != nil {
  223. ctx.ServerError("LoadPullRequest", err)
  224. return
  225. }
  226. commitStatus[issues[i].PullRequest.ID], _ = pull_service.GetLastCommitStatus(issues[i].PullRequest)
  227. }
  228. }
  229. ctx.Data["Issues"] = issues
  230. ctx.Data["CommitStatus"] = commitStatus
  231. // Get assignees.
  232. ctx.Data["Assignees"], err = repo.GetAssignees()
  233. if err != nil {
  234. ctx.ServerError("GetAssignees", err)
  235. return
  236. }
  237. labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
  238. if err != nil {
  239. ctx.ServerError("GetLabelsByRepoID", err)
  240. return
  241. }
  242. if repo.Owner.IsOrganization() {
  243. orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.Query("sort"), models.ListOptions{})
  244. if err != nil {
  245. ctx.ServerError("GetLabelsByOrgID", err)
  246. return
  247. }
  248. ctx.Data["OrgLabels"] = orgLabels
  249. labels = append(labels, orgLabels...)
  250. }
  251. for _, l := range labels {
  252. l.LoadSelectedLabelsAfterClick(labelIDs)
  253. }
  254. ctx.Data["Labels"] = labels
  255. ctx.Data["NumLabels"] = len(labels)
  256. if ctx.QueryInt64("assignee") == 0 {
  257. assigneeID = 0 // Reset ID to prevent unexpected selection of assignee.
  258. }
  259. ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] =
  260. issue_service.GetRefEndNamesAndURLs(issues, ctx.Repo.RepoLink)
  261. ctx.Data["ApprovalCounts"] = func(issueID int64, typ string) int64 {
  262. counts, ok := approvalCounts[issueID]
  263. if !ok || len(counts) == 0 {
  264. return 0
  265. }
  266. reviewTyp := models.ReviewTypeApprove
  267. if typ == "reject" {
  268. reviewTyp = models.ReviewTypeReject
  269. } else if typ == "waiting" {
  270. reviewTyp = models.ReviewTypeRequest
  271. }
  272. for _, count := range counts {
  273. if count.Type == reviewTyp {
  274. return count.Count
  275. }
  276. }
  277. return 0
  278. }
  279. ctx.Data["IssueStats"] = issueStats
  280. ctx.Data["SelLabelIDs"] = labelIDs
  281. ctx.Data["SelectLabels"] = selectLabels
  282. ctx.Data["ViewType"] = viewType
  283. ctx.Data["SortType"] = sortType
  284. ctx.Data["MilestoneID"] = milestoneID
  285. ctx.Data["AssigneeID"] = assigneeID
  286. ctx.Data["IsShowClosed"] = isShowClosed
  287. ctx.Data["Keyword"] = keyword
  288. if isShowClosed {
  289. ctx.Data["State"] = "closed"
  290. } else {
  291. ctx.Data["State"] = "open"
  292. }
  293. pager.AddParam(ctx, "q", "Keyword")
  294. pager.AddParam(ctx, "type", "ViewType")
  295. pager.AddParam(ctx, "sort", "SortType")
  296. pager.AddParam(ctx, "state", "State")
  297. pager.AddParam(ctx, "labels", "SelectLabels")
  298. pager.AddParam(ctx, "milestone", "MilestoneID")
  299. pager.AddParam(ctx, "assignee", "AssigneeID")
  300. ctx.Data["Page"] = pager
  301. }
  302. // Issues render issues page
  303. func Issues(ctx *context.Context) {
  304. isPullList := ctx.Params(":type") == "pulls"
  305. if isPullList {
  306. MustAllowPulls(ctx)
  307. if ctx.Written() {
  308. return
  309. }
  310. ctx.Data["Title"] = ctx.Tr("repo.pulls")
  311. ctx.Data["PageIsPullList"] = true
  312. } else {
  313. MustEnableIssues(ctx)
  314. if ctx.Written() {
  315. return
  316. }
  317. ctx.Data["Title"] = ctx.Tr("repo.issues")
  318. ctx.Data["PageIsIssueList"] = true
  319. ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
  320. }
  321. issues(ctx, ctx.QueryInt64("milestone"), ctx.QueryInt64("project"), util.OptionalBoolOf(isPullList))
  322. var err error
  323. // Get milestones
  324. ctx.Data["Milestones"], err = models.GetMilestones(models.GetMilestonesOption{
  325. RepoID: ctx.Repo.Repository.ID,
  326. State: api.StateType(ctx.Query("state")),
  327. })
  328. if err != nil {
  329. ctx.ServerError("GetAllRepoMilestones", err)
  330. return
  331. }
  332. ctx.Data["CanWriteIssuesOrPulls"] = ctx.Repo.CanWriteIssuesOrPulls(isPullList)
  333. ctx.HTML(200, tplIssues)
  334. }
  335. // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
  336. func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
  337. var err error
  338. ctx.Data["OpenMilestones"], err = models.GetMilestones(models.GetMilestonesOption{
  339. RepoID: repo.ID,
  340. State: api.StateOpen,
  341. })
  342. if err != nil {
  343. ctx.ServerError("GetMilestones", err)
  344. return
  345. }
  346. ctx.Data["ClosedMilestones"], err = models.GetMilestones(models.GetMilestonesOption{
  347. RepoID: repo.ID,
  348. State: api.StateClosed,
  349. })
  350. if err != nil {
  351. ctx.ServerError("GetMilestones", err)
  352. return
  353. }
  354. ctx.Data["Assignees"], err = repo.GetAssignees()
  355. if err != nil {
  356. ctx.ServerError("GetAssignees", err)
  357. return
  358. }
  359. }
  360. func retrieveProjects(ctx *context.Context, repo *models.Repository) {
  361. var err error
  362. ctx.Data["OpenProjects"], _, err = models.GetProjects(models.ProjectSearchOptions{
  363. RepoID: repo.ID,
  364. Page: -1,
  365. IsClosed: util.OptionalBoolFalse,
  366. Type: models.ProjectTypeRepository,
  367. })
  368. if err != nil {
  369. ctx.ServerError("GetProjects", err)
  370. return
  371. }
  372. ctx.Data["ClosedProjects"], _, err = models.GetProjects(models.ProjectSearchOptions{
  373. RepoID: repo.ID,
  374. Page: -1,
  375. IsClosed: util.OptionalBoolTrue,
  376. Type: models.ProjectTypeRepository,
  377. })
  378. if err != nil {
  379. ctx.ServerError("GetProjects", err)
  380. return
  381. }
  382. }
  383. // RetrieveRepoReviewers find all reviewers of a repository
  384. func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issuePosterID int64) {
  385. var err error
  386. ctx.Data["Reviewers"], err = repo.GetReviewers(ctx.User.ID, issuePosterID)
  387. if err != nil {
  388. ctx.ServerError("GetReviewers", err)
  389. return
  390. }
  391. }
  392. // RetrieveRepoMetas find all the meta information of a repository
  393. func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull bool) []*models.Label {
  394. if !ctx.Repo.CanWriteIssuesOrPulls(isPull) {
  395. return nil
  396. }
  397. labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
  398. if err != nil {
  399. ctx.ServerError("GetLabelsByRepoID", err)
  400. return nil
  401. }
  402. ctx.Data["Labels"] = labels
  403. if repo.Owner.IsOrganization() {
  404. orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.Query("sort"), models.ListOptions{})
  405. if err != nil {
  406. return nil
  407. }
  408. ctx.Data["OrgLabels"] = orgLabels
  409. labels = append(labels, orgLabels...)
  410. }
  411. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  412. if ctx.Written() {
  413. return nil
  414. }
  415. retrieveProjects(ctx, repo)
  416. if ctx.Written() {
  417. return nil
  418. }
  419. brs, err := ctx.Repo.GitRepo.GetBranches()
  420. if err != nil {
  421. ctx.ServerError("GetBranches", err)
  422. return nil
  423. }
  424. ctx.Data["Branches"] = brs
  425. // Contains true if the user can create issue dependencies
  426. ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User, isPull)
  427. return labels
  428. }
  429. func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (string, bool) {
  430. var bytes []byte
  431. if ctx.Repo.Commit == nil {
  432. var err error
  433. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
  434. if err != nil {
  435. return "", false
  436. }
  437. }
  438. entry, err := ctx.Repo.Commit.GetTreeEntryByPath(filename)
  439. if err != nil {
  440. return "", false
  441. }
  442. if entry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
  443. return "", false
  444. }
  445. r, err := entry.Blob().DataAsync()
  446. if err != nil {
  447. return "", false
  448. }
  449. defer r.Close()
  450. bytes, err = ioutil.ReadAll(r)
  451. if err != nil {
  452. return "", false
  453. }
  454. return string(bytes), true
  455. }
  456. func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs []string, possibleFiles []string) {
  457. templateCandidates := make([]string, 0, len(possibleFiles))
  458. if ctx.Query("template") != "" {
  459. for _, dirName := range possibleDirs {
  460. templateCandidates = append(templateCandidates, path.Join(dirName, ctx.Query("template")))
  461. }
  462. }
  463. templateCandidates = append(templateCandidates, possibleFiles...) // Append files to the end because they should be fallback
  464. for _, filename := range templateCandidates {
  465. templateContent, found := getFileContentFromDefaultBranch(ctx, filename)
  466. if found {
  467. var meta api.IssueTemplate
  468. templateBody, err := markdown.ExtractMetadata(templateContent, &meta)
  469. if err != nil {
  470. log.Debug("could not extract metadata from %s [%s]: %v", filename, ctx.Repo.Repository.FullName(), err)
  471. ctx.Data[ctxDataKey] = templateContent
  472. return
  473. }
  474. ctx.Data[issueTemplateTitleKey] = meta.Title
  475. ctx.Data[ctxDataKey] = templateBody
  476. labelIDs := make([]string, 0, len(meta.Labels))
  477. if repoLabels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, "", models.ListOptions{}); err == nil {
  478. for _, metaLabel := range meta.Labels {
  479. for _, repoLabel := range repoLabels {
  480. if strings.EqualFold(repoLabel.Name, metaLabel) {
  481. repoLabel.IsChecked = true
  482. labelIDs = append(labelIDs, fmt.Sprintf("%d", repoLabel.ID))
  483. break
  484. }
  485. }
  486. }
  487. ctx.Data["Labels"] = repoLabels
  488. }
  489. ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0
  490. ctx.Data["label_ids"] = strings.Join(labelIDs, ",")
  491. return
  492. }
  493. }
  494. }
  495. // NewIssue render creating issue page
  496. func NewIssue(ctx *context.Context) {
  497. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  498. ctx.Data["PageIsIssueList"] = true
  499. ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
  500. ctx.Data["RequireHighlightJS"] = true
  501. ctx.Data["RequireSimpleMDE"] = true
  502. ctx.Data["RequireTribute"] = true
  503. ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
  504. title := ctx.Query("title")
  505. ctx.Data["TitleQuery"] = title
  506. body := ctx.Query("body")
  507. ctx.Data["BodyQuery"] = body
  508. ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects)
  509. milestoneID := ctx.QueryInt64("milestone")
  510. if milestoneID > 0 {
  511. milestone, err := models.GetMilestoneByID(milestoneID)
  512. if err != nil {
  513. log.Error("GetMilestoneByID: %d: %v", milestoneID, err)
  514. } else {
  515. ctx.Data["milestone_id"] = milestoneID
  516. ctx.Data["Milestone"] = milestone
  517. }
  518. }
  519. projectID := ctx.QueryInt64("project")
  520. if projectID > 0 {
  521. project, err := models.GetProjectByID(projectID)
  522. if err != nil {
  523. log.Error("GetProjectByID: %d: %v", projectID, err)
  524. } else if project.RepoID != ctx.Repo.Repository.ID {
  525. log.Error("GetProjectByID: %d: %v", projectID, fmt.Errorf("project[%d] not in repo [%d]", project.ID, ctx.Repo.Repository.ID))
  526. } else {
  527. ctx.Data["project_id"] = projectID
  528. ctx.Data["Project"] = project
  529. }
  530. }
  531. renderAttachmentSettings(ctx)
  532. RetrieveRepoMetas(ctx, ctx.Repo.Repository, false)
  533. setTemplateIfExists(ctx, issueTemplateKey, context.IssueTemplateDirCandidates, IssueTemplateCandidates)
  534. if ctx.Written() {
  535. return
  536. }
  537. ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeIssues)
  538. ctx.HTML(200, tplIssueNew)
  539. }
  540. // NewIssueChooseTemplate render creating issue from template page
  541. func NewIssueChooseTemplate(ctx *context.Context) {
  542. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  543. ctx.Data["PageIsIssueList"] = true
  544. ctx.Data["milestone"] = ctx.QueryInt64("milestone")
  545. issueTemplates := ctx.IssueTemplatesFromDefaultBranch()
  546. ctx.Data["NewIssueChooseTemplate"] = len(issueTemplates) > 0
  547. ctx.Data["IssueTemplates"] = issueTemplates
  548. ctx.HTML(200, tplIssueChoose)
  549. }
  550. // ValidateRepoMetas check and returns repository's meta informations
  551. func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm, isPull bool) ([]int64, []int64, int64, int64) {
  552. var (
  553. repo = ctx.Repo.Repository
  554. err error
  555. )
  556. labels := RetrieveRepoMetas(ctx, ctx.Repo.Repository, isPull)
  557. if ctx.Written() {
  558. return nil, nil, 0, 0
  559. }
  560. var labelIDs []int64
  561. hasSelected := false
  562. // Check labels.
  563. if len(form.LabelIDs) > 0 {
  564. labelIDs, err = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
  565. if err != nil {
  566. return nil, nil, 0, 0
  567. }
  568. labelIDMark := base.Int64sToMap(labelIDs)
  569. for i := range labels {
  570. if labelIDMark[labels[i].ID] {
  571. labels[i].IsChecked = true
  572. hasSelected = true
  573. }
  574. }
  575. }
  576. ctx.Data["Labels"] = labels
  577. ctx.Data["HasSelectedLabel"] = hasSelected
  578. ctx.Data["label_ids"] = form.LabelIDs
  579. // Check milestone.
  580. milestoneID := form.MilestoneID
  581. if milestoneID > 0 {
  582. ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
  583. if err != nil {
  584. ctx.ServerError("GetMilestoneByID", err)
  585. return nil, nil, 0, 0
  586. }
  587. ctx.Data["milestone_id"] = milestoneID
  588. }
  589. if form.ProjectID > 0 {
  590. p, err := models.GetProjectByID(form.ProjectID)
  591. if err != nil {
  592. ctx.ServerError("GetProjectByID", err)
  593. return nil, nil, 0, 0
  594. }
  595. if p.RepoID != ctx.Repo.Repository.ID {
  596. ctx.NotFound("", nil)
  597. return nil, nil, 0, 0
  598. }
  599. ctx.Data["Project"] = p
  600. ctx.Data["project_id"] = form.ProjectID
  601. }
  602. // Check assignees
  603. var assigneeIDs []int64
  604. if len(form.AssigneeIDs) > 0 {
  605. assigneeIDs, err = base.StringsToInt64s(strings.Split(form.AssigneeIDs, ","))
  606. if err != nil {
  607. return nil, nil, 0, 0
  608. }
  609. // Check if the passed assignees actually exists and is assignable
  610. for _, aID := range assigneeIDs {
  611. assignee, err := models.GetUserByID(aID)
  612. if err != nil {
  613. ctx.ServerError("GetUserByID", err)
  614. return nil, nil, 0, 0
  615. }
  616. valid, err := models.CanBeAssigned(assignee, repo, isPull)
  617. if err != nil {
  618. ctx.ServerError("CanBeAssigned", err)
  619. return nil, nil, 0, 0
  620. }
  621. if !valid {
  622. ctx.ServerError("canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
  623. return nil, nil, 0, 0
  624. }
  625. }
  626. }
  627. // Keep the old assignee id thingy for compatibility reasons
  628. if form.AssigneeID > 0 {
  629. assigneeIDs = append(assigneeIDs, form.AssigneeID)
  630. }
  631. return labelIDs, assigneeIDs, milestoneID, form.ProjectID
  632. }
  633. // NewIssuePost response for creating new issue
  634. func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
  635. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  636. ctx.Data["PageIsIssueList"] = true
  637. ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
  638. ctx.Data["RequireHighlightJS"] = true
  639. ctx.Data["RequireSimpleMDE"] = true
  640. ctx.Data["ReadOnly"] = false
  641. ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
  642. renderAttachmentSettings(ctx)
  643. var (
  644. repo = ctx.Repo.Repository
  645. attachments []string
  646. )
  647. labelIDs, assigneeIDs, milestoneID, projectID := ValidateRepoMetas(ctx, form, false)
  648. if ctx.Written() {
  649. return
  650. }
  651. if setting.Attachment.Enabled {
  652. attachments = form.Files
  653. }
  654. if ctx.HasError() {
  655. ctx.HTML(200, tplIssueNew)
  656. return
  657. }
  658. if util.IsEmptyString(form.Title) {
  659. ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplIssueNew, form)
  660. return
  661. }
  662. issue := &models.Issue{
  663. RepoID: repo.ID,
  664. Title: form.Title,
  665. PosterID: ctx.User.ID,
  666. Poster: ctx.User,
  667. MilestoneID: milestoneID,
  668. Content: form.Content,
  669. Ref: form.Ref,
  670. }
  671. if err := issue_service.NewIssue(repo, issue, labelIDs, attachments, assigneeIDs); err != nil {
  672. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  673. ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
  674. return
  675. }
  676. ctx.ServerError("NewIssue", err)
  677. return
  678. }
  679. if projectID > 0 {
  680. if err := models.ChangeProjectAssign(issue, ctx.User, projectID); err != nil {
  681. ctx.ServerError("ChangeProjectAssign", err)
  682. return
  683. }
  684. }
  685. log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
  686. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  687. }
  688. // commentTag returns the CommentTag for a comment in/with the given repo, poster and issue
  689. func commentTag(repo *models.Repository, poster *models.User, issue *models.Issue) (models.CommentTag, error) {
  690. perm, err := models.GetUserRepoPermission(repo, poster)
  691. if err != nil {
  692. return models.CommentTagNone, err
  693. }
  694. if perm.IsOwner() {
  695. return models.CommentTagOwner, nil
  696. } else if perm.CanWrite(models.UnitTypeCode) {
  697. return models.CommentTagWriter, nil
  698. }
  699. return models.CommentTagNone, nil
  700. }
  701. func getBranchData(ctx *context.Context, issue *models.Issue) {
  702. ctx.Data["BaseBranch"] = nil
  703. ctx.Data["HeadBranch"] = nil
  704. ctx.Data["HeadUserName"] = nil
  705. ctx.Data["BaseName"] = ctx.Repo.Repository.OwnerName
  706. if issue.IsPull {
  707. pull := issue.PullRequest
  708. ctx.Data["BaseBranch"] = pull.BaseBranch
  709. ctx.Data["HeadBranch"] = pull.HeadBranch
  710. ctx.Data["HeadUserName"] = pull.MustHeadUserName()
  711. }
  712. }
  713. // ViewIssue render issue view page
  714. func ViewIssue(ctx *context.Context) {
  715. if ctx.Params(":type") == "issues" {
  716. // If issue was requested we check if repo has external tracker and redirect
  717. extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
  718. if err == nil && extIssueUnit != nil {
  719. if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" {
  720. metas := ctx.Repo.Repository.ComposeMetas()
  721. metas["index"] = ctx.Params(":index")
  722. ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas))
  723. return
  724. }
  725. } else if err != nil && !models.IsErrUnitTypeNotExist(err) {
  726. ctx.ServerError("GetUnit", err)
  727. return
  728. }
  729. }
  730. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  731. if err != nil {
  732. if models.IsErrIssueNotExist(err) {
  733. ctx.NotFound("GetIssueByIndex", err)
  734. } else {
  735. ctx.ServerError("GetIssueByIndex", err)
  736. }
  737. return
  738. }
  739. // Make sure type and URL matches.
  740. if ctx.Params(":type") == "issues" && issue.IsPull {
  741. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  742. return
  743. } else if ctx.Params(":type") == "pulls" && !issue.IsPull {
  744. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  745. return
  746. }
  747. if issue.IsPull {
  748. MustAllowPulls(ctx)
  749. if ctx.Written() {
  750. return
  751. }
  752. ctx.Data["PageIsPullList"] = true
  753. ctx.Data["PageIsPullConversation"] = true
  754. } else {
  755. MustEnableIssues(ctx)
  756. if ctx.Written() {
  757. return
  758. }
  759. ctx.Data["PageIsIssueList"] = true
  760. ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
  761. }
  762. if issue.IsPull && !ctx.Repo.CanRead(models.UnitTypeIssues) {
  763. ctx.Data["IssueType"] = "pulls"
  764. } else if !issue.IsPull && !ctx.Repo.CanRead(models.UnitTypePullRequests) {
  765. ctx.Data["IssueType"] = "issues"
  766. } else {
  767. ctx.Data["IssueType"] = "all"
  768. }
  769. ctx.Data["RequireHighlightJS"] = true
  770. ctx.Data["RequireTribute"] = true
  771. ctx.Data["RequireSimpleMDE"] = true
  772. ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects)
  773. renderAttachmentSettings(ctx)
  774. if err = issue.LoadAttributes(); err != nil {
  775. ctx.ServerError("LoadAttributes", err)
  776. return
  777. }
  778. if err = filterXRefComments(ctx, issue); err != nil {
  779. ctx.ServerError("filterXRefComments", err)
  780. return
  781. }
  782. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  783. iw := new(models.IssueWatch)
  784. if ctx.User != nil {
  785. iw.UserID = ctx.User.ID
  786. iw.IssueID = issue.ID
  787. iw.IsWatching, err = models.CheckIssueWatch(ctx.User, issue)
  788. if err != nil {
  789. ctx.InternalServerError(err)
  790. return
  791. }
  792. }
  793. ctx.Data["IssueWatch"] = iw
  794. issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink,
  795. ctx.Repo.Repository.ComposeMetas()))
  796. repo := ctx.Repo.Repository
  797. // Get more information if it's a pull request.
  798. if issue.IsPull {
  799. if issue.PullRequest.HasMerged {
  800. ctx.Data["DisableStatusChange"] = issue.PullRequest.HasMerged
  801. PrepareMergedViewPullInfo(ctx, issue)
  802. } else {
  803. PrepareViewPullInfo(ctx, issue)
  804. ctx.Data["DisableStatusChange"] = ctx.Data["IsPullRequestBroken"] == true && issue.IsClosed
  805. }
  806. if ctx.Written() {
  807. return
  808. }
  809. }
  810. // Metas.
  811. // Check labels.
  812. labelIDMark := make(map[int64]bool)
  813. for i := range issue.Labels {
  814. labelIDMark[issue.Labels[i].ID] = true
  815. }
  816. labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
  817. if err != nil {
  818. ctx.ServerError("GetLabelsByRepoID", err)
  819. return
  820. }
  821. ctx.Data["Labels"] = labels
  822. if repo.Owner.IsOrganization() {
  823. orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.Query("sort"), models.ListOptions{})
  824. if err != nil {
  825. ctx.ServerError("GetLabelsByOrgID", err)
  826. return
  827. }
  828. ctx.Data["OrgLabels"] = orgLabels
  829. labels = append(labels, orgLabels...)
  830. }
  831. hasSelected := false
  832. for i := range labels {
  833. if labelIDMark[labels[i].ID] {
  834. labels[i].IsChecked = true
  835. hasSelected = true
  836. }
  837. }
  838. ctx.Data["HasSelectedLabel"] = hasSelected
  839. // Check milestone and assignee.
  840. if ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
  841. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  842. retrieveProjects(ctx, repo)
  843. if ctx.Written() {
  844. return
  845. }
  846. }
  847. if issue.IsPull {
  848. canChooseReviewer := ctx.Repo.CanWrite(models.UnitTypePullRequests)
  849. if !canChooseReviewer && ctx.User != nil && ctx.IsSigned {
  850. canChooseReviewer, err = models.IsOfficialReviewer(issue, ctx.User)
  851. if err != nil {
  852. ctx.ServerError("IsOfficialReviewer", err)
  853. return
  854. }
  855. }
  856. if canChooseReviewer {
  857. RetrieveRepoReviewers(ctx, repo, issue.PosterID)
  858. ctx.Data["CanChooseReviewer"] = true
  859. } else {
  860. ctx.Data["CanChooseReviewer"] = false
  861. }
  862. if ctx.Written() {
  863. return
  864. }
  865. }
  866. if ctx.IsSigned {
  867. // Update issue-user.
  868. if err = issue.ReadBy(ctx.User.ID); err != nil {
  869. ctx.ServerError("ReadBy", err)
  870. return
  871. }
  872. }
  873. var (
  874. tag models.CommentTag
  875. ok bool
  876. marked = make(map[int64]models.CommentTag)
  877. comment *models.Comment
  878. participants = make([]*models.User, 1, 10)
  879. )
  880. if ctx.Repo.Repository.IsTimetrackerEnabled() {
  881. if ctx.IsSigned {
  882. // Deal with the stopwatch
  883. ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.User.ID, issue.ID)
  884. if !ctx.Data["IsStopwatchRunning"].(bool) {
  885. var exists bool
  886. var sw *models.Stopwatch
  887. if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
  888. ctx.ServerError("HasUserStopwatch", err)
  889. return
  890. }
  891. ctx.Data["HasUserStopwatch"] = exists
  892. if exists {
  893. // Add warning if the user has already a stopwatch
  894. var otherIssue *models.Issue
  895. if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
  896. ctx.ServerError("GetIssueByID", err)
  897. return
  898. }
  899. if err = otherIssue.LoadRepo(); err != nil {
  900. ctx.ServerError("LoadRepo", err)
  901. return
  902. }
  903. // Add link to the issue of the already running stopwatch
  904. ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
  905. }
  906. }
  907. ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.User)
  908. } else {
  909. ctx.Data["CanUseTimetracker"] = false
  910. }
  911. if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
  912. ctx.ServerError("TotalTimes", err)
  913. return
  914. }
  915. }
  916. // Check if the user can use the dependencies
  917. ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull)
  918. // check if dependencies can be created across repositories
  919. ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
  920. if issue.ShowTag, err = commentTag(repo, issue.Poster, issue); err != nil {
  921. ctx.ServerError("commentTag", err)
  922. return
  923. }
  924. marked[issue.PosterID] = issue.ShowTag
  925. // Render comments and and fetch participants.
  926. participants[0] = issue.Poster
  927. for _, comment = range issue.Comments {
  928. comment.Issue = issue
  929. if err := comment.LoadPoster(); err != nil {
  930. ctx.ServerError("LoadPoster", err)
  931. return
  932. }
  933. if comment.Type == models.CommentTypeComment {
  934. if err := comment.LoadAttachments(); err != nil {
  935. ctx.ServerError("LoadAttachments", err)
  936. return
  937. }
  938. comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink,
  939. ctx.Repo.Repository.ComposeMetas()))
  940. // Check tag.
  941. tag, ok = marked[comment.PosterID]
  942. if ok {
  943. comment.ShowTag = tag
  944. continue
  945. }
  946. comment.ShowTag, err = commentTag(repo, comment.Poster, issue)
  947. if err != nil {
  948. ctx.ServerError("commentTag", err)
  949. return
  950. }
  951. marked[comment.PosterID] = comment.ShowTag
  952. participants = addParticipant(comment.Poster, participants)
  953. } else if comment.Type == models.CommentTypeLabel {
  954. if err = comment.LoadLabel(); err != nil {
  955. ctx.ServerError("LoadLabel", err)
  956. return
  957. }
  958. } else if comment.Type == models.CommentTypeMilestone {
  959. if err = comment.LoadMilestone(); err != nil {
  960. ctx.ServerError("LoadMilestone", err)
  961. return
  962. }
  963. ghostMilestone := &models.Milestone{
  964. ID: -1,
  965. Name: ctx.Tr("repo.issues.deleted_milestone"),
  966. }
  967. if comment.OldMilestoneID > 0 && comment.OldMilestone == nil {
  968. comment.OldMilestone = ghostMilestone
  969. }
  970. if comment.MilestoneID > 0 && comment.Milestone == nil {
  971. comment.Milestone = ghostMilestone
  972. }
  973. } else if comment.Type == models.CommentTypeProject {
  974. if err = comment.LoadProject(); err != nil {
  975. ctx.ServerError("LoadProject", err)
  976. return
  977. }
  978. ghostProject := &models.Project{
  979. ID: -1,
  980. Title: ctx.Tr("repo.issues.deleted_project"),
  981. }
  982. if comment.OldProjectID > 0 && comment.OldProject == nil {
  983. comment.OldProject = ghostProject
  984. }
  985. if comment.ProjectID > 0 && comment.Project == nil {
  986. comment.Project = ghostProject
  987. }
  988. } else if comment.Type == models.CommentTypeAssignees || comment.Type == models.CommentTypeReviewRequest {
  989. if err = comment.LoadAssigneeUser(); err != nil {
  990. ctx.ServerError("LoadAssigneeUser", err)
  991. return
  992. }
  993. } else if comment.Type == models.CommentTypeRemoveDependency || comment.Type == models.CommentTypeAddDependency {
  994. if err = comment.LoadDepIssueDetails(); err != nil {
  995. if !models.IsErrIssueNotExist(err) {
  996. ctx.ServerError("LoadDepIssueDetails", err)
  997. return
  998. }
  999. }
  1000. } else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview {
  1001. comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink,
  1002. ctx.Repo.Repository.ComposeMetas()))
  1003. if err = comment.LoadReview(); err != nil && !models.IsErrReviewNotExist(err) {
  1004. ctx.ServerError("LoadReview", err)
  1005. return
  1006. }
  1007. participants = addParticipant(comment.Poster, participants)
  1008. if comment.Review == nil {
  1009. continue
  1010. }
  1011. if err = comment.Review.LoadAttributes(); err != nil {
  1012. if !models.IsErrUserNotExist(err) {
  1013. ctx.ServerError("Review.LoadAttributes", err)
  1014. return
  1015. }
  1016. comment.Review.Reviewer = models.NewGhostUser()
  1017. }
  1018. if err = comment.Review.LoadCodeComments(); err != nil {
  1019. ctx.ServerError("Review.LoadCodeComments", err)
  1020. return
  1021. }
  1022. if err = comment.LoadResolveDoer(); err != nil {
  1023. ctx.ServerError("LoadResolveDoer", err)
  1024. return
  1025. }
  1026. } else if comment.Type == models.CommentTypePullPush {
  1027. participants = addParticipant(comment.Poster, participants)
  1028. if err = comment.LoadPushCommits(); err != nil {
  1029. ctx.ServerError("LoadPushCommits", err)
  1030. return
  1031. }
  1032. }
  1033. }
  1034. getBranchData(ctx, issue)
  1035. if issue.IsPull {
  1036. pull := issue.PullRequest
  1037. pull.Issue = issue
  1038. canDelete := false
  1039. ctx.Data["AllowMerge"] = false
  1040. if ctx.IsSigned {
  1041. if err := pull.LoadHeadRepo(); err != nil {
  1042. log.Error("LoadHeadRepo: %v", err)
  1043. } else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch {
  1044. perm, err := models.GetUserRepoPermission(pull.HeadRepo, ctx.User)
  1045. if err != nil {
  1046. ctx.ServerError("GetUserRepoPermission", err)
  1047. return
  1048. }
  1049. if perm.CanWrite(models.UnitTypeCode) {
  1050. // Check if branch is not protected
  1051. if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch, ctx.User); err != nil {
  1052. log.Error("IsProtectedBranch: %v", err)
  1053. } else if !protected {
  1054. canDelete = true
  1055. ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
  1056. }
  1057. }
  1058. }
  1059. if err := pull.LoadBaseRepo(); err != nil {
  1060. log.Error("LoadBaseRepo: %v", err)
  1061. }
  1062. perm, err := models.GetUserRepoPermission(pull.BaseRepo, ctx.User)
  1063. if err != nil {
  1064. ctx.ServerError("GetUserRepoPermission", err)
  1065. return
  1066. }
  1067. ctx.Data["AllowMerge"], err = pull_service.IsUserAllowedToMerge(pull, perm, ctx.User)
  1068. if err != nil {
  1069. ctx.ServerError("IsUserAllowedToMerge", err)
  1070. return
  1071. }
  1072. if ctx.Data["CanMarkConversation"], err = models.CanMarkConversation(issue, ctx.User); err != nil {
  1073. ctx.ServerError("CanMarkConversation", err)
  1074. return
  1075. }
  1076. }
  1077. prUnit, err := repo.GetUnit(models.UnitTypePullRequests)
  1078. if err != nil {
  1079. ctx.ServerError("GetUnit", err)
  1080. return
  1081. }
  1082. prConfig := prUnit.PullRequestsConfig()
  1083. // Check correct values and select default
  1084. if ms, ok := ctx.Data["MergeStyle"].(models.MergeStyle); !ok ||
  1085. !prConfig.IsMergeStyleAllowed(ms) {
  1086. if prConfig.AllowMerge {
  1087. ctx.Data["MergeStyle"] = models.MergeStyleMerge
  1088. } else if prConfig.AllowRebase {
  1089. ctx.Data["MergeStyle"] = models.MergeStyleRebase
  1090. } else if prConfig.AllowRebaseMerge {
  1091. ctx.Data["MergeStyle"] = models.MergeStyleRebaseMerge
  1092. } else if prConfig.AllowSquash {
  1093. ctx.Data["MergeStyle"] = models.MergeStyleSquash
  1094. } else {
  1095. ctx.Data["MergeStyle"] = ""
  1096. }
  1097. }
  1098. if err = pull.LoadProtectedBranch(); err != nil {
  1099. ctx.ServerError("LoadProtectedBranch", err)
  1100. return
  1101. }
  1102. if pull.ProtectedBranch != nil {
  1103. cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
  1104. ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull)
  1105. ctx.Data["IsBlockedByRejection"] = pull.ProtectedBranch.MergeBlockedByRejectedReview(pull)
  1106. ctx.Data["IsBlockedByOutdatedBranch"] = pull.ProtectedBranch.MergeBlockedByOutdatedBranch(pull)
  1107. ctx.Data["GrantedApprovals"] = cnt
  1108. ctx.Data["RequireSigned"] = pull.ProtectedBranch.RequireSignedCommits
  1109. }
  1110. ctx.Data["WillSign"] = false
  1111. if ctx.User != nil {
  1112. sign, key, _, err := pull.SignMerge(ctx.User, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitRefName())
  1113. ctx.Data["WillSign"] = sign
  1114. ctx.Data["SigningKey"] = key
  1115. if err != nil {
  1116. if models.IsErrWontSign(err) {
  1117. ctx.Data["WontSignReason"] = err.(*models.ErrWontSign).Reason
  1118. } else {
  1119. ctx.Data["WontSignReason"] = "error"
  1120. log.Error("Error whilst checking if could sign pr %d in repo %s. Error: %v", pull.ID, pull.BaseRepo.FullName(), err)
  1121. }
  1122. }
  1123. } else {
  1124. ctx.Data["WontSignReason"] = "not_signed_in"
  1125. }
  1126. ctx.Data["IsPullBranchDeletable"] = canDelete &&
  1127. pull.HeadRepo != nil &&
  1128. git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch) &&
  1129. (!pull.HasMerged || ctx.Data["HeadBranchCommitID"] == ctx.Data["PullHeadCommitID"])
  1130. ctx.Data["PullReviewers"], err = models.GetReviewersByIssueID(issue.ID)
  1131. if err != nil {
  1132. ctx.ServerError("GetReviewersByIssueID", err)
  1133. return
  1134. }
  1135. }
  1136. // Get Dependencies
  1137. ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
  1138. if err != nil {
  1139. ctx.ServerError("BlockedByDependencies", err)
  1140. return
  1141. }
  1142. ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()
  1143. if err != nil {
  1144. ctx.ServerError("BlockingDependencies", err)
  1145. return
  1146. }
  1147. ctx.Data["Participants"] = participants
  1148. ctx.Data["NumParticipants"] = len(participants)
  1149. ctx.Data["Issue"] = issue
  1150. ctx.Data["ReadOnly"] = false
  1151. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
  1152. ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
  1153. ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
  1154. ctx.Data["HasProjectsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeProjects)
  1155. ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin)
  1156. ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons
  1157. ctx.Data["RefEndName"] = git.RefEndName(issue.Ref)
  1158. ctx.HTML(200, tplIssueView)
  1159. }
  1160. // GetActionIssue will return the issue which is used in the context.
  1161. func GetActionIssue(ctx *context.Context) *models.Issue {
  1162. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  1163. if err != nil {
  1164. ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
  1165. return nil
  1166. }
  1167. issue.Repo = ctx.Repo.Repository
  1168. checkIssueRights(ctx, issue)
  1169. if ctx.Written() {
  1170. return nil
  1171. }
  1172. if err = issue.LoadAttributes(); err != nil {
  1173. ctx.ServerError("LoadAttributes", nil)
  1174. return nil
  1175. }
  1176. return issue
  1177. }
  1178. func checkIssueRights(ctx *context.Context, issue *models.Issue) {
  1179. if issue.IsPull && !ctx.Repo.CanRead(models.UnitTypePullRequests) ||
  1180. !issue.IsPull && !ctx.Repo.CanRead(models.UnitTypeIssues) {
  1181. ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
  1182. }
  1183. }
  1184. func getActionIssues(ctx *context.Context) []*models.Issue {
  1185. commaSeparatedIssueIDs := ctx.Query("issue_ids")
  1186. if len(commaSeparatedIssueIDs) == 0 {
  1187. return nil
  1188. }
  1189. issueIDs := make([]int64, 0, 10)
  1190. for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") {
  1191. issueID, err := strconv.ParseInt(stringIssueID, 10, 64)
  1192. if err != nil {
  1193. ctx.ServerError("ParseInt", err)
  1194. return nil
  1195. }
  1196. issueIDs = append(issueIDs, issueID)
  1197. }
  1198. issues, err := models.GetIssuesByIDs(issueIDs)
  1199. if err != nil {
  1200. ctx.ServerError("GetIssuesByIDs", err)
  1201. return nil
  1202. }
  1203. // Check access rights for all issues
  1204. issueUnitEnabled := ctx.Repo.CanRead(models.UnitTypeIssues)
  1205. prUnitEnabled := ctx.Repo.CanRead(models.UnitTypePullRequests)
  1206. for _, issue := range issues {
  1207. if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
  1208. ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
  1209. return nil
  1210. }
  1211. if err = issue.LoadAttributes(); err != nil {
  1212. ctx.ServerError("LoadAttributes", err)
  1213. return nil
  1214. }
  1215. }
  1216. return issues
  1217. }
  1218. // UpdateIssueTitle change issue's title
  1219. func UpdateIssueTitle(ctx *context.Context) {
  1220. issue := GetActionIssue(ctx)
  1221. if ctx.Written() {
  1222. return
  1223. }
  1224. if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
  1225. ctx.Error(403)
  1226. return
  1227. }
  1228. title := ctx.QueryTrim("title")
  1229. if len(title) == 0 {
  1230. ctx.Error(204)
  1231. return
  1232. }
  1233. if err := issue_service.ChangeTitle(issue, ctx.User, title); err != nil {
  1234. ctx.ServerError("ChangeTitle", err)
  1235. return
  1236. }
  1237. ctx.JSON(200, map[string]interface{}{
  1238. "title": issue.Title,
  1239. })
  1240. }
  1241. // UpdateIssueRef change issue's ref (branch)
  1242. func UpdateIssueRef(ctx *context.Context) {
  1243. issue := GetActionIssue(ctx)
  1244. if ctx.Written() {
  1245. return
  1246. }
  1247. if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) || issue.IsPull {
  1248. ctx.Error(403)
  1249. return
  1250. }
  1251. ref := ctx.QueryTrim("ref")
  1252. if err := issue_service.ChangeIssueRef(issue, ctx.User, ref); err != nil {
  1253. ctx.ServerError("ChangeRef", err)
  1254. return
  1255. }
  1256. ctx.JSON(200, map[string]interface{}{
  1257. "ref": ref,
  1258. })
  1259. }
  1260. // UpdateIssueContent change issue's content
  1261. func UpdateIssueContent(ctx *context.Context) {
  1262. issue := GetActionIssue(ctx)
  1263. if ctx.Written() {
  1264. return
  1265. }
  1266. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
  1267. ctx.Error(403)
  1268. return
  1269. }
  1270. content := ctx.Query("content")
  1271. if err := issue_service.ChangeContent(issue, ctx.User, content); err != nil {
  1272. ctx.ServerError("ChangeContent", err)
  1273. return
  1274. }
  1275. files := ctx.QueryStrings("files[]")
  1276. if err := updateAttachments(issue, files); err != nil {
  1277. ctx.ServerError("UpdateAttachments", err)
  1278. }
  1279. ctx.JSON(200, map[string]interface{}{
  1280. "content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  1281. "attachments": attachmentsHTML(ctx, issue.Attachments),
  1282. })
  1283. }
  1284. // UpdateIssueMilestone change issue's milestone
  1285. func UpdateIssueMilestone(ctx *context.Context) {
  1286. issues := getActionIssues(ctx)
  1287. if ctx.Written() {
  1288. return
  1289. }
  1290. milestoneID := ctx.QueryInt64("id")
  1291. for _, issue := range issues {
  1292. oldMilestoneID := issue.MilestoneID
  1293. if oldMilestoneID == milestoneID {
  1294. continue
  1295. }
  1296. issue.MilestoneID = milestoneID
  1297. if err := issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
  1298. ctx.ServerError("ChangeMilestoneAssign", err)
  1299. return
  1300. }
  1301. }
  1302. ctx.JSON(200, map[string]interface{}{
  1303. "ok": true,
  1304. })
  1305. }
  1306. // UpdateIssueAssignee change issue's or pull's assignee
  1307. func UpdateIssueAssignee(ctx *context.Context) {
  1308. issues := getActionIssues(ctx)
  1309. if ctx.Written() {
  1310. return
  1311. }
  1312. assigneeID := ctx.QueryInt64("id")
  1313. action := ctx.Query("action")
  1314. for _, issue := range issues {
  1315. switch action {
  1316. case "clear":
  1317. if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*models.User{}); err != nil {
  1318. ctx.ServerError("ClearAssignees", err)
  1319. return
  1320. }
  1321. default:
  1322. assignee, err := models.GetUserByID(assigneeID)
  1323. if err != nil {
  1324. ctx.ServerError("GetUserByID", err)
  1325. return
  1326. }
  1327. valid, err := models.CanBeAssigned(assignee, issue.Repo, issue.IsPull)
  1328. if err != nil {
  1329. ctx.ServerError("canBeAssigned", err)
  1330. return
  1331. }
  1332. if !valid {
  1333. ctx.ServerError("canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: assigneeID, RepoName: issue.Repo.Name})
  1334. return
  1335. }
  1336. _, _, err = issue_service.ToggleAssignee(issue, ctx.User, assigneeID)
  1337. if err != nil {
  1338. ctx.ServerError("ToggleAssignee", err)
  1339. return
  1340. }
  1341. }
  1342. }
  1343. ctx.JSON(200, map[string]interface{}{
  1344. "ok": true,
  1345. })
  1346. }
  1347. func isLegalReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models.Issue) error {
  1348. if reviewer.IsOrganization() {
  1349. return fmt.Errorf("Organization can't be added as reviewer [user_id: %d, repo_id: %d]", reviewer.ID, issue.PullRequest.BaseRepo.ID)
  1350. }
  1351. if doer.IsOrganization() {
  1352. return fmt.Errorf("Organization can't be doer to add reviewer [user_id: %d, repo_id: %d]", doer.ID, issue.PullRequest.BaseRepo.ID)
  1353. }
  1354. permReviewer, err := models.GetUserRepoPermission(issue.Repo, reviewer)
  1355. if err != nil {
  1356. return err
  1357. }
  1358. permDoer, err := models.GetUserRepoPermission(issue.Repo, doer)
  1359. if err != nil {
  1360. return err
  1361. }
  1362. lastreview, err := models.GetReviewerByIssueIDAndUserID(issue.ID, reviewer.ID)
  1363. if err != nil {
  1364. return err
  1365. }
  1366. var pemResult bool
  1367. if isAdd {
  1368. pemResult = permReviewer.CanAccessAny(models.AccessModeRead, models.UnitTypePullRequests)
  1369. if !pemResult {
  1370. return fmt.Errorf("Reviewer can't read [user_id: %d, repo_name: %s]", reviewer.ID, issue.Repo.Name)
  1371. }
  1372. if doer.ID == issue.PosterID && lastreview != nil && lastreview.Type != models.ReviewTypeRequest {
  1373. return nil
  1374. }
  1375. pemResult = permDoer.CanAccessAny(models.AccessModeWrite, models.UnitTypePullRequests)
  1376. if !pemResult {
  1377. pemResult, err = models.IsOfficialReviewer(issue, doer)
  1378. if err != nil {
  1379. return err
  1380. }
  1381. if !pemResult {
  1382. return fmt.Errorf("Doer can't choose reviewer [user_id: %d, repo_name: %s, issue_id: %d]", doer.ID, issue.Repo.Name, issue.ID)
  1383. }
  1384. }
  1385. if doer.ID == reviewer.ID {
  1386. return fmt.Errorf("doer can't be reviewer [user_id: %d, repo_name: %s]", doer.ID, issue.Repo.Name)
  1387. }
  1388. if reviewer.ID == issue.PosterID {
  1389. return fmt.Errorf("poster of pr can't be reviewer [user_id: %d, repo_name: %s]", reviewer.ID, issue.Repo.Name)
  1390. }
  1391. } else {
  1392. if lastreview.Type == models.ReviewTypeRequest && lastreview.ReviewerID == doer.ID {
  1393. return nil
  1394. }
  1395. pemResult = permDoer.IsAdmin()
  1396. if !pemResult {
  1397. return fmt.Errorf("Doer is not admin [user_id: %d, repo_name: %s]", doer.ID, issue.Repo.Name)
  1398. }
  1399. }
  1400. return nil
  1401. }
  1402. // updatePullReviewRequest change pull's request reviewers
  1403. func updatePullReviewRequest(ctx *context.Context) {
  1404. issues := getActionIssues(ctx)
  1405. if ctx.Written() {
  1406. return
  1407. }
  1408. reviewID := ctx.QueryInt64("id")
  1409. action := ctx.Query("action")
  1410. // TODO: Not support 'clear' now
  1411. if action != "attach" && action != "detach" {
  1412. ctx.Status(403)
  1413. return
  1414. }
  1415. for _, issue := range issues {
  1416. if issue.IsPull {
  1417. reviewer, err := models.GetUserByID(reviewID)
  1418. if err != nil {
  1419. ctx.ServerError("GetUserByID", err)
  1420. return
  1421. }
  1422. err = isLegalReviewRequest(reviewer, ctx.User, action == "attach", issue)
  1423. if err != nil {
  1424. ctx.ServerError("isLegalRequestReview", err)
  1425. return
  1426. }
  1427. err = issue_service.ReviewRequest(issue, ctx.User, reviewer, action == "attach")
  1428. if err != nil {
  1429. ctx.ServerError("ReviewRequest", err)
  1430. return
  1431. }
  1432. } else {
  1433. ctx.Status(403)
  1434. return
  1435. }
  1436. }
  1437. ctx.JSON(200, map[string]interface{}{
  1438. "ok": true,
  1439. })
  1440. }
  1441. // UpdatePullReviewRequest add or remove review request
  1442. func UpdatePullReviewRequest(ctx *context.Context) {
  1443. updatePullReviewRequest(ctx)
  1444. }
  1445. // UpdateIssueStatus change issue's status
  1446. func UpdateIssueStatus(ctx *context.Context) {
  1447. issues := getActionIssues(ctx)
  1448. if ctx.Written() {
  1449. return
  1450. }
  1451. var isClosed bool
  1452. switch action := ctx.Query("action"); action {
  1453. case "open":
  1454. isClosed = false
  1455. case "close":
  1456. isClosed = true
  1457. default:
  1458. log.Warn("Unrecognized action: %s", action)
  1459. }
  1460. if _, err := models.IssueList(issues).LoadRepositories(); err != nil {
  1461. ctx.ServerError("LoadRepositories", err)
  1462. return
  1463. }
  1464. for _, issue := range issues {
  1465. if issue.IsClosed != isClosed {
  1466. if err := issue_service.ChangeStatus(issue, ctx.User, isClosed); err != nil {
  1467. if models.IsErrDependenciesLeft(err) {
  1468. ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
  1469. "error": "cannot close this issue because it still has open dependencies",
  1470. })
  1471. return
  1472. }
  1473. ctx.ServerError("ChangeStatus", err)
  1474. return
  1475. }
  1476. }
  1477. }
  1478. ctx.JSON(200, map[string]interface{}{
  1479. "ok": true,
  1480. })
  1481. }
  1482. // NewComment create a comment for issue
  1483. func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
  1484. issue := GetActionIssue(ctx)
  1485. if ctx.Written() {
  1486. return
  1487. }
  1488. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
  1489. if log.IsTrace() {
  1490. if ctx.IsSigned {
  1491. issueType := "issues"
  1492. if issue.IsPull {
  1493. issueType = "pulls"
  1494. }
  1495. log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
  1496. "User in Repo has Permissions: %-+v",
  1497. ctx.User,
  1498. log.NewColoredIDValue(issue.PosterID),
  1499. issueType,
  1500. ctx.Repo.Repository,
  1501. ctx.Repo.Permission)
  1502. } else {
  1503. log.Trace("Permission Denied: Not logged in")
  1504. }
  1505. }
  1506. ctx.Error(403)
  1507. return
  1508. }
  1509. if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.User.IsAdmin {
  1510. ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
  1511. ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
  1512. return
  1513. }
  1514. var attachments []string
  1515. if setting.Attachment.Enabled {
  1516. attachments = form.Files
  1517. }
  1518. if ctx.HasError() {
  1519. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  1520. ctx.Redirect(issue.HTMLURL())
  1521. return
  1522. }
  1523. var comment *models.Comment
  1524. defer func() {
  1525. // Check if issue admin/poster changes the status of issue.
  1526. if (ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) &&
  1527. (form.Status == "reopen" || form.Status == "close") &&
  1528. !(issue.IsPull && issue.PullRequest.HasMerged) {
  1529. // Duplication and conflict check should apply to reopen pull request.
  1530. var pr *models.PullRequest
  1531. if form.Status == "reopen" && issue.IsPull {
  1532. pull := issue.PullRequest
  1533. var err error
  1534. pr, err = models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
  1535. if err != nil {
  1536. if !models.IsErrPullRequestNotExist(err) {
  1537. ctx.ServerError("GetUnmergedPullRequest", err)
  1538. return
  1539. }
  1540. }
  1541. // Regenerate patch and test conflict.
  1542. if pr == nil {
  1543. pull_service.AddToTaskQueue(issue.PullRequest)
  1544. }
  1545. }
  1546. if pr != nil {
  1547. ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
  1548. } else {
  1549. isClosed := form.Status == "close"
  1550. if err := issue_service.ChangeStatus(issue, ctx.User, isClosed); err != nil {
  1551. log.Error("ChangeStatus: %v", err)
  1552. if models.IsErrDependenciesLeft(err) {
  1553. if issue.IsPull {
  1554. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
  1555. ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther)
  1556. } else {
  1557. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.issue_close_blocked"))
  1558. ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther)
  1559. }
  1560. return
  1561. }
  1562. } else {
  1563. if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
  1564. ctx.ServerError("CreateOrStopIssueStopwatch", err)
  1565. return
  1566. }
  1567. log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
  1568. }
  1569. }
  1570. }
  1571. // Redirect to comment hashtag if there is any actual content.
  1572. typeName := "issues"
  1573. if issue.IsPull {
  1574. typeName = "pulls"
  1575. }
  1576. if comment != nil {
  1577. ctx.Redirect(fmt.Sprintf("%s/%s/%d#%s", ctx.Repo.RepoLink, typeName, issue.Index, comment.HashTag()))
  1578. } else {
  1579. ctx.Redirect(fmt.Sprintf("%s/%s/%d", ctx.Repo.RepoLink, typeName, issue.Index))
  1580. }
  1581. }()
  1582. // Fix #321: Allow empty comments, as long as we have attachments.
  1583. if len(form.Content) == 0 && len(attachments) == 0 {
  1584. return
  1585. }
  1586. comment, err := comment_service.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
  1587. if err != nil {
  1588. ctx.ServerError("CreateIssueComment", err)
  1589. return
  1590. }
  1591. log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
  1592. }
  1593. // UpdateCommentContent change comment of issue's content
  1594. func UpdateCommentContent(ctx *context.Context) {
  1595. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  1596. if err != nil {
  1597. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  1598. return
  1599. }
  1600. if err := comment.LoadIssue(); err != nil {
  1601. ctx.NotFoundOrServerError("LoadIssue", models.IsErrIssueNotExist, err)
  1602. return
  1603. }
  1604. if comment.Type == models.CommentTypeComment {
  1605. if err := comment.LoadAttachments(); err != nil {
  1606. ctx.ServerError("LoadAttachments", err)
  1607. return
  1608. }
  1609. }
  1610. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
  1611. ctx.Error(403)
  1612. return
  1613. } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
  1614. ctx.Error(204)
  1615. return
  1616. }
  1617. oldContent := comment.Content
  1618. comment.Content = ctx.Query("content")
  1619. if len(comment.Content) == 0 {
  1620. ctx.JSON(200, map[string]interface{}{
  1621. "content": "",
  1622. })
  1623. return
  1624. }
  1625. if err = comment_service.UpdateComment(comment, ctx.User, oldContent); err != nil {
  1626. ctx.ServerError("UpdateComment", err)
  1627. return
  1628. }
  1629. files := ctx.QueryStrings("files[]")
  1630. if err := updateAttachments(comment, files); err != nil {
  1631. ctx.ServerError("UpdateAttachments", err)
  1632. }
  1633. ctx.JSON(200, map[string]interface{}{
  1634. "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  1635. "attachments": attachmentsHTML(ctx, comment.Attachments),
  1636. })
  1637. }
  1638. // DeleteComment delete comment of issue
  1639. func DeleteComment(ctx *context.Context) {
  1640. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  1641. if err != nil {
  1642. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  1643. return
  1644. }
  1645. if err := comment.LoadIssue(); err != nil {
  1646. ctx.NotFoundOrServerError("LoadIssue", models.IsErrIssueNotExist, err)
  1647. return
  1648. }
  1649. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
  1650. ctx.Error(403)
  1651. return
  1652. } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
  1653. ctx.Error(204)
  1654. return
  1655. }
  1656. if err = comment_service.DeleteComment(comment, ctx.User); err != nil {
  1657. ctx.ServerError("DeleteCommentByID", err)
  1658. return
  1659. }
  1660. ctx.Status(200)
  1661. }
  1662. // ChangeIssueReaction create a reaction for issue
  1663. func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) {
  1664. issue := GetActionIssue(ctx)
  1665. if ctx.Written() {
  1666. return
  1667. }
  1668. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
  1669. if log.IsTrace() {
  1670. if ctx.IsSigned {
  1671. issueType := "issues"
  1672. if issue.IsPull {
  1673. issueType = "pulls"
  1674. }
  1675. log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
  1676. "User in Repo has Permissions: %-+v",
  1677. ctx.User,
  1678. log.NewColoredIDValue(issue.PosterID),
  1679. issueType,
  1680. ctx.Repo.Repository,
  1681. ctx.Repo.Permission)
  1682. } else {
  1683. log.Trace("Permission Denied: Not logged in")
  1684. }
  1685. }
  1686. ctx.Error(403)
  1687. return
  1688. }
  1689. if ctx.HasError() {
  1690. ctx.ServerError("ChangeIssueReaction", errors.New(ctx.GetErrMsg()))
  1691. return
  1692. }
  1693. switch ctx.Params(":action") {
  1694. case "react":
  1695. reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Content)
  1696. if err != nil {
  1697. if models.IsErrForbiddenIssueReaction(err) {
  1698. ctx.ServerError("ChangeIssueReaction", err)
  1699. return
  1700. }
  1701. log.Info("CreateIssueReaction: %s", err)
  1702. break
  1703. }
  1704. // Reload new reactions
  1705. issue.Reactions = nil
  1706. if err = issue.LoadAttributes(); err != nil {
  1707. log.Info("issue.LoadAttributes: %s", err)
  1708. break
  1709. }
  1710. log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
  1711. case "unreact":
  1712. if err := models.DeleteIssueReaction(ctx.User, issue, form.Content); err != nil {
  1713. ctx.ServerError("DeleteIssueReaction", err)
  1714. return
  1715. }
  1716. // Reload new reactions
  1717. issue.Reactions = nil
  1718. if err := issue.LoadAttributes(); err != nil {
  1719. log.Info("issue.LoadAttributes: %s", err)
  1720. break
  1721. }
  1722. log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID)
  1723. default:
  1724. ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
  1725. return
  1726. }
  1727. if len(issue.Reactions) == 0 {
  1728. ctx.JSON(200, map[string]interface{}{
  1729. "empty": true,
  1730. "html": "",
  1731. })
  1732. return
  1733. }
  1734. html, err := ctx.HTMLString(string(tplReactions), map[string]interface{}{
  1735. "ctx": ctx.Data,
  1736. "ActionURL": fmt.Sprintf("%s/issues/%d/reactions", ctx.Repo.RepoLink, issue.Index),
  1737. "Reactions": issue.Reactions.GroupByType(),
  1738. })
  1739. if err != nil {
  1740. ctx.ServerError("ChangeIssueReaction.HTMLString", err)
  1741. return
  1742. }
  1743. ctx.JSON(200, map[string]interface{}{
  1744. "html": html,
  1745. })
  1746. }
  1747. // ChangeCommentReaction create a reaction for comment
  1748. func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {
  1749. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  1750. if err != nil {
  1751. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  1752. return
  1753. }
  1754. if err := comment.LoadIssue(); err != nil {
  1755. ctx.NotFoundOrServerError("LoadIssue", models.IsErrIssueNotExist, err)
  1756. return
  1757. }
  1758. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull)) {
  1759. if log.IsTrace() {
  1760. if ctx.IsSigned {
  1761. issueType := "issues"
  1762. if comment.Issue.IsPull {
  1763. issueType = "pulls"
  1764. }
  1765. log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
  1766. "User in Repo has Permissions: %-+v",
  1767. ctx.User,
  1768. log.NewColoredIDValue(comment.Issue.PosterID),
  1769. issueType,
  1770. ctx.Repo.Repository,
  1771. ctx.Repo.Permission)
  1772. } else {
  1773. log.Trace("Permission Denied: Not logged in")
  1774. }
  1775. }
  1776. ctx.Error(403)
  1777. return
  1778. } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
  1779. ctx.Error(204)
  1780. return
  1781. }
  1782. switch ctx.Params(":action") {
  1783. case "react":
  1784. reaction, err := models.CreateCommentReaction(ctx.User, comment.Issue, comment, form.Content)
  1785. if err != nil {
  1786. if models.IsErrForbiddenIssueReaction(err) {
  1787. ctx.ServerError("ChangeIssueReaction", err)
  1788. return
  1789. }
  1790. log.Info("CreateCommentReaction: %s", err)
  1791. break
  1792. }
  1793. // Reload new reactions
  1794. comment.Reactions = nil
  1795. if err = comment.LoadReactions(ctx.Repo.Repository); err != nil {
  1796. log.Info("comment.LoadReactions: %s", err)
  1797. break
  1798. }
  1799. log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID, reaction.ID)
  1800. case "unreact":
  1801. if err := models.DeleteCommentReaction(ctx.User, comment.Issue, comment, form.Content); err != nil {
  1802. ctx.ServerError("DeleteCommentReaction", err)
  1803. return
  1804. }
  1805. // Reload new reactions
  1806. comment.Reactions = nil
  1807. if err = comment.LoadReactions(ctx.Repo.Repository); err != nil {
  1808. log.Info("comment.LoadReactions: %s", err)
  1809. break
  1810. }
  1811. log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID)
  1812. default:
  1813. ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
  1814. return
  1815. }
  1816. if len(comment.Reactions) == 0 {
  1817. ctx.JSON(200, map[string]interface{}{
  1818. "empty": true,
  1819. "html": "",
  1820. })
  1821. return
  1822. }
  1823. html, err := ctx.HTMLString(string(tplReactions), map[string]interface{}{
  1824. "ctx": ctx.Data,
  1825. "ActionURL": fmt.Sprintf("%s/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
  1826. "Reactions": comment.Reactions.GroupByType(),
  1827. })
  1828. if err != nil {
  1829. ctx.ServerError("ChangeCommentReaction.HTMLString", err)
  1830. return
  1831. }
  1832. ctx.JSON(200, map[string]interface{}{
  1833. "html": html,
  1834. })
  1835. }
  1836. func addParticipant(poster *models.User, participants []*models.User) []*models.User {
  1837. for _, part := range participants {
  1838. if poster.ID == part.ID {
  1839. return participants
  1840. }
  1841. }
  1842. return append(participants, poster)
  1843. }
  1844. func filterXRefComments(ctx *context.Context, issue *models.Issue) error {
  1845. // Remove comments that the user has no permissions to see
  1846. for i := 0; i < len(issue.Comments); {
  1847. c := issue.Comments[i]
  1848. if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issue.RepoID && c.RefRepoID != 0 {
  1849. var err error
  1850. // Set RefRepo for description in template
  1851. c.RefRepo, err = models.GetRepositoryByID(c.RefRepoID)
  1852. if err != nil {
  1853. return err
  1854. }
  1855. perm, err := models.GetUserRepoPermission(c.RefRepo, ctx.User)
  1856. if err != nil {
  1857. return err
  1858. }
  1859. if !perm.CanReadIssuesOrPulls(c.RefIsPull) {
  1860. issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...)
  1861. continue
  1862. }
  1863. }
  1864. i++
  1865. }
  1866. return nil
  1867. }
  1868. // GetIssueAttachments returns attachments for the issue
  1869. func GetIssueAttachments(ctx *context.Context) {
  1870. issue := GetActionIssue(ctx)
  1871. var attachments = make([]*api.Attachment, len(issue.Attachments))
  1872. for i := 0; i < len(issue.Attachments); i++ {
  1873. attachments[i] = issue.Attachments[i].APIFormat()
  1874. }
  1875. ctx.JSON(200, attachments)
  1876. }
  1877. // GetCommentAttachments returns attachments for the comment
  1878. func GetCommentAttachments(ctx *context.Context) {
  1879. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  1880. if err != nil {
  1881. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  1882. return
  1883. }
  1884. var attachments = make([]*api.Attachment, 0)
  1885. if comment.Type == models.CommentTypeComment {
  1886. if err := comment.LoadAttachments(); err != nil {
  1887. ctx.ServerError("LoadAttachments", err)
  1888. return
  1889. }
  1890. for i := 0; i < len(comment.Attachments); i++ {
  1891. attachments = append(attachments, comment.Attachments[i].APIFormat())
  1892. }
  1893. }
  1894. ctx.JSON(200, attachments)
  1895. }
  1896. func updateAttachments(item interface{}, files []string) error {
  1897. var attachments []*models.Attachment
  1898. switch content := item.(type) {
  1899. case *models.Issue:
  1900. attachments = content.Attachments
  1901. case *models.Comment:
  1902. attachments = content.Attachments
  1903. default:
  1904. return fmt.Errorf("Unknown Type: %T", content)
  1905. }
  1906. for i := 0; i < len(attachments); i++ {
  1907. if util.IsStringInSlice(attachments[i].UUID, files) {
  1908. continue
  1909. }
  1910. if err := models.DeleteAttachment(attachments[i], true); err != nil {
  1911. return err
  1912. }
  1913. }
  1914. var err error
  1915. if len(files) > 0 {
  1916. switch content := item.(type) {
  1917. case *models.Issue:
  1918. err = content.UpdateAttachments(files)
  1919. case *models.Comment:
  1920. err = content.UpdateAttachments(files)
  1921. default:
  1922. return fmt.Errorf("Unknown Type: %T", content)
  1923. }
  1924. if err != nil {
  1925. return err
  1926. }
  1927. }
  1928. switch content := item.(type) {
  1929. case *models.Issue:
  1930. content.Attachments, err = models.GetAttachmentsByIssueID(content.ID)
  1931. case *models.Comment:
  1932. content.Attachments, err = models.GetAttachmentsByCommentID(content.ID)
  1933. default:
  1934. return fmt.Errorf("Unknown Type: %T", content)
  1935. }
  1936. return err
  1937. }
  1938. func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) string {
  1939. attachHTML, err := ctx.HTMLString(string(tplAttachment), map[string]interface{}{
  1940. "ctx": ctx.Data,
  1941. "Attachments": attachments,
  1942. })
  1943. if err != nil {
  1944. ctx.ServerError("attachmentsHTML.HTMLString", err)
  1945. return ""
  1946. }
  1947. return attachHTML
  1948. }