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

pull.go 26 kB

11 years ago
11 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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>
6 years ago
9 years ago
9 years ago
9 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>
6 years ago
9 years ago
9 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
8 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
11 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
6 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
6 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
6 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
6 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
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. // Copyright 2018 The Gitea Authors.
  2. // Copyright 2014 The Gogs Authors.
  3. // All rights reserved.
  4. // Use of this source code is governed by a MIT-style
  5. // license that can be found in the LICENSE file.
  6. package repo
  7. import (
  8. "container/list"
  9. "crypto/subtle"
  10. "fmt"
  11. "io"
  12. "path"
  13. "strings"
  14. "code.gitea.io/gitea/models"
  15. "code.gitea.io/gitea/modules/auth"
  16. "code.gitea.io/gitea/modules/base"
  17. "code.gitea.io/gitea/modules/context"
  18. "code.gitea.io/gitea/modules/git"
  19. "code.gitea.io/gitea/modules/log"
  20. "code.gitea.io/gitea/modules/notification"
  21. "code.gitea.io/gitea/modules/pull"
  22. "code.gitea.io/gitea/modules/setting"
  23. "code.gitea.io/gitea/modules/util"
  24. "code.gitea.io/gitea/services/gitdiff"
  25. "github.com/unknwon/com"
  26. )
  27. const (
  28. tplFork base.TplName = "repo/pulls/fork"
  29. tplCompareDiff base.TplName = "repo/diff/compare"
  30. tplPullCommits base.TplName = "repo/pulls/commits"
  31. tplPullFiles base.TplName = "repo/pulls/files"
  32. pullRequestTemplateKey = "PullRequestTemplate"
  33. )
  34. var (
  35. pullRequestTemplateCandidates = []string{
  36. "PULL_REQUEST_TEMPLATE.md",
  37. "pull_request_template.md",
  38. ".gitea/PULL_REQUEST_TEMPLATE.md",
  39. ".gitea/pull_request_template.md",
  40. ".github/PULL_REQUEST_TEMPLATE.md",
  41. ".github/pull_request_template.md",
  42. }
  43. )
  44. func getForkRepository(ctx *context.Context) *models.Repository {
  45. forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
  46. if err != nil {
  47. if models.IsErrRepoNotExist(err) {
  48. ctx.NotFound("GetRepositoryByID", nil)
  49. } else {
  50. ctx.ServerError("GetRepositoryByID", err)
  51. }
  52. return nil
  53. }
  54. perm, err := models.GetUserRepoPermission(forkRepo, ctx.User)
  55. if err != nil {
  56. ctx.ServerError("GetUserRepoPermission", err)
  57. return nil
  58. }
  59. if forkRepo.IsEmpty || !perm.CanRead(models.UnitTypeCode) {
  60. if log.IsTrace() {
  61. if forkRepo.IsEmpty {
  62. log.Trace("Empty fork repository %-v", forkRepo)
  63. } else {
  64. log.Trace("Permission Denied: User %-v cannot read %-v of forkRepo %-v\n"+
  65. "User in forkRepo has Permissions: %-+v",
  66. ctx.User,
  67. models.UnitTypeCode,
  68. ctx.Repo,
  69. perm)
  70. }
  71. }
  72. ctx.NotFound("getForkRepository", nil)
  73. return nil
  74. }
  75. ctx.Data["repo_name"] = forkRepo.Name
  76. ctx.Data["description"] = forkRepo.Description
  77. ctx.Data["IsPrivate"] = forkRepo.IsPrivate
  78. canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
  79. if err = forkRepo.GetOwner(); err != nil {
  80. ctx.ServerError("GetOwner", err)
  81. return nil
  82. }
  83. ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
  84. ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
  85. if err := ctx.User.GetOwnedOrganizations(); err != nil {
  86. ctx.ServerError("GetOwnedOrganizations", err)
  87. return nil
  88. }
  89. var orgs []*models.User
  90. for _, org := range ctx.User.OwnedOrgs {
  91. if forkRepo.OwnerID != org.ID && !org.HasForkedRepo(forkRepo.ID) {
  92. orgs = append(orgs, org)
  93. }
  94. }
  95. var traverseParentRepo = forkRepo
  96. for {
  97. if ctx.User.ID == traverseParentRepo.OwnerID {
  98. canForkToUser = false
  99. } else {
  100. for i, org := range orgs {
  101. if org.ID == traverseParentRepo.OwnerID {
  102. orgs = append(orgs[:i], orgs[i+1:]...)
  103. break
  104. }
  105. }
  106. }
  107. if !traverseParentRepo.IsFork {
  108. break
  109. }
  110. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  111. if err != nil {
  112. ctx.ServerError("GetRepositoryByID", err)
  113. return nil
  114. }
  115. }
  116. ctx.Data["CanForkToUser"] = canForkToUser
  117. ctx.Data["Orgs"] = orgs
  118. if canForkToUser {
  119. ctx.Data["ContextUser"] = ctx.User
  120. } else if len(orgs) > 0 {
  121. ctx.Data["ContextUser"] = orgs[0]
  122. }
  123. return forkRepo
  124. }
  125. // Fork render repository fork page
  126. func Fork(ctx *context.Context) {
  127. ctx.Data["Title"] = ctx.Tr("new_fork")
  128. getForkRepository(ctx)
  129. if ctx.Written() {
  130. return
  131. }
  132. ctx.HTML(200, tplFork)
  133. }
  134. // ForkPost response for forking a repository
  135. func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
  136. ctx.Data["Title"] = ctx.Tr("new_fork")
  137. ctxUser := checkContextUser(ctx, form.UID)
  138. if ctx.Written() {
  139. return
  140. }
  141. forkRepo := getForkRepository(ctx)
  142. if ctx.Written() {
  143. return
  144. }
  145. ctx.Data["ContextUser"] = ctxUser
  146. if ctx.HasError() {
  147. ctx.HTML(200, tplFork)
  148. return
  149. }
  150. var err error
  151. var traverseParentRepo = forkRepo
  152. for {
  153. if ctxUser.ID == traverseParentRepo.OwnerID {
  154. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  155. return
  156. }
  157. repo, has := models.HasForkedRepo(ctxUser.ID, traverseParentRepo.ID)
  158. if has {
  159. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  160. return
  161. }
  162. if !traverseParentRepo.IsFork {
  163. break
  164. }
  165. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  166. if err != nil {
  167. ctx.ServerError("GetRepositoryByID", err)
  168. return
  169. }
  170. }
  171. // Check ownership of organization.
  172. if ctxUser.IsOrganization() {
  173. isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
  174. if err != nil {
  175. ctx.ServerError("IsOwnedBy", err)
  176. return
  177. } else if !isOwner {
  178. ctx.Error(403)
  179. return
  180. }
  181. }
  182. repo, err := models.ForkRepository(ctx.User, ctxUser, forkRepo, form.RepoName, form.Description)
  183. if err != nil {
  184. ctx.Data["Err_RepoName"] = true
  185. switch {
  186. case models.IsErrRepoAlreadyExist(err):
  187. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  188. case models.IsErrNameReserved(err):
  189. ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
  190. case models.IsErrNamePatternNotAllowed(err):
  191. ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
  192. default:
  193. ctx.ServerError("ForkPost", err)
  194. }
  195. return
  196. }
  197. log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
  198. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  199. }
  200. func checkPullInfo(ctx *context.Context) *models.Issue {
  201. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  202. if err != nil {
  203. if models.IsErrIssueNotExist(err) {
  204. ctx.NotFound("GetIssueByIndex", err)
  205. } else {
  206. ctx.ServerError("GetIssueByIndex", err)
  207. }
  208. return nil
  209. }
  210. if err = issue.LoadPoster(); err != nil {
  211. ctx.ServerError("LoadPoster", err)
  212. return nil
  213. }
  214. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  215. ctx.Data["Issue"] = issue
  216. if !issue.IsPull {
  217. ctx.NotFound("ViewPullCommits", nil)
  218. return nil
  219. }
  220. if err = issue.LoadPullRequest(); err != nil {
  221. ctx.ServerError("LoadPullRequest", err)
  222. return nil
  223. }
  224. if err = issue.PullRequest.GetHeadRepo(); err != nil {
  225. ctx.ServerError("GetHeadRepo", err)
  226. return nil
  227. }
  228. if ctx.IsSigned {
  229. // Update issue-user.
  230. if err = issue.ReadBy(ctx.User.ID); err != nil {
  231. ctx.ServerError("ReadBy", err)
  232. return nil
  233. }
  234. }
  235. return issue
  236. }
  237. func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
  238. if ctx.Repo.Owner.Name == pull.HeadUserName {
  239. ctx.Data["HeadTarget"] = pull.HeadBranch
  240. } else if pull.HeadRepo == nil {
  241. ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch
  242. } else {
  243. ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
  244. }
  245. ctx.Data["BaseTarget"] = pull.BaseBranch
  246. }
  247. // PrepareMergedViewPullInfo show meta information for a merged pull request view page
  248. func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  249. pull := issue.PullRequest
  250. setMergeTarget(ctx, pull)
  251. ctx.Data["HasMerged"] = true
  252. compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
  253. pull.MergeBase, pull.GetGitRefName())
  254. if err != nil {
  255. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  256. ctx.Data["IsPullRequestBroken"] = true
  257. ctx.Data["BaseTarget"] = "deleted"
  258. ctx.Data["NumCommits"] = 0
  259. ctx.Data["NumFiles"] = 0
  260. return nil
  261. }
  262. ctx.ServerError("GetCompareInfo", err)
  263. return nil
  264. }
  265. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  266. ctx.Data["NumFiles"] = compareInfo.NumFiles
  267. return compareInfo
  268. }
  269. // PrepareViewPullInfo show meta information for a pull request preview page
  270. func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  271. repo := ctx.Repo.Repository
  272. pull := issue.PullRequest
  273. var err error
  274. if err = pull.GetHeadRepo(); err != nil {
  275. ctx.ServerError("GetHeadRepo", err)
  276. return nil
  277. }
  278. setMergeTarget(ctx, pull)
  279. var headGitRepo *git.Repository
  280. var headBranchExist bool
  281. // HeadRepo may be missing
  282. if pull.HeadRepo != nil {
  283. headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath())
  284. if err != nil {
  285. ctx.ServerError("OpenRepository", err)
  286. return nil
  287. }
  288. headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)
  289. if headBranchExist {
  290. sha, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
  291. if err != nil {
  292. ctx.ServerError("GetBranchCommitID", err)
  293. return nil
  294. }
  295. commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0)
  296. if err != nil {
  297. ctx.ServerError("GetLatestCommitStatus", err)
  298. return nil
  299. }
  300. if len(commitStatuses) > 0 {
  301. ctx.Data["LatestCommitStatuses"] = commitStatuses
  302. ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
  303. }
  304. }
  305. }
  306. if pull.HeadRepo == nil || !headBranchExist {
  307. ctx.Data["IsPullRequestBroken"] = true
  308. ctx.Data["HeadTarget"] = "deleted"
  309. ctx.Data["NumCommits"] = 0
  310. ctx.Data["NumFiles"] = 0
  311. return nil
  312. }
  313. compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
  314. pull.BaseBranch, pull.HeadBranch)
  315. if err != nil {
  316. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  317. ctx.Data["IsPullRequestBroken"] = true
  318. ctx.Data["BaseTarget"] = "deleted"
  319. ctx.Data["NumCommits"] = 0
  320. ctx.Data["NumFiles"] = 0
  321. return nil
  322. }
  323. ctx.ServerError("GetCompareInfo", err)
  324. return nil
  325. }
  326. if pull.IsWorkInProgress() {
  327. ctx.Data["IsPullWorkInProgress"] = true
  328. ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()
  329. }
  330. if pull.IsFilesConflicted() {
  331. ctx.Data["IsPullFilesConflicted"] = true
  332. ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
  333. }
  334. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  335. ctx.Data["NumFiles"] = compareInfo.NumFiles
  336. return compareInfo
  337. }
  338. // ViewPullCommits show commits for a pull request
  339. func ViewPullCommits(ctx *context.Context) {
  340. ctx.Data["PageIsPullList"] = true
  341. ctx.Data["PageIsPullCommits"] = true
  342. issue := checkPullInfo(ctx)
  343. if ctx.Written() {
  344. return
  345. }
  346. pull := issue.PullRequest
  347. var commits *list.List
  348. if pull.HasMerged {
  349. prInfo := PrepareMergedViewPullInfo(ctx, issue)
  350. if ctx.Written() {
  351. return
  352. } else if prInfo == nil {
  353. ctx.NotFound("ViewPullCommits", nil)
  354. return
  355. }
  356. ctx.Data["Username"] = ctx.Repo.Owner.Name
  357. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  358. commits = prInfo.Commits
  359. } else {
  360. prInfo := PrepareViewPullInfo(ctx, issue)
  361. if ctx.Written() {
  362. return
  363. } else if prInfo == nil {
  364. ctx.NotFound("ViewPullCommits", nil)
  365. return
  366. }
  367. ctx.Data["Username"] = pull.HeadUserName
  368. ctx.Data["Reponame"] = pull.HeadRepo.Name
  369. commits = prInfo.Commits
  370. }
  371. commits = models.ValidateCommitsWithEmails(commits)
  372. commits = models.ParseCommitsWithSignature(commits)
  373. commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
  374. ctx.Data["Commits"] = commits
  375. ctx.Data["CommitCount"] = commits.Len()
  376. ctx.HTML(200, tplPullCommits)
  377. }
  378. // ViewPullFiles render pull request changed files list page
  379. func ViewPullFiles(ctx *context.Context) {
  380. ctx.Data["PageIsPullList"] = true
  381. ctx.Data["PageIsPullFiles"] = true
  382. issue := checkPullInfo(ctx)
  383. if ctx.Written() {
  384. return
  385. }
  386. pull := issue.PullRequest
  387. whitespaceFlags := map[string]string{
  388. "ignore-all": "-w",
  389. "ignore-change": "-b",
  390. "ignore-eol": "--ignore-space-at-eol",
  391. "": ""}
  392. var (
  393. diffRepoPath string
  394. startCommitID string
  395. endCommitID string
  396. gitRepo *git.Repository
  397. )
  398. var headTarget string
  399. if pull.HasMerged {
  400. prInfo := PrepareMergedViewPullInfo(ctx, issue)
  401. if ctx.Written() {
  402. return
  403. } else if prInfo == nil {
  404. ctx.NotFound("ViewPullFiles", nil)
  405. return
  406. }
  407. diffRepoPath = ctx.Repo.GitRepo.Path
  408. gitRepo = ctx.Repo.GitRepo
  409. headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
  410. if err != nil {
  411. ctx.ServerError("GetRefCommitID", err)
  412. return
  413. }
  414. startCommitID = prInfo.MergeBase
  415. endCommitID = headCommitID
  416. headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
  417. ctx.Data["Username"] = ctx.Repo.Owner.Name
  418. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  419. } else {
  420. prInfo := PrepareViewPullInfo(ctx, issue)
  421. if ctx.Written() {
  422. return
  423. } else if prInfo == nil {
  424. ctx.NotFound("ViewPullFiles", nil)
  425. return
  426. }
  427. headRepoPath := models.RepoPath(pull.HeadUserName, pull.HeadRepo.Name)
  428. headGitRepo, err := git.OpenRepository(headRepoPath)
  429. if err != nil {
  430. ctx.ServerError("OpenRepository", err)
  431. return
  432. }
  433. headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
  434. if err != nil {
  435. ctx.ServerError("GetBranchCommitID", err)
  436. return
  437. }
  438. diffRepoPath = headRepoPath
  439. startCommitID = prInfo.MergeBase
  440. endCommitID = headCommitID
  441. gitRepo = headGitRepo
  442. headTarget = path.Join(pull.HeadUserName, pull.HeadRepo.Name)
  443. ctx.Data["Username"] = pull.HeadUserName
  444. ctx.Data["Reponame"] = pull.HeadRepo.Name
  445. }
  446. diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,
  447. startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
  448. setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
  449. whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
  450. if err != nil {
  451. ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
  452. return
  453. }
  454. if err = diff.LoadComments(issue, ctx.User); err != nil {
  455. ctx.ServerError("LoadComments", err)
  456. return
  457. }
  458. ctx.Data["Diff"] = diff
  459. ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
  460. commit, err := gitRepo.GetCommit(endCommitID)
  461. if err != nil {
  462. ctx.ServerError("GetCommit", err)
  463. return
  464. }
  465. ctx.Data["IsImageFile"] = commit.IsImageFile
  466. ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", endCommitID)
  467. ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", startCommitID)
  468. ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(headTarget, "raw", "commit", endCommitID)
  469. ctx.Data["RequireHighlightJS"] = true
  470. ctx.Data["RequireTribute"] = true
  471. if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil {
  472. ctx.ServerError("GetAssignees", err)
  473. return
  474. }
  475. ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.User, issue)
  476. if err != nil && !models.IsErrReviewNotExist(err) {
  477. ctx.ServerError("GetCurrentReview", err)
  478. return
  479. }
  480. ctx.HTML(200, tplPullFiles)
  481. }
  482. // MergePullRequest response for merging pull request
  483. func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
  484. issue := checkPullInfo(ctx)
  485. if ctx.Written() {
  486. return
  487. }
  488. if issue.IsClosed {
  489. ctx.NotFound("MergePullRequest", nil)
  490. return
  491. }
  492. pr := issue.PullRequest
  493. if !pr.CanAutoMerge() || pr.HasMerged {
  494. ctx.NotFound("MergePullRequest", nil)
  495. return
  496. }
  497. if pr.IsWorkInProgress() {
  498. ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_wip"))
  499. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  500. return
  501. }
  502. if ctx.HasError() {
  503. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  504. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  505. return
  506. }
  507. message := strings.TrimSpace(form.MergeTitleField)
  508. if len(message) == 0 {
  509. if models.MergeStyle(form.Do) == models.MergeStyleMerge {
  510. message = pr.GetDefaultMergeMessage()
  511. }
  512. if models.MergeStyle(form.Do) == models.MergeStyleRebaseMerge {
  513. message = pr.GetDefaultMergeMessage()
  514. }
  515. if models.MergeStyle(form.Do) == models.MergeStyleSquash {
  516. message = pr.GetDefaultSquashMessage()
  517. }
  518. }
  519. form.MergeMessageField = strings.TrimSpace(form.MergeMessageField)
  520. if len(form.MergeMessageField) > 0 {
  521. message += "\n\n" + form.MergeMessageField
  522. }
  523. pr.Issue = issue
  524. pr.Issue.Repo = ctx.Repo.Repository
  525. noDeps, err := models.IssueNoDependenciesLeft(issue)
  526. if err != nil {
  527. return
  528. }
  529. if !noDeps {
  530. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
  531. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  532. return
  533. }
  534. if err = pull.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
  535. if models.IsErrInvalidMergeStyle(err) {
  536. ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
  537. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  538. return
  539. }
  540. ctx.ServerError("Merge", err)
  541. return
  542. }
  543. if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
  544. ctx.ServerError("CreateOrStopIssueStopwatch", err)
  545. return
  546. }
  547. notification.NotifyMergePullRequest(pr, ctx.User, ctx.Repo.GitRepo)
  548. log.Trace("Pull request merged: %d", pr.ID)
  549. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  550. }
  551. func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
  552. if models.StopwatchExists(user.ID, issue.ID) {
  553. if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
  554. return err
  555. }
  556. }
  557. return nil
  558. }
  559. // CompareAndPullRequestPost response for creating pull request
  560. func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) {
  561. ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
  562. ctx.Data["PageIsComparePull"] = true
  563. ctx.Data["IsDiffCompare"] = true
  564. ctx.Data["RequireHighlightJS"] = true
  565. ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
  566. renderAttachmentSettings(ctx)
  567. var (
  568. repo = ctx.Repo.Repository
  569. attachments []string
  570. )
  571. headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
  572. if ctx.Written() {
  573. return
  574. }
  575. labelIDs, assigneeIDs, milestoneID := ValidateRepoMetas(ctx, form, true)
  576. if ctx.Written() {
  577. return
  578. }
  579. if setting.AttachmentEnabled {
  580. attachments = form.Files
  581. }
  582. if ctx.HasError() {
  583. auth.AssignForm(form, ctx.Data)
  584. // This stage is already stop creating new pull request, so it does not matter if it has
  585. // something to compare or not.
  586. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  587. if ctx.Written() {
  588. return
  589. }
  590. ctx.HTML(200, tplCompareDiff)
  591. return
  592. }
  593. if util.IsEmptyString(form.Title) {
  594. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  595. if ctx.Written() {
  596. return
  597. }
  598. ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplCompareDiff, form)
  599. return
  600. }
  601. patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch)
  602. if err != nil {
  603. ctx.ServerError("GetPatch", err)
  604. return
  605. }
  606. pullIssue := &models.Issue{
  607. RepoID: repo.ID,
  608. Title: form.Title,
  609. PosterID: ctx.User.ID,
  610. Poster: ctx.User,
  611. MilestoneID: milestoneID,
  612. IsPull: true,
  613. Content: form.Content,
  614. }
  615. pullRequest := &models.PullRequest{
  616. HeadRepoID: headRepo.ID,
  617. BaseRepoID: repo.ID,
  618. HeadUserName: headUser.Name,
  619. HeadBranch: headBranch,
  620. BaseBranch: baseBranch,
  621. HeadRepo: headRepo,
  622. BaseRepo: repo,
  623. MergeBase: prInfo.MergeBase,
  624. Type: models.PullRequestGitea,
  625. }
  626. // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
  627. // instead of 500.
  628. if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch, assigneeIDs); err != nil {
  629. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  630. ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
  631. return
  632. }
  633. ctx.ServerError("NewPullRequest", err)
  634. return
  635. } else if err := pullRequest.PushToBaseRepo(); err != nil {
  636. ctx.ServerError("PushToBaseRepo", err)
  637. return
  638. }
  639. notification.NotifyNewPullRequest(pullRequest)
  640. log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
  641. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
  642. }
  643. // TriggerTask response for a trigger task request
  644. func TriggerTask(ctx *context.Context) {
  645. pusherID := ctx.QueryInt64("pusher")
  646. branch := ctx.Query("branch")
  647. secret := ctx.Query("secret")
  648. if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 {
  649. ctx.Error(404)
  650. log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid")
  651. return
  652. }
  653. owner, repo := parseOwnerAndRepo(ctx)
  654. if ctx.Written() {
  655. return
  656. }
  657. got := []byte(base.EncodeMD5(owner.Salt))
  658. want := []byte(secret)
  659. if subtle.ConstantTimeCompare(got, want) != 1 {
  660. ctx.Error(404)
  661. log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
  662. return
  663. }
  664. pusher, err := models.GetUserByID(pusherID)
  665. if err != nil {
  666. if models.IsErrUserNotExist(err) {
  667. ctx.Error(404)
  668. } else {
  669. ctx.ServerError("GetUserByID", err)
  670. }
  671. return
  672. }
  673. log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
  674. go models.HookQueue.Add(repo.ID)
  675. go models.AddTestPullRequestTask(pusher, repo.ID, branch, true)
  676. ctx.Status(202)
  677. }
  678. // CleanUpPullRequest responses for delete merged branch when PR has been merged
  679. func CleanUpPullRequest(ctx *context.Context) {
  680. issue := checkPullInfo(ctx)
  681. if ctx.Written() {
  682. return
  683. }
  684. pr := issue.PullRequest
  685. // Don't cleanup unmerged and unclosed PRs
  686. if !pr.HasMerged && !issue.IsClosed {
  687. ctx.NotFound("CleanUpPullRequest", nil)
  688. return
  689. }
  690. if err := pr.GetHeadRepo(); err != nil {
  691. ctx.ServerError("GetHeadRepo", err)
  692. return
  693. } else if pr.HeadRepo == nil {
  694. // Forked repository has already been deleted
  695. ctx.NotFound("CleanUpPullRequest", nil)
  696. return
  697. } else if err = pr.GetBaseRepo(); err != nil {
  698. ctx.ServerError("GetBaseRepo", err)
  699. return
  700. } else if err = pr.HeadRepo.GetOwner(); err != nil {
  701. ctx.ServerError("HeadRepo.GetOwner", err)
  702. return
  703. }
  704. perm, err := models.GetUserRepoPermission(pr.HeadRepo, ctx.User)
  705. if err != nil {
  706. ctx.ServerError("GetUserRepoPermission", err)
  707. return
  708. }
  709. if !perm.CanWrite(models.UnitTypeCode) {
  710. ctx.NotFound("CleanUpPullRequest", nil)
  711. return
  712. }
  713. fullBranchName := pr.HeadRepo.Owner.Name + "/" + pr.HeadBranch
  714. gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  715. if err != nil {
  716. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
  717. return
  718. }
  719. gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
  720. if err != nil {
  721. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
  722. return
  723. }
  724. defer func() {
  725. ctx.JSON(200, map[string]interface{}{
  726. "redirect": pr.BaseRepo.Link() + "/pulls/" + com.ToStr(issue.Index),
  727. })
  728. }()
  729. if pr.HeadBranch == pr.HeadRepo.DefaultBranch || !gitRepo.IsBranchExist(pr.HeadBranch) {
  730. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  731. return
  732. }
  733. // Check if branch is not protected
  734. if protected, err := pr.HeadRepo.IsProtectedBranch(pr.HeadBranch, ctx.User); err != nil || protected {
  735. if err != nil {
  736. log.Error("HeadRepo.IsProtectedBranch: %v", err)
  737. }
  738. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  739. return
  740. }
  741. // Check if branch has no new commits
  742. headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
  743. if err != nil {
  744. log.Error("GetRefCommitID: %v", err)
  745. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  746. return
  747. }
  748. branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
  749. if err != nil {
  750. log.Error("GetBranchCommitID: %v", err)
  751. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  752. return
  753. }
  754. if headCommitID != branchCommitID {
  755. ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName))
  756. return
  757. }
  758. if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
  759. Force: true,
  760. }); err != nil {
  761. log.Error("DeleteBranch: %v", err)
  762. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  763. return
  764. }
  765. if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, issue.ID, pr.HeadBranch); err != nil {
  766. // Do not fail here as branch has already been deleted
  767. log.Error("DeleteBranch: %v", err)
  768. }
  769. ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))
  770. }
  771. // DownloadPullDiff render a pull's raw diff
  772. func DownloadPullDiff(ctx *context.Context) {
  773. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  774. if err != nil {
  775. if models.IsErrIssueNotExist(err) {
  776. ctx.NotFound("GetIssueByIndex", err)
  777. } else {
  778. ctx.ServerError("GetIssueByIndex", err)
  779. }
  780. return
  781. }
  782. // Return not found if it's not a pull request
  783. if !issue.IsPull {
  784. ctx.NotFound("DownloadPullDiff",
  785. fmt.Errorf("Issue is not a pull request"))
  786. return
  787. }
  788. if err = issue.LoadPullRequest(); err != nil {
  789. ctx.ServerError("LoadPullRequest", err)
  790. return
  791. }
  792. pr := issue.PullRequest
  793. if err = pr.GetBaseRepo(); err != nil {
  794. ctx.ServerError("GetBaseRepo", err)
  795. return
  796. }
  797. patch, err := pr.BaseRepo.PatchPath(pr.Index)
  798. if err != nil {
  799. ctx.ServerError("PatchPath", err)
  800. return
  801. }
  802. ctx.ServeFileContent(patch)
  803. }
  804. // DownloadPullPatch render a pull's raw patch
  805. func DownloadPullPatch(ctx *context.Context) {
  806. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  807. if err != nil {
  808. if models.IsErrIssueNotExist(err) {
  809. ctx.NotFound("GetIssueByIndex", err)
  810. } else {
  811. ctx.ServerError("GetIssueByIndex", err)
  812. }
  813. return
  814. }
  815. // Return not found if it's not a pull request
  816. if !issue.IsPull {
  817. ctx.NotFound("DownloadPullDiff",
  818. fmt.Errorf("Issue is not a pull request"))
  819. return
  820. }
  821. if err = issue.LoadPullRequest(); err != nil {
  822. ctx.ServerError("LoadPullRequest", err)
  823. return
  824. }
  825. pr := issue.PullRequest
  826. if err = pr.GetHeadRepo(); err != nil {
  827. ctx.ServerError("GetHeadRepo", err)
  828. return
  829. }
  830. headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  831. if err != nil {
  832. ctx.ServerError("OpenRepository", err)
  833. return
  834. }
  835. patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch)
  836. if err != nil {
  837. ctx.ServerError("GetFormatPatch", err)
  838. return
  839. }
  840. _, err = io.Copy(ctx, patch)
  841. if err != nil {
  842. ctx.ServerError("io.Copy", err)
  843. return
  844. }
  845. }