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