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