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