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

11 years ago
10 years ago
11 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
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>
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>
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>
6 years ago
10 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>
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>
6 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
10 years ago
10 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
10 years ago
10 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
10 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
10 years ago
10 years ago
10 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
11 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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. "path"
  13. "strings"
  14. "code.gitea.io/gitea/models"
  15. "code.gitea.io/gitea/modules/auth"
  16. "code.gitea.io/gitea/modules/base"
  17. "code.gitea.io/gitea/modules/context"
  18. "code.gitea.io/gitea/modules/git"
  19. "code.gitea.io/gitea/modules/log"
  20. "code.gitea.io/gitea/modules/notification"
  21. "code.gitea.io/gitea/modules/setting"
  22. "code.gitea.io/gitea/modules/util"
  23. "code.gitea.io/gitea/services/gitdiff"
  24. pull_service "code.gitea.io/gitea/services/pull"
  25. repo_service "code.gitea.io/gitea/services/repository"
  26. "github.com/unknwon/com"
  27. )
  28. const (
  29. tplFork base.TplName = "repo/pulls/fork"
  30. tplCompareDiff base.TplName = "repo/diff/compare"
  31. tplPullCommits base.TplName = "repo/pulls/commits"
  32. tplPullFiles base.TplName = "repo/pulls/files"
  33. pullRequestTemplateKey = "PullRequestTemplate"
  34. )
  35. var (
  36. pullRequestTemplateCandidates = []string{
  37. "PULL_REQUEST_TEMPLATE.md",
  38. "pull_request_template.md",
  39. ".gitea/PULL_REQUEST_TEMPLATE.md",
  40. ".gitea/pull_request_template.md",
  41. ".github/PULL_REQUEST_TEMPLATE.md",
  42. ".github/pull_request_template.md",
  43. }
  44. )
  45. func getRepository(ctx *context.Context, repoID int64) *models.Repository {
  46. repo, err := models.GetRepositoryByID(repoID)
  47. if err != nil {
  48. if models.IsErrRepoNotExist(err) {
  49. ctx.NotFound("GetRepositoryByID", nil)
  50. } else {
  51. ctx.ServerError("GetRepositoryByID", err)
  52. }
  53. return nil
  54. }
  55. perm, err := models.GetUserRepoPermission(repo, ctx.User)
  56. if err != nil {
  57. ctx.ServerError("GetUserRepoPermission", err)
  58. return nil
  59. }
  60. if !perm.CanRead(models.UnitTypeCode) {
  61. log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
  62. "User in repo has Permissions: %-+v",
  63. ctx.User,
  64. models.UnitTypeCode,
  65. ctx.Repo,
  66. perm)
  67. ctx.NotFound("getRepository", nil)
  68. return nil
  69. }
  70. return repo
  71. }
  72. func getForkRepository(ctx *context.Context) *models.Repository {
  73. forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid"))
  74. if ctx.Written() {
  75. return nil
  76. }
  77. if forkRepo.IsEmpty {
  78. log.Trace("Empty repository %-v", forkRepo)
  79. ctx.NotFound("getForkRepository", nil)
  80. return nil
  81. }
  82. ctx.Data["repo_name"] = forkRepo.Name
  83. ctx.Data["description"] = forkRepo.Description
  84. ctx.Data["IsPrivate"] = forkRepo.IsPrivate
  85. canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
  86. if err := forkRepo.GetOwner(); err != nil {
  87. ctx.ServerError("GetOwner", err)
  88. return nil
  89. }
  90. ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
  91. ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
  92. if err := ctx.User.GetOwnedOrganizations(); err != nil {
  93. ctx.ServerError("GetOwnedOrganizations", err)
  94. return nil
  95. }
  96. var orgs []*models.User
  97. for _, org := range ctx.User.OwnedOrgs {
  98. if forkRepo.OwnerID != org.ID && !org.HasForkedRepo(forkRepo.ID) {
  99. orgs = append(orgs, org)
  100. }
  101. }
  102. var traverseParentRepo = forkRepo
  103. var err error
  104. for {
  105. if ctx.User.ID == traverseParentRepo.OwnerID {
  106. canForkToUser = false
  107. } else {
  108. for i, org := range orgs {
  109. if org.ID == traverseParentRepo.OwnerID {
  110. orgs = append(orgs[:i], orgs[i+1:]...)
  111. break
  112. }
  113. }
  114. }
  115. if !traverseParentRepo.IsFork {
  116. break
  117. }
  118. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  119. if err != nil {
  120. ctx.ServerError("GetRepositoryByID", err)
  121. return nil
  122. }
  123. }
  124. ctx.Data["CanForkToUser"] = canForkToUser
  125. ctx.Data["Orgs"] = orgs
  126. if canForkToUser {
  127. ctx.Data["ContextUser"] = ctx.User
  128. } else if len(orgs) > 0 {
  129. ctx.Data["ContextUser"] = orgs[0]
  130. }
  131. return forkRepo
  132. }
  133. // Fork render repository fork page
  134. func Fork(ctx *context.Context) {
  135. ctx.Data["Title"] = ctx.Tr("new_fork")
  136. getForkRepository(ctx)
  137. if ctx.Written() {
  138. return
  139. }
  140. ctx.HTML(200, tplFork)
  141. }
  142. // ForkPost response for forking a repository
  143. func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
  144. ctx.Data["Title"] = ctx.Tr("new_fork")
  145. ctxUser := checkContextUser(ctx, form.UID)
  146. if ctx.Written() {
  147. return
  148. }
  149. forkRepo := getForkRepository(ctx)
  150. if ctx.Written() {
  151. return
  152. }
  153. ctx.Data["ContextUser"] = ctxUser
  154. if ctx.HasError() {
  155. ctx.HTML(200, tplFork)
  156. return
  157. }
  158. var err error
  159. var traverseParentRepo = forkRepo
  160. for {
  161. if ctxUser.ID == traverseParentRepo.OwnerID {
  162. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  163. return
  164. }
  165. repo, has := models.HasForkedRepo(ctxUser.ID, traverseParentRepo.ID)
  166. if has {
  167. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  168. return
  169. }
  170. if !traverseParentRepo.IsFork {
  171. break
  172. }
  173. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  174. if err != nil {
  175. ctx.ServerError("GetRepositoryByID", err)
  176. return
  177. }
  178. }
  179. // Check ownership of organization.
  180. if ctxUser.IsOrganization() {
  181. isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
  182. if err != nil {
  183. ctx.ServerError("IsOwnedBy", err)
  184. return
  185. } else if !isOwner {
  186. ctx.Error(403)
  187. return
  188. }
  189. }
  190. repo, err := repo_service.ForkRepository(ctx.User, ctxUser, forkRepo, form.RepoName, form.Description)
  191. if err != nil {
  192. ctx.Data["Err_RepoName"] = true
  193. switch {
  194. case models.IsErrRepoAlreadyExist(err):
  195. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  196. case models.IsErrNameReserved(err):
  197. ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
  198. case models.IsErrNamePatternNotAllowed(err):
  199. ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
  200. default:
  201. ctx.ServerError("ForkPost", err)
  202. }
  203. return
  204. }
  205. log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
  206. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  207. }
  208. func checkPullInfo(ctx *context.Context) *models.Issue {
  209. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  210. if err != nil {
  211. if models.IsErrIssueNotExist(err) {
  212. ctx.NotFound("GetIssueByIndex", err)
  213. } else {
  214. ctx.ServerError("GetIssueByIndex", err)
  215. }
  216. return nil
  217. }
  218. if err = issue.LoadPoster(); err != nil {
  219. ctx.ServerError("LoadPoster", err)
  220. return nil
  221. }
  222. if err := issue.LoadRepo(); err != nil {
  223. ctx.ServerError("LoadRepo", err)
  224. return nil
  225. }
  226. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  227. ctx.Data["Issue"] = issue
  228. if !issue.IsPull {
  229. ctx.NotFound("ViewPullCommits", nil)
  230. return nil
  231. }
  232. if err = issue.LoadPullRequest(); err != nil {
  233. ctx.ServerError("LoadPullRequest", err)
  234. return nil
  235. }
  236. if err = issue.PullRequest.GetHeadRepo(); err != nil {
  237. ctx.ServerError("GetHeadRepo", err)
  238. return nil
  239. }
  240. if ctx.IsSigned {
  241. // Update issue-user.
  242. if err = issue.ReadBy(ctx.User.ID); err != nil {
  243. ctx.ServerError("ReadBy", err)
  244. return nil
  245. }
  246. }
  247. return issue
  248. }
  249. func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
  250. if ctx.Repo.Owner.Name == pull.MustHeadUserName() {
  251. ctx.Data["HeadTarget"] = pull.HeadBranch
  252. } else if pull.HeadRepo == nil {
  253. ctx.Data["HeadTarget"] = pull.MustHeadUserName() + ":" + pull.HeadBranch
  254. } else {
  255. ctx.Data["HeadTarget"] = pull.MustHeadUserName() + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
  256. }
  257. ctx.Data["BaseTarget"] = pull.BaseBranch
  258. }
  259. // PrepareMergedViewPullInfo show meta information for a merged pull request view page
  260. func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  261. pull := issue.PullRequest
  262. setMergeTarget(ctx, pull)
  263. ctx.Data["HasMerged"] = true
  264. compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
  265. pull.MergeBase, pull.GetGitRefName())
  266. if err != nil {
  267. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  268. ctx.Data["IsPullRequestBroken"] = true
  269. ctx.Data["BaseTarget"] = "deleted"
  270. ctx.Data["NumCommits"] = 0
  271. ctx.Data["NumFiles"] = 0
  272. return nil
  273. }
  274. ctx.ServerError("GetCompareInfo", err)
  275. return nil
  276. }
  277. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  278. ctx.Data["NumFiles"] = compareInfo.NumFiles
  279. return compareInfo
  280. }
  281. // PrepareViewPullInfo show meta information for a pull request preview page
  282. func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  283. repo := ctx.Repo.Repository
  284. pull := issue.PullRequest
  285. var err error
  286. if err = pull.GetHeadRepo(); err != nil {
  287. ctx.ServerError("GetHeadRepo", err)
  288. return nil
  289. }
  290. setMergeTarget(ctx, pull)
  291. if err = pull.LoadProtectedBranch(); err != nil {
  292. ctx.ServerError("GetLatestCommitStatus", err)
  293. return nil
  294. }
  295. ctx.Data["EnableStatusCheck"] = pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck
  296. var headGitRepo *git.Repository
  297. var headBranchExist bool
  298. // HeadRepo may be missing
  299. if pull.HeadRepo != nil {
  300. headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath())
  301. if err != nil {
  302. ctx.ServerError("OpenRepository", err)
  303. return nil
  304. }
  305. defer headGitRepo.Close()
  306. headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)
  307. if headBranchExist {
  308. sha, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
  309. if err != nil {
  310. ctx.ServerError("GetBranchCommitID", err)
  311. return nil
  312. }
  313. commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0)
  314. if err != nil {
  315. ctx.ServerError("GetLatestCommitStatus", err)
  316. return nil
  317. }
  318. if len(commitStatuses) > 0 {
  319. ctx.Data["LatestCommitStatuses"] = commitStatuses
  320. ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
  321. }
  322. if pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck {
  323. ctx.Data["is_context_required"] = func(context string) bool {
  324. for _, c := range pull.ProtectedBranch.StatusCheckContexts {
  325. if c == context {
  326. return true
  327. }
  328. }
  329. return false
  330. }
  331. ctx.Data["IsRequiredStatusCheckSuccess"] = pull_service.IsCommitStatusContextSuccess(commitStatuses, pull.ProtectedBranch.StatusCheckContexts)
  332. }
  333. }
  334. }
  335. if pull.HeadRepo == nil || !headBranchExist {
  336. ctx.Data["IsPullRequestBroken"] = true
  337. ctx.Data["HeadTarget"] = "deleted"
  338. ctx.Data["NumCommits"] = 0
  339. ctx.Data["NumFiles"] = 0
  340. return nil
  341. }
  342. compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
  343. pull.BaseBranch, pull.HeadBranch)
  344. if err != nil {
  345. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  346. ctx.Data["IsPullRequestBroken"] = true
  347. ctx.Data["BaseTarget"] = "deleted"
  348. ctx.Data["NumCommits"] = 0
  349. ctx.Data["NumFiles"] = 0
  350. return nil
  351. }
  352. ctx.ServerError("GetCompareInfo", err)
  353. return nil
  354. }
  355. if pull.IsWorkInProgress() {
  356. ctx.Data["IsPullWorkInProgress"] = true
  357. ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()
  358. }
  359. if pull.IsFilesConflicted() {
  360. ctx.Data["IsPullFilesConflicted"] = true
  361. ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
  362. }
  363. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  364. ctx.Data["NumFiles"] = compareInfo.NumFiles
  365. ctx.Data["AllowedReactions"] = setting.UI.Reactions
  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. log.Trace("Pull request merged: %d", pr.ID)
  620. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  621. }
  622. func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
  623. if models.StopwatchExists(user.ID, issue.ID) {
  624. if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
  625. return err
  626. }
  627. }
  628. return nil
  629. }
  630. // CompareAndPullRequestPost response for creating pull request
  631. func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) {
  632. ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
  633. ctx.Data["PageIsComparePull"] = true
  634. ctx.Data["IsDiffCompare"] = true
  635. ctx.Data["RequireHighlightJS"] = true
  636. ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
  637. renderAttachmentSettings(ctx)
  638. var (
  639. repo = ctx.Repo.Repository
  640. attachments []string
  641. )
  642. headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
  643. if ctx.Written() {
  644. return
  645. }
  646. defer headGitRepo.Close()
  647. labelIDs, assigneeIDs, milestoneID := ValidateRepoMetas(ctx, form, true)
  648. if ctx.Written() {
  649. return
  650. }
  651. if setting.AttachmentEnabled {
  652. attachments = form.Files
  653. }
  654. if ctx.HasError() {
  655. auth.AssignForm(form, ctx.Data)
  656. // This stage is already stop creating new pull request, so it does not matter if it has
  657. // something to compare or not.
  658. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  659. if ctx.Written() {
  660. return
  661. }
  662. ctx.HTML(200, tplCompareDiff)
  663. return
  664. }
  665. if util.IsEmptyString(form.Title) {
  666. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  667. if ctx.Written() {
  668. return
  669. }
  670. ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplCompareDiff, form)
  671. return
  672. }
  673. pullIssue := &models.Issue{
  674. RepoID: repo.ID,
  675. Title: form.Title,
  676. PosterID: ctx.User.ID,
  677. Poster: ctx.User,
  678. MilestoneID: milestoneID,
  679. IsPull: true,
  680. Content: form.Content,
  681. }
  682. pullRequest := &models.PullRequest{
  683. HeadRepoID: headRepo.ID,
  684. BaseRepoID: repo.ID,
  685. HeadBranch: headBranch,
  686. BaseBranch: baseBranch,
  687. HeadRepo: headRepo,
  688. BaseRepo: repo,
  689. MergeBase: prInfo.MergeBase,
  690. Type: models.PullRequestGitea,
  691. }
  692. // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
  693. // instead of 500.
  694. if err := pull_service.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil {
  695. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  696. ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
  697. return
  698. }
  699. ctx.ServerError("NewPullRequest", err)
  700. return
  701. }
  702. notification.NotifyNewPullRequest(pullRequest)
  703. log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
  704. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
  705. }
  706. // TriggerTask response for a trigger task request
  707. func TriggerTask(ctx *context.Context) {
  708. pusherID := ctx.QueryInt64("pusher")
  709. branch := ctx.Query("branch")
  710. secret := ctx.Query("secret")
  711. if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 {
  712. ctx.Error(404)
  713. log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid")
  714. return
  715. }
  716. owner, repo := parseOwnerAndRepo(ctx)
  717. if ctx.Written() {
  718. return
  719. }
  720. got := []byte(base.EncodeMD5(owner.Salt))
  721. want := []byte(secret)
  722. if subtle.ConstantTimeCompare(got, want) != 1 {
  723. ctx.Error(404)
  724. log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
  725. return
  726. }
  727. pusher, err := models.GetUserByID(pusherID)
  728. if err != nil {
  729. if models.IsErrUserNotExist(err) {
  730. ctx.Error(404)
  731. } else {
  732. ctx.ServerError("GetUserByID", err)
  733. }
  734. return
  735. }
  736. log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
  737. go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true)
  738. ctx.Status(202)
  739. }
  740. // CleanUpPullRequest responses for delete merged branch when PR has been merged
  741. func CleanUpPullRequest(ctx *context.Context) {
  742. issue := checkPullInfo(ctx)
  743. if ctx.Written() {
  744. return
  745. }
  746. pr := issue.PullRequest
  747. // Don't cleanup unmerged and unclosed PRs
  748. if !pr.HasMerged && !issue.IsClosed {
  749. ctx.NotFound("CleanUpPullRequest", nil)
  750. return
  751. }
  752. if err := pr.GetHeadRepo(); err != nil {
  753. ctx.ServerError("GetHeadRepo", err)
  754. return
  755. } else if pr.HeadRepo == nil {
  756. // Forked repository has already been deleted
  757. ctx.NotFound("CleanUpPullRequest", nil)
  758. return
  759. } else if err = pr.GetBaseRepo(); err != nil {
  760. ctx.ServerError("GetBaseRepo", err)
  761. return
  762. } else if err = pr.HeadRepo.GetOwner(); err != nil {
  763. ctx.ServerError("HeadRepo.GetOwner", err)
  764. return
  765. }
  766. perm, err := models.GetUserRepoPermission(pr.HeadRepo, ctx.User)
  767. if err != nil {
  768. ctx.ServerError("GetUserRepoPermission", err)
  769. return
  770. }
  771. if !perm.CanWrite(models.UnitTypeCode) {
  772. ctx.NotFound("CleanUpPullRequest", nil)
  773. return
  774. }
  775. fullBranchName := pr.HeadRepo.Owner.Name + "/" + pr.HeadBranch
  776. gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  777. if err != nil {
  778. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
  779. return
  780. }
  781. defer gitRepo.Close()
  782. gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
  783. if err != nil {
  784. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
  785. return
  786. }
  787. defer gitBaseRepo.Close()
  788. defer func() {
  789. ctx.JSON(200, map[string]interface{}{
  790. "redirect": pr.BaseRepo.Link() + "/pulls/" + com.ToStr(issue.Index),
  791. })
  792. }()
  793. if pr.HeadBranch == pr.HeadRepo.DefaultBranch || !gitRepo.IsBranchExist(pr.HeadBranch) {
  794. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  795. return
  796. }
  797. // Check if branch is not protected
  798. if protected, err := pr.HeadRepo.IsProtectedBranch(pr.HeadBranch, ctx.User); err != nil || protected {
  799. if err != nil {
  800. log.Error("HeadRepo.IsProtectedBranch: %v", err)
  801. }
  802. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  803. return
  804. }
  805. // Check if branch has no new commits
  806. headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
  807. if err != nil {
  808. log.Error("GetRefCommitID: %v", err)
  809. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  810. return
  811. }
  812. branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
  813. if err != nil {
  814. log.Error("GetBranchCommitID: %v", err)
  815. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  816. return
  817. }
  818. if headCommitID != branchCommitID {
  819. ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName))
  820. return
  821. }
  822. if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
  823. Force: true,
  824. }); err != nil {
  825. log.Error("DeleteBranch: %v", err)
  826. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  827. return
  828. }
  829. if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, issue.ID, pr.HeadBranch); err != nil {
  830. // Do not fail here as branch has already been deleted
  831. log.Error("DeleteBranch: %v", err)
  832. }
  833. ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))
  834. }
  835. // DownloadPullDiff render a pull's raw diff
  836. func DownloadPullDiff(ctx *context.Context) {
  837. DownloadPullDiffOrPatch(ctx, false)
  838. }
  839. // DownloadPullPatch render a pull's raw patch
  840. func DownloadPullPatch(ctx *context.Context) {
  841. DownloadPullDiffOrPatch(ctx, true)
  842. }
  843. // DownloadPullDiffOrPatch render a pull's raw diff or patch
  844. func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
  845. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  846. if err != nil {
  847. if models.IsErrIssueNotExist(err) {
  848. ctx.NotFound("GetIssueByIndex", err)
  849. } else {
  850. ctx.ServerError("GetIssueByIndex", err)
  851. }
  852. return
  853. }
  854. // Return not found if it's not a pull request
  855. if !issue.IsPull {
  856. ctx.NotFound("DownloadPullDiff",
  857. fmt.Errorf("Issue is not a pull request"))
  858. return
  859. }
  860. if err = issue.LoadPullRequest(); err != nil {
  861. ctx.ServerError("LoadPullRequest", err)
  862. return
  863. }
  864. pr := issue.PullRequest
  865. if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch); err != nil {
  866. ctx.ServerError("DownloadDiffOrPatch", err)
  867. return
  868. }
  869. }