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 29 kB

11 years ago
11 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
9 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
9 years ago
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>
5 years ago
9 years ago
9 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>
5 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
9 years ago
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
11 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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. "html"
  12. "io"
  13. "path"
  14. "strings"
  15. "code.gitea.io/gitea/models"
  16. "code.gitea.io/gitea/modules/auth"
  17. "code.gitea.io/gitea/modules/base"
  18. "code.gitea.io/gitea/modules/context"
  19. "code.gitea.io/gitea/modules/git"
  20. "code.gitea.io/gitea/modules/log"
  21. "code.gitea.io/gitea/modules/notification"
  22. "code.gitea.io/gitea/modules/setting"
  23. "code.gitea.io/gitea/modules/util"
  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 getRepository(ctx *context.Context, repoID int64) *models.Repository {
  47. repo, err := models.GetRepositoryByID(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(repo, ctx.User)
  57. if err != nil {
  58. ctx.ServerError("GetUserRepoPermission", err)
  59. return nil
  60. }
  61. if !perm.CanRead(models.UnitTypeCode) {
  62. log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
  63. "User in repo has Permissions: %-+v",
  64. ctx.User,
  65. models.UnitTypeCode,
  66. ctx.Repo,
  67. perm)
  68. ctx.NotFound("getRepository", nil)
  69. return nil
  70. }
  71. return repo
  72. }
  73. func getForkRepository(ctx *context.Context) *models.Repository {
  74. forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid"))
  75. if ctx.Written() {
  76. return nil
  77. }
  78. if forkRepo.IsEmpty {
  79. log.Trace("Empty repository %-v", forkRepo)
  80. ctx.NotFound("getForkRepository", nil)
  81. return nil
  82. }
  83. ctx.Data["repo_name"] = forkRepo.Name
  84. ctx.Data["description"] = forkRepo.Description
  85. ctx.Data["IsPrivate"] = forkRepo.IsPrivate
  86. canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
  87. if err := forkRepo.GetOwner(); err != nil {
  88. ctx.ServerError("GetOwner", err)
  89. return nil
  90. }
  91. ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
  92. ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
  93. if err := ctx.User.GetOwnedOrganizations(); err != nil {
  94. ctx.ServerError("GetOwnedOrganizations", err)
  95. return nil
  96. }
  97. var orgs []*models.User
  98. for _, org := range ctx.User.OwnedOrgs {
  99. if forkRepo.OwnerID != org.ID && !org.HasForkedRepo(forkRepo.ID) {
  100. orgs = append(orgs, org)
  101. }
  102. }
  103. var traverseParentRepo = forkRepo
  104. var err error
  105. for {
  106. if ctx.User.ID == traverseParentRepo.OwnerID {
  107. canForkToUser = false
  108. } else {
  109. for i, org := range orgs {
  110. if org.ID == traverseParentRepo.OwnerID {
  111. orgs = append(orgs[:i], orgs[i+1:]...)
  112. break
  113. }
  114. }
  115. }
  116. if !traverseParentRepo.IsFork {
  117. break
  118. }
  119. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  120. if err != nil {
  121. ctx.ServerError("GetRepositoryByID", err)
  122. return nil
  123. }
  124. }
  125. ctx.Data["CanForkToUser"] = canForkToUser
  126. ctx.Data["Orgs"] = orgs
  127. if canForkToUser {
  128. ctx.Data["ContextUser"] = ctx.User
  129. } else if len(orgs) > 0 {
  130. ctx.Data["ContextUser"] = orgs[0]
  131. }
  132. return forkRepo
  133. }
  134. // Fork render repository fork page
  135. func Fork(ctx *context.Context) {
  136. ctx.Data["Title"] = ctx.Tr("new_fork")
  137. getForkRepository(ctx)
  138. if ctx.Written() {
  139. return
  140. }
  141. ctx.HTML(200, tplFork)
  142. }
  143. // ForkPost response for forking a repository
  144. func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
  145. ctx.Data["Title"] = ctx.Tr("new_fork")
  146. ctxUser := checkContextUser(ctx, form.UID)
  147. if ctx.Written() {
  148. return
  149. }
  150. forkRepo := getForkRepository(ctx)
  151. if ctx.Written() {
  152. return
  153. }
  154. ctx.Data["ContextUser"] = ctxUser
  155. if ctx.HasError() {
  156. ctx.HTML(200, tplFork)
  157. return
  158. }
  159. var err error
  160. var traverseParentRepo = forkRepo
  161. for {
  162. if ctxUser.ID == traverseParentRepo.OwnerID {
  163. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  164. return
  165. }
  166. repo, has := models.HasForkedRepo(ctxUser.ID, traverseParentRepo.ID)
  167. if has {
  168. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  169. return
  170. }
  171. if !traverseParentRepo.IsFork {
  172. break
  173. }
  174. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  175. if err != nil {
  176. ctx.ServerError("GetRepositoryByID", err)
  177. return
  178. }
  179. }
  180. // Check ownership of organization.
  181. if ctxUser.IsOrganization() {
  182. isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
  183. if err != nil {
  184. ctx.ServerError("IsOwnedBy", err)
  185. return
  186. } else if !isOwner {
  187. ctx.Error(403)
  188. return
  189. }
  190. }
  191. repo, err := repo_service.ForkRepository(ctx.User, ctxUser, forkRepo, form.RepoName, form.Description)
  192. if err != nil {
  193. ctx.Data["Err_RepoName"] = true
  194. switch {
  195. case models.IsErrRepoAlreadyExist(err):
  196. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  197. case models.IsErrNameReserved(err):
  198. ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
  199. case models.IsErrNamePatternNotAllowed(err):
  200. ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
  201. default:
  202. ctx.ServerError("ForkPost", err)
  203. }
  204. return
  205. }
  206. log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
  207. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  208. }
  209. func checkPullInfo(ctx *context.Context) *models.Issue {
  210. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  211. if err != nil {
  212. if models.IsErrIssueNotExist(err) {
  213. ctx.NotFound("GetIssueByIndex", err)
  214. } else {
  215. ctx.ServerError("GetIssueByIndex", err)
  216. }
  217. return nil
  218. }
  219. if err = issue.LoadPoster(); err != nil {
  220. ctx.ServerError("LoadPoster", err)
  221. return nil
  222. }
  223. if err := issue.LoadRepo(); err != nil {
  224. ctx.ServerError("LoadRepo", err)
  225. return nil
  226. }
  227. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  228. ctx.Data["Issue"] = issue
  229. if !issue.IsPull {
  230. ctx.NotFound("ViewPullCommits", nil)
  231. return nil
  232. }
  233. if err = issue.LoadPullRequest(); err != nil {
  234. ctx.ServerError("LoadPullRequest", err)
  235. return nil
  236. }
  237. if err = issue.PullRequest.GetHeadRepo(); err != nil {
  238. ctx.ServerError("GetHeadRepo", err)
  239. return nil
  240. }
  241. if ctx.IsSigned {
  242. // Update issue-user.
  243. if err = issue.ReadBy(ctx.User.ID); err != nil {
  244. ctx.ServerError("ReadBy", err)
  245. return nil
  246. }
  247. }
  248. return issue
  249. }
  250. func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
  251. if ctx.Repo.Owner.Name == pull.MustHeadUserName() {
  252. ctx.Data["HeadTarget"] = pull.HeadBranch
  253. } else if pull.HeadRepo == nil {
  254. ctx.Data["HeadTarget"] = pull.MustHeadUserName() + ":" + pull.HeadBranch
  255. } else {
  256. ctx.Data["HeadTarget"] = pull.MustHeadUserName() + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
  257. }
  258. ctx.Data["BaseTarget"] = pull.BaseBranch
  259. }
  260. // PrepareMergedViewPullInfo show meta information for a merged pull request view page
  261. func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  262. pull := issue.PullRequest
  263. setMergeTarget(ctx, pull)
  264. ctx.Data["HasMerged"] = true
  265. compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
  266. pull.MergeBase, pull.GetGitRefName())
  267. if err != nil {
  268. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  269. ctx.Data["IsPullRequestBroken"] = true
  270. ctx.Data["BaseTarget"] = "deleted"
  271. ctx.Data["NumCommits"] = 0
  272. ctx.Data["NumFiles"] = 0
  273. return nil
  274. }
  275. ctx.ServerError("GetCompareInfo", err)
  276. return nil
  277. }
  278. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  279. ctx.Data["NumFiles"] = compareInfo.NumFiles
  280. return compareInfo
  281. }
  282. // PrepareViewPullInfo show meta information for a pull request preview page
  283. func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  284. repo := ctx.Repo.Repository
  285. pull := issue.PullRequest
  286. var err error
  287. if err = pull.GetHeadRepo(); err != nil {
  288. ctx.ServerError("GetHeadRepo", err)
  289. return nil
  290. }
  291. setMergeTarget(ctx, pull)
  292. if err = pull.LoadProtectedBranch(); err != nil {
  293. ctx.ServerError("GetLatestCommitStatus", err)
  294. return nil
  295. }
  296. ctx.Data["EnableStatusCheck"] = pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck
  297. var headGitRepo *git.Repository
  298. var headBranchExist bool
  299. // HeadRepo may be missing
  300. if pull.HeadRepo != nil {
  301. headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath())
  302. if err != nil {
  303. ctx.ServerError("OpenRepository", err)
  304. return nil
  305. }
  306. defer headGitRepo.Close()
  307. headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)
  308. if headBranchExist {
  309. sha, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
  310. if err != nil {
  311. ctx.ServerError("GetBranchCommitID", err)
  312. return nil
  313. }
  314. commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0)
  315. if err != nil {
  316. ctx.ServerError("GetLatestCommitStatus", err)
  317. return nil
  318. }
  319. if len(commitStatuses) > 0 {
  320. ctx.Data["LatestCommitStatuses"] = commitStatuses
  321. ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
  322. }
  323. if pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck {
  324. ctx.Data["is_context_required"] = func(context string) bool {
  325. for _, c := range pull.ProtectedBranch.StatusCheckContexts {
  326. if c == context {
  327. return true
  328. }
  329. }
  330. return false
  331. }
  332. ctx.Data["IsRequiredStatusCheckSuccess"] = pull_service.IsCommitStatusContextSuccess(commitStatuses, pull.ProtectedBranch.StatusCheckContexts)
  333. }
  334. }
  335. }
  336. if pull.HeadRepo == nil || !headBranchExist {
  337. ctx.Data["IsPullRequestBroken"] = true
  338. ctx.Data["HeadTarget"] = "deleted"
  339. ctx.Data["NumCommits"] = 0
  340. ctx.Data["NumFiles"] = 0
  341. return nil
  342. }
  343. compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
  344. pull.BaseBranch, pull.HeadBranch)
  345. if err != nil {
  346. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  347. ctx.Data["IsPullRequestBroken"] = true
  348. ctx.Data["BaseTarget"] = "deleted"
  349. ctx.Data["NumCommits"] = 0
  350. ctx.Data["NumFiles"] = 0
  351. return nil
  352. }
  353. ctx.ServerError("GetCompareInfo", err)
  354. return nil
  355. }
  356. if pull.IsWorkInProgress() {
  357. ctx.Data["IsPullWorkInProgress"] = true
  358. ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()
  359. }
  360. if pull.IsFilesConflicted() {
  361. ctx.Data["IsPullFilesConflicted"] = true
  362. ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
  363. }
  364. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  365. ctx.Data["NumFiles"] = compareInfo.NumFiles
  366. return compareInfo
  367. }
  368. // ViewPullCommits show commits for a pull request
  369. func ViewPullCommits(ctx *context.Context) {
  370. ctx.Data["PageIsPullList"] = true
  371. ctx.Data["PageIsPullCommits"] = true
  372. issue := checkPullInfo(ctx)
  373. if ctx.Written() {
  374. return
  375. }
  376. pull := issue.PullRequest
  377. var commits *list.List
  378. if pull.HasMerged {
  379. prInfo := PrepareMergedViewPullInfo(ctx, issue)
  380. if ctx.Written() {
  381. return
  382. } else if prInfo == nil {
  383. ctx.NotFound("ViewPullCommits", nil)
  384. return
  385. }
  386. ctx.Data["Username"] = ctx.Repo.Owner.Name
  387. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  388. commits = prInfo.Commits
  389. } else {
  390. prInfo := PrepareViewPullInfo(ctx, issue)
  391. if ctx.Written() {
  392. return
  393. } else if prInfo == nil {
  394. ctx.NotFound("ViewPullCommits", nil)
  395. return
  396. }
  397. ctx.Data["Username"] = pull.MustHeadUserName()
  398. ctx.Data["Reponame"] = pull.HeadRepo.Name
  399. commits = prInfo.Commits
  400. }
  401. commits = models.ValidateCommitsWithEmails(commits)
  402. commits = models.ParseCommitsWithSignature(commits)
  403. commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
  404. ctx.Data["Commits"] = commits
  405. ctx.Data["CommitCount"] = commits.Len()
  406. ctx.HTML(200, tplPullCommits)
  407. }
  408. // ViewPullFiles render pull request changed files list page
  409. func ViewPullFiles(ctx *context.Context) {
  410. ctx.Data["PageIsPullList"] = true
  411. ctx.Data["PageIsPullFiles"] = true
  412. issue := checkPullInfo(ctx)
  413. if ctx.Written() {
  414. return
  415. }
  416. pull := issue.PullRequest
  417. whitespaceFlags := map[string]string{
  418. "ignore-all": "-w",
  419. "ignore-change": "-b",
  420. "ignore-eol": "--ignore-space-at-eol",
  421. "": ""}
  422. var (
  423. diffRepoPath string
  424. startCommitID string
  425. endCommitID string
  426. gitRepo *git.Repository
  427. )
  428. var headTarget string
  429. if pull.HasMerged {
  430. prInfo := PrepareMergedViewPullInfo(ctx, issue)
  431. if ctx.Written() {
  432. return
  433. } else if prInfo == nil {
  434. ctx.NotFound("ViewPullFiles", nil)
  435. return
  436. }
  437. diffRepoPath = ctx.Repo.GitRepo.Path
  438. gitRepo = ctx.Repo.GitRepo
  439. headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
  440. if err != nil {
  441. ctx.ServerError("GetRefCommitID", err)
  442. return
  443. }
  444. startCommitID = prInfo.MergeBase
  445. endCommitID = headCommitID
  446. headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
  447. ctx.Data["Username"] = ctx.Repo.Owner.Name
  448. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  449. } else {
  450. prInfo := PrepareViewPullInfo(ctx, issue)
  451. if ctx.Written() {
  452. return
  453. } else if prInfo == nil {
  454. ctx.NotFound("ViewPullFiles", nil)
  455. return
  456. }
  457. headRepoPath := pull.HeadRepo.RepoPath()
  458. headGitRepo, err := git.OpenRepository(headRepoPath)
  459. if err != nil {
  460. ctx.ServerError("OpenRepository", err)
  461. return
  462. }
  463. defer headGitRepo.Close()
  464. headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
  465. if err != nil {
  466. ctx.ServerError("GetBranchCommitID", err)
  467. return
  468. }
  469. diffRepoPath = headRepoPath
  470. startCommitID = prInfo.MergeBase
  471. endCommitID = headCommitID
  472. gitRepo = headGitRepo
  473. headTarget = path.Join(pull.MustHeadUserName(), pull.HeadRepo.Name)
  474. ctx.Data["Username"] = pull.MustHeadUserName()
  475. ctx.Data["Reponame"] = pull.HeadRepo.Name
  476. }
  477. ctx.Data["AfterCommitID"] = endCommitID
  478. diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,
  479. startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
  480. setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
  481. whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
  482. if err != nil {
  483. ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
  484. return
  485. }
  486. if err = diff.LoadComments(issue, ctx.User); err != nil {
  487. ctx.ServerError("LoadComments", err)
  488. return
  489. }
  490. ctx.Data["Diff"] = diff
  491. ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
  492. baseCommit, err := ctx.Repo.GitRepo.GetCommit(startCommitID)
  493. if err != nil {
  494. ctx.ServerError("GetCommit", err)
  495. return
  496. }
  497. commit, err := gitRepo.GetCommit(endCommitID)
  498. if err != nil {
  499. ctx.ServerError("GetCommit", err)
  500. return
  501. }
  502. setImageCompareContext(ctx, baseCommit, commit)
  503. setPathsCompareContext(ctx, baseCommit, commit, headTarget)
  504. ctx.Data["RequireHighlightJS"] = true
  505. ctx.Data["RequireTribute"] = true
  506. if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil {
  507. ctx.ServerError("GetAssignees", err)
  508. return
  509. }
  510. ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.User, issue)
  511. if err != nil && !models.IsErrReviewNotExist(err) {
  512. ctx.ServerError("GetCurrentReview", err)
  513. return
  514. }
  515. ctx.HTML(200, tplPullFiles)
  516. }
  517. // MergePullRequest response for merging pull request
  518. func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
  519. issue := checkPullInfo(ctx)
  520. if ctx.Written() {
  521. return
  522. }
  523. if issue.IsClosed {
  524. ctx.NotFound("MergePullRequest", nil)
  525. return
  526. }
  527. pr := issue.PullRequest
  528. if !pr.CanAutoMerge() || pr.HasMerged {
  529. ctx.NotFound("MergePullRequest", nil)
  530. return
  531. }
  532. if pr.IsWorkInProgress() {
  533. ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_wip"))
  534. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  535. return
  536. }
  537. isPass, err := pull_service.IsPullCommitStatusPass(pr)
  538. if err != nil {
  539. ctx.ServerError("IsPullCommitStatusPass", err)
  540. return
  541. }
  542. if !isPass && !ctx.IsUserRepoAdmin() {
  543. ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_status_check"))
  544. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  545. return
  546. }
  547. if ctx.HasError() {
  548. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  549. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  550. return
  551. }
  552. message := strings.TrimSpace(form.MergeTitleField)
  553. if len(message) == 0 {
  554. if models.MergeStyle(form.Do) == models.MergeStyleMerge {
  555. message = pr.GetDefaultMergeMessage()
  556. }
  557. if models.MergeStyle(form.Do) == models.MergeStyleRebaseMerge {
  558. message = pr.GetDefaultMergeMessage()
  559. }
  560. if models.MergeStyle(form.Do) == models.MergeStyleSquash {
  561. message = pr.GetDefaultSquashMessage()
  562. }
  563. }
  564. form.MergeMessageField = strings.TrimSpace(form.MergeMessageField)
  565. if len(form.MergeMessageField) > 0 {
  566. message += "\n\n" + form.MergeMessageField
  567. }
  568. pr.Issue = issue
  569. pr.Issue.Repo = ctx.Repo.Repository
  570. noDeps, err := models.IssueNoDependenciesLeft(issue)
  571. if err != nil {
  572. return
  573. }
  574. if !noDeps {
  575. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
  576. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  577. return
  578. }
  579. if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
  580. sanitize := func(x string) string {
  581. runes := []rune(x)
  582. if len(runes) > 512 {
  583. x = "..." + string(runes[len(runes)-512:])
  584. }
  585. return strings.Replace(html.EscapeString(x), "\n", "<br>", -1)
  586. }
  587. if models.IsErrInvalidMergeStyle(err) {
  588. ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
  589. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  590. return
  591. } else if models.IsErrMergeConflicts(err) {
  592. conflictError := err.(models.ErrMergeConflicts)
  593. ctx.Flash.Error(ctx.Tr("repo.pulls.merge_conflict", sanitize(conflictError.StdErr), sanitize(conflictError.StdOut)))
  594. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  595. return
  596. } else if models.IsErrRebaseConflicts(err) {
  597. conflictError := err.(models.ErrRebaseConflicts)
  598. ctx.Flash.Error(ctx.Tr("repo.pulls.rebase_conflict", sanitize(conflictError.CommitSHA), sanitize(conflictError.StdErr), sanitize(conflictError.StdOut)))
  599. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  600. return
  601. } else if models.IsErrMergeUnrelatedHistories(err) {
  602. log.Debug("MergeUnrelatedHistories error: %v", err)
  603. ctx.Flash.Error(ctx.Tr("repo.pulls.unrelated_histories"))
  604. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  605. return
  606. } else if models.IsErrMergePushOutOfDate(err) {
  607. log.Debug("MergePushOutOfDate error: %v", err)
  608. ctx.Flash.Error(ctx.Tr("repo.pulls.merge_out_of_date"))
  609. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  610. return
  611. }
  612. ctx.ServerError("Merge", err)
  613. return
  614. }
  615. if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
  616. ctx.ServerError("CreateOrStopIssueStopwatch", err)
  617. return
  618. }
  619. notification.NotifyMergePullRequest(pr, ctx.User, ctx.Repo.GitRepo)
  620. log.Trace("Pull request merged: %d", pr.ID)
  621. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  622. }
  623. func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
  624. if models.StopwatchExists(user.ID, issue.ID) {
  625. if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
  626. return err
  627. }
  628. }
  629. return nil
  630. }
  631. // CompareAndPullRequestPost response for creating pull request
  632. func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) {
  633. ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
  634. ctx.Data["PageIsComparePull"] = true
  635. ctx.Data["IsDiffCompare"] = true
  636. ctx.Data["RequireHighlightJS"] = true
  637. ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
  638. renderAttachmentSettings(ctx)
  639. var (
  640. repo = ctx.Repo.Repository
  641. attachments []string
  642. )
  643. headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
  644. if ctx.Written() {
  645. return
  646. }
  647. defer headGitRepo.Close()
  648. labelIDs, assigneeIDs, milestoneID := ValidateRepoMetas(ctx, form, true)
  649. if ctx.Written() {
  650. return
  651. }
  652. if setting.AttachmentEnabled {
  653. attachments = form.Files
  654. }
  655. if ctx.HasError() {
  656. auth.AssignForm(form, ctx.Data)
  657. // This stage is already stop creating new pull request, so it does not matter if it has
  658. // something to compare or not.
  659. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  660. if ctx.Written() {
  661. return
  662. }
  663. ctx.HTML(200, tplCompareDiff)
  664. return
  665. }
  666. if util.IsEmptyString(form.Title) {
  667. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  668. if ctx.Written() {
  669. return
  670. }
  671. ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplCompareDiff, form)
  672. return
  673. }
  674. patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch)
  675. if err != nil {
  676. ctx.ServerError("GetPatch", err)
  677. return
  678. }
  679. pullIssue := &models.Issue{
  680. RepoID: repo.ID,
  681. Title: form.Title,
  682. PosterID: ctx.User.ID,
  683. Poster: ctx.User,
  684. MilestoneID: milestoneID,
  685. IsPull: true,
  686. Content: form.Content,
  687. }
  688. pullRequest := &models.PullRequest{
  689. HeadRepoID: headRepo.ID,
  690. BaseRepoID: repo.ID,
  691. HeadBranch: headBranch,
  692. BaseBranch: baseBranch,
  693. HeadRepo: headRepo,
  694. BaseRepo: repo,
  695. MergeBase: prInfo.MergeBase,
  696. Type: models.PullRequestGitea,
  697. }
  698. // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
  699. // instead of 500.
  700. if err := pull_service.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch, assigneeIDs); err != nil {
  701. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  702. ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
  703. return
  704. }
  705. ctx.ServerError("NewPullRequest", err)
  706. return
  707. } else if err := pullRequest.PushToBaseRepo(); err != nil {
  708. ctx.ServerError("PushToBaseRepo", err)
  709. return
  710. }
  711. notification.NotifyNewPullRequest(pullRequest)
  712. log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
  713. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
  714. }
  715. // TriggerTask response for a trigger task request
  716. func TriggerTask(ctx *context.Context) {
  717. pusherID := ctx.QueryInt64("pusher")
  718. branch := ctx.Query("branch")
  719. secret := ctx.Query("secret")
  720. if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 {
  721. ctx.Error(404)
  722. log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid")
  723. return
  724. }
  725. owner, repo := parseOwnerAndRepo(ctx)
  726. if ctx.Written() {
  727. return
  728. }
  729. got := []byte(base.EncodeMD5(owner.Salt))
  730. want := []byte(secret)
  731. if subtle.ConstantTimeCompare(got, want) != 1 {
  732. ctx.Error(404)
  733. log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
  734. return
  735. }
  736. pusher, err := models.GetUserByID(pusherID)
  737. if err != nil {
  738. if models.IsErrUserNotExist(err) {
  739. ctx.Error(404)
  740. } else {
  741. ctx.ServerError("GetUserByID", err)
  742. }
  743. return
  744. }
  745. log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
  746. go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true)
  747. ctx.Status(202)
  748. }
  749. // CleanUpPullRequest responses for delete merged branch when PR has been merged
  750. func CleanUpPullRequest(ctx *context.Context) {
  751. issue := checkPullInfo(ctx)
  752. if ctx.Written() {
  753. return
  754. }
  755. pr := issue.PullRequest
  756. // Don't cleanup unmerged and unclosed PRs
  757. if !pr.HasMerged && !issue.IsClosed {
  758. ctx.NotFound("CleanUpPullRequest", nil)
  759. return
  760. }
  761. if err := pr.GetHeadRepo(); err != nil {
  762. ctx.ServerError("GetHeadRepo", err)
  763. return
  764. } else if pr.HeadRepo == nil {
  765. // Forked repository has already been deleted
  766. ctx.NotFound("CleanUpPullRequest", nil)
  767. return
  768. } else if err = pr.GetBaseRepo(); err != nil {
  769. ctx.ServerError("GetBaseRepo", err)
  770. return
  771. } else if err = pr.HeadRepo.GetOwner(); err != nil {
  772. ctx.ServerError("HeadRepo.GetOwner", err)
  773. return
  774. }
  775. perm, err := models.GetUserRepoPermission(pr.HeadRepo, ctx.User)
  776. if err != nil {
  777. ctx.ServerError("GetUserRepoPermission", err)
  778. return
  779. }
  780. if !perm.CanWrite(models.UnitTypeCode) {
  781. ctx.NotFound("CleanUpPullRequest", nil)
  782. return
  783. }
  784. fullBranchName := pr.HeadRepo.Owner.Name + "/" + pr.HeadBranch
  785. gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  786. if err != nil {
  787. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
  788. return
  789. }
  790. defer gitRepo.Close()
  791. gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
  792. if err != nil {
  793. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
  794. return
  795. }
  796. defer gitBaseRepo.Close()
  797. defer func() {
  798. ctx.JSON(200, map[string]interface{}{
  799. "redirect": pr.BaseRepo.Link() + "/pulls/" + com.ToStr(issue.Index),
  800. })
  801. }()
  802. if pr.HeadBranch == pr.HeadRepo.DefaultBranch || !gitRepo.IsBranchExist(pr.HeadBranch) {
  803. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  804. return
  805. }
  806. // Check if branch is not protected
  807. if protected, err := pr.HeadRepo.IsProtectedBranch(pr.HeadBranch, ctx.User); err != nil || protected {
  808. if err != nil {
  809. log.Error("HeadRepo.IsProtectedBranch: %v", err)
  810. }
  811. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  812. return
  813. }
  814. // Check if branch has no new commits
  815. headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
  816. if err != nil {
  817. log.Error("GetRefCommitID: %v", err)
  818. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  819. return
  820. }
  821. branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
  822. if err != nil {
  823. log.Error("GetBranchCommitID: %v", err)
  824. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  825. return
  826. }
  827. if headCommitID != branchCommitID {
  828. ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName))
  829. return
  830. }
  831. if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
  832. Force: true,
  833. }); err != nil {
  834. log.Error("DeleteBranch: %v", err)
  835. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  836. return
  837. }
  838. if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, issue.ID, pr.HeadBranch); err != nil {
  839. // Do not fail here as branch has already been deleted
  840. log.Error("DeleteBranch: %v", err)
  841. }
  842. ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))
  843. }
  844. // DownloadPullDiff render a pull's raw diff
  845. func DownloadPullDiff(ctx *context.Context) {
  846. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  847. if err != nil {
  848. if models.IsErrIssueNotExist(err) {
  849. ctx.NotFound("GetIssueByIndex", err)
  850. } else {
  851. ctx.ServerError("GetIssueByIndex", err)
  852. }
  853. return
  854. }
  855. // Return not found if it's not a pull request
  856. if !issue.IsPull {
  857. ctx.NotFound("DownloadPullDiff",
  858. fmt.Errorf("Issue is not a pull request"))
  859. return
  860. }
  861. if err = issue.LoadPullRequest(); err != nil {
  862. ctx.ServerError("LoadPullRequest", err)
  863. return
  864. }
  865. pr := issue.PullRequest
  866. if err = pr.GetBaseRepo(); err != nil {
  867. ctx.ServerError("GetBaseRepo", err)
  868. return
  869. }
  870. patch, err := pr.BaseRepo.PatchPath(pr.Index)
  871. if err != nil {
  872. ctx.ServerError("PatchPath", err)
  873. return
  874. }
  875. ctx.ServeFileContent(patch)
  876. }
  877. // DownloadPullPatch render a pull's raw patch
  878. func DownloadPullPatch(ctx *context.Context) {
  879. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  880. if err != nil {
  881. if models.IsErrIssueNotExist(err) {
  882. ctx.NotFound("GetIssueByIndex", err)
  883. } else {
  884. ctx.ServerError("GetIssueByIndex", err)
  885. }
  886. return
  887. }
  888. // Return not found if it's not a pull request
  889. if !issue.IsPull {
  890. ctx.NotFound("DownloadPullDiff",
  891. fmt.Errorf("Issue is not a pull request"))
  892. return
  893. }
  894. if err = issue.LoadPullRequest(); err != nil {
  895. ctx.ServerError("LoadPullRequest", err)
  896. return
  897. }
  898. pr := issue.PullRequest
  899. if err = pr.GetHeadRepo(); err != nil {
  900. ctx.ServerError("GetHeadRepo", err)
  901. return
  902. }
  903. headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  904. if err != nil {
  905. ctx.ServerError("OpenRepository", err)
  906. return
  907. }
  908. defer headGitRepo.Close()
  909. patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch)
  910. if err != nil {
  911. ctx.ServerError("GetFormatPatch", err)
  912. return
  913. }
  914. _, err = io.Copy(ctx, patch)
  915. if err != nil {
  916. ctx.ServerError("io.Copy", err)
  917. return
  918. }
  919. }