You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1258 lines
35 KiB

10 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 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
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
4 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>
4 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>
4 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>
4 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>
4 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
5 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
5 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
5 years ago
8 years ago
8 years ago
8 years ago
8 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
5 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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>
5 years ago
8 years ago
8 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>
4 years ago
8 years ago
8 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>
4 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>
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
8 years ago
8 years ago
Add a storage layer for attachments (#11387) * Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
3 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
7 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
5 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
5 years ago
10 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
5 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
5 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
5 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
5 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
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
  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. "net/http"
  12. "path"
  13. "strings"
  14. "time"
  15. "code.gitea.io/gitea/models"
  16. "code.gitea.io/gitea/modules/auth"
  17. "code.gitea.io/gitea/modules/base"
  18. "code.gitea.io/gitea/modules/context"
  19. "code.gitea.io/gitea/modules/git"
  20. "code.gitea.io/gitea/modules/log"
  21. "code.gitea.io/gitea/modules/notification"
  22. "code.gitea.io/gitea/modules/setting"
  23. "code.gitea.io/gitea/modules/structs"
  24. "code.gitea.io/gitea/modules/util"
  25. "code.gitea.io/gitea/routers/utils"
  26. "code.gitea.io/gitea/services/gitdiff"
  27. pull_service "code.gitea.io/gitea/services/pull"
  28. repo_service "code.gitea.io/gitea/services/repository"
  29. "github.com/unknwon/com"
  30. )
  31. const (
  32. tplFork base.TplName = "repo/pulls/fork"
  33. tplCompareDiff base.TplName = "repo/diff/compare"
  34. tplPullCommits base.TplName = "repo/pulls/commits"
  35. tplPullFiles base.TplName = "repo/pulls/files"
  36. pullRequestTemplateKey = "PullRequestTemplate"
  37. )
  38. var (
  39. pullRequestTemplateCandidates = []string{
  40. "PULL_REQUEST_TEMPLATE.md",
  41. "pull_request_template.md",
  42. ".gitea/PULL_REQUEST_TEMPLATE.md",
  43. ".gitea/pull_request_template.md",
  44. ".github/PULL_REQUEST_TEMPLATE.md",
  45. ".github/pull_request_template.md",
  46. }
  47. )
  48. func getRepository(ctx *context.Context, repoID int64) *models.Repository {
  49. repo, err := models.GetRepositoryByID(repoID)
  50. if err != nil {
  51. if models.IsErrRepoNotExist(err) {
  52. ctx.NotFound("GetRepositoryByID", nil)
  53. } else {
  54. ctx.ServerError("GetRepositoryByID", err)
  55. }
  56. return nil
  57. }
  58. perm, err := models.GetUserRepoPermission(repo, ctx.User)
  59. if err != nil {
  60. ctx.ServerError("GetUserRepoPermission", err)
  61. return nil
  62. }
  63. if !perm.CanRead(models.UnitTypeCode) {
  64. log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
  65. "User in repo has Permissions: %-+v",
  66. ctx.User,
  67. models.UnitTypeCode,
  68. ctx.Repo,
  69. perm)
  70. ctx.NotFound("getRepository", nil)
  71. return nil
  72. }
  73. return repo
  74. }
  75. func getForkRepository(ctx *context.Context) *models.Repository {
  76. forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid"))
  77. if ctx.Written() {
  78. return nil
  79. }
  80. if forkRepo.IsEmpty {
  81. log.Trace("Empty repository %-v", forkRepo)
  82. ctx.NotFound("getForkRepository", nil)
  83. return nil
  84. }
  85. if err := forkRepo.GetOwner(); err != nil {
  86. ctx.ServerError("GetOwner", err)
  87. return nil
  88. }
  89. ctx.Data["repo_name"] = forkRepo.Name
  90. ctx.Data["description"] = forkRepo.Description
  91. ctx.Data["IsPrivate"] = forkRepo.IsPrivate || forkRepo.Owner.Visibility == structs.VisibleTypePrivate
  92. canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
  93. ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
  94. ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
  95. if err := ctx.User.GetOwnedOrganizations(); err != nil {
  96. ctx.ServerError("GetOwnedOrganizations", err)
  97. return nil
  98. }
  99. var orgs []*models.User
  100. for _, org := range ctx.User.OwnedOrgs {
  101. if forkRepo.OwnerID != org.ID && !org.HasForkedRepo(forkRepo.ID) {
  102. orgs = append(orgs, org)
  103. }
  104. }
  105. var traverseParentRepo = forkRepo
  106. var err error
  107. for {
  108. if ctx.User.ID == traverseParentRepo.OwnerID {
  109. canForkToUser = false
  110. } else {
  111. for i, org := range orgs {
  112. if org.ID == traverseParentRepo.OwnerID {
  113. orgs = append(orgs[:i], orgs[i+1:]...)
  114. break
  115. }
  116. }
  117. }
  118. if !traverseParentRepo.IsFork {
  119. break
  120. }
  121. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  122. if err != nil {
  123. ctx.ServerError("GetRepositoryByID", err)
  124. return nil
  125. }
  126. }
  127. ctx.Data["CanForkToUser"] = canForkToUser
  128. ctx.Data["Orgs"] = orgs
  129. if canForkToUser {
  130. ctx.Data["ContextUser"] = ctx.User
  131. } else if len(orgs) > 0 {
  132. ctx.Data["ContextUser"] = orgs[0]
  133. }
  134. return forkRepo
  135. }
  136. // Fork render repository fork page
  137. func Fork(ctx *context.Context) {
  138. ctx.Data["Title"] = ctx.Tr("new_fork")
  139. getForkRepository(ctx)
  140. if ctx.Written() {
  141. return
  142. }
  143. ctx.HTML(200, tplFork)
  144. }
  145. // ForkPost response for forking a repository
  146. func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
  147. ctx.Data["Title"] = ctx.Tr("new_fork")
  148. ctxUser := checkContextUser(ctx, form.UID)
  149. if ctx.Written() {
  150. return
  151. }
  152. forkRepo := getForkRepository(ctx)
  153. if ctx.Written() {
  154. return
  155. }
  156. ctx.Data["ContextUser"] = ctxUser
  157. if ctx.HasError() {
  158. ctx.HTML(200, tplFork)
  159. return
  160. }
  161. var err error
  162. var traverseParentRepo = forkRepo
  163. for {
  164. if ctxUser.ID == traverseParentRepo.OwnerID {
  165. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  166. return
  167. }
  168. repo, has := models.HasForkedRepo(ctxUser.ID, traverseParentRepo.ID)
  169. if has {
  170. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  171. return
  172. }
  173. if !traverseParentRepo.IsFork {
  174. break
  175. }
  176. traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
  177. if err != nil {
  178. ctx.ServerError("GetRepositoryByID", err)
  179. return
  180. }
  181. }
  182. // Check ownership of organization.
  183. if ctxUser.IsOrganization() {
  184. isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
  185. if err != nil {
  186. ctx.ServerError("IsOwnedBy", err)
  187. return
  188. } else if !isOwner {
  189. ctx.Error(403)
  190. return
  191. }
  192. }
  193. repo, err := repo_service.ForkRepository(ctx.User, ctxUser, forkRepo, form.RepoName, form.Description)
  194. if err != nil {
  195. ctx.Data["Err_RepoName"] = true
  196. switch {
  197. case models.IsErrRepoAlreadyExist(err):
  198. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
  199. case models.IsErrNameReserved(err):
  200. ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
  201. case models.IsErrNamePatternNotAllowed(err):
  202. ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
  203. default:
  204. ctx.ServerError("ForkPost", err)
  205. }
  206. return
  207. }
  208. log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
  209. ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
  210. }
  211. func checkPullInfo(ctx *context.Context) *models.Issue {
  212. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  213. if err != nil {
  214. if models.IsErrIssueNotExist(err) {
  215. ctx.NotFound("GetIssueByIndex", err)
  216. } else {
  217. ctx.ServerError("GetIssueByIndex", err)
  218. }
  219. return nil
  220. }
  221. if err = issue.LoadPoster(); err != nil {
  222. ctx.ServerError("LoadPoster", err)
  223. return nil
  224. }
  225. if err := issue.LoadRepo(); err != nil {
  226. ctx.ServerError("LoadRepo", err)
  227. return nil
  228. }
  229. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  230. ctx.Data["Issue"] = issue
  231. if !issue.IsPull {
  232. ctx.NotFound("ViewPullCommits", nil)
  233. return nil
  234. }
  235. if err = issue.LoadPullRequest(); err != nil {
  236. ctx.ServerError("LoadPullRequest", err)
  237. return nil
  238. }
  239. if err = issue.PullRequest.LoadHeadRepo(); err != nil {
  240. ctx.ServerError("LoadHeadRepo", err)
  241. return nil
  242. }
  243. if ctx.IsSigned {
  244. // Update issue-user.
  245. if err = issue.ReadBy(ctx.User.ID); err != nil {
  246. ctx.ServerError("ReadBy", err)
  247. return nil
  248. }
  249. }
  250. return issue
  251. }
  252. func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
  253. if ctx.Repo.Owner.Name == pull.MustHeadUserName() {
  254. ctx.Data["HeadTarget"] = pull.HeadBranch
  255. } else if pull.HeadRepo == nil {
  256. ctx.Data["HeadTarget"] = pull.MustHeadUserName() + ":" + pull.HeadBranch
  257. } else {
  258. ctx.Data["HeadTarget"] = pull.MustHeadUserName() + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
  259. }
  260. ctx.Data["BaseTarget"] = pull.BaseBranch
  261. }
  262. // PrepareMergedViewPullInfo show meta information for a merged pull request view page
  263. func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  264. pull := issue.PullRequest
  265. setMergeTarget(ctx, pull)
  266. ctx.Data["HasMerged"] = true
  267. compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
  268. pull.MergeBase, pull.GetGitRefName())
  269. if err != nil {
  270. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  271. ctx.Data["IsPullRequestBroken"] = true
  272. ctx.Data["BaseTarget"] = pull.BaseBranch
  273. ctx.Data["NumCommits"] = 0
  274. ctx.Data["NumFiles"] = 0
  275. return nil
  276. }
  277. ctx.ServerError("GetCompareInfo", err)
  278. return nil
  279. }
  280. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  281. ctx.Data["NumFiles"] = compareInfo.NumFiles
  282. return compareInfo
  283. }
  284. // PrepareViewPullInfo show meta information for a pull request preview page
  285. func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
  286. repo := ctx.Repo.Repository
  287. pull := issue.PullRequest
  288. if err := pull.LoadHeadRepo(); err != nil {
  289. ctx.ServerError("LoadHeadRepo", err)
  290. return nil
  291. }
  292. if err := pull.LoadBaseRepo(); err != nil {
  293. ctx.ServerError("LoadBaseRepo", err)
  294. return nil
  295. }
  296. setMergeTarget(ctx, pull)
  297. if err := pull.LoadProtectedBranch(); err != nil {
  298. ctx.ServerError("LoadProtectedBranch", err)
  299. return nil
  300. }
  301. ctx.Data["EnableStatusCheck"] = pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck
  302. baseGitRepo, err := git.OpenRepository(pull.BaseRepo.RepoPath())
  303. if err != nil {
  304. ctx.ServerError("OpenRepository", err)
  305. return nil
  306. }
  307. defer baseGitRepo.Close()
  308. if !baseGitRepo.IsBranchExist(pull.BaseBranch) {
  309. ctx.Data["IsPullRequestBroken"] = true
  310. ctx.Data["BaseTarget"] = pull.BaseBranch
  311. ctx.Data["HeadTarget"] = pull.HeadBranch
  312. sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
  313. if err != nil {
  314. ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
  315. return nil
  316. }
  317. commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0)
  318. if err != nil {
  319. ctx.ServerError("GetLatestCommitStatus", err)
  320. return nil
  321. }
  322. if len(commitStatuses) > 0 {
  323. ctx.Data["LatestCommitStatuses"] = commitStatuses
  324. ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
  325. }
  326. compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
  327. pull.MergeBase, pull.GetGitRefName())
  328. if err != nil {
  329. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  330. ctx.Data["IsPullRequestBroken"] = true
  331. ctx.Data["BaseTarget"] = pull.BaseBranch
  332. ctx.Data["NumCommits"] = 0
  333. ctx.Data["NumFiles"] = 0
  334. return nil
  335. }
  336. ctx.ServerError("GetCompareInfo", err)
  337. return nil
  338. }
  339. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  340. ctx.Data["NumFiles"] = compareInfo.NumFiles
  341. return compareInfo
  342. }
  343. var headBranchExist bool
  344. var headBranchSha string
  345. // HeadRepo may be missing
  346. if pull.HeadRepo != nil {
  347. headGitRepo, err := git.OpenRepository(pull.HeadRepo.RepoPath())
  348. if err != nil {
  349. ctx.ServerError("OpenRepository", err)
  350. return nil
  351. }
  352. defer headGitRepo.Close()
  353. headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)
  354. if headBranchExist {
  355. headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch)
  356. if err != nil {
  357. ctx.ServerError("GetBranchCommitID", err)
  358. return nil
  359. }
  360. }
  361. }
  362. if headBranchExist {
  363. ctx.Data["UpdateAllowed"], err = pull_service.IsUserAllowedToUpdate(pull, ctx.User)
  364. if err != nil {
  365. ctx.ServerError("IsUserAllowedToUpdate", err)
  366. return nil
  367. }
  368. ctx.Data["GetCommitMessages"] = pull_service.GetCommitMessages(pull)
  369. }
  370. sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
  371. if err != nil {
  372. if git.IsErrNotExist(err) {
  373. ctx.Data["IsPullRequestBroken"] = true
  374. if pull.IsSameRepo() {
  375. ctx.Data["HeadTarget"] = pull.HeadBranch
  376. } else if pull.HeadRepo == nil {
  377. ctx.Data["HeadTarget"] = "<deleted>:" + pull.HeadBranch
  378. } else {
  379. ctx.Data["HeadTarget"] = pull.HeadRepo.OwnerName + ":" + pull.HeadBranch
  380. }
  381. ctx.Data["BaseTarget"] = pull.BaseBranch
  382. ctx.Data["NumCommits"] = 0
  383. ctx.Data["NumFiles"] = 0
  384. return nil
  385. }
  386. ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
  387. return nil
  388. }
  389. commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0)
  390. if err != nil {
  391. ctx.ServerError("GetLatestCommitStatus", err)
  392. return nil
  393. }
  394. if len(commitStatuses) > 0 {
  395. ctx.Data["LatestCommitStatuses"] = commitStatuses
  396. ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
  397. }
  398. if pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck {
  399. ctx.Data["is_context_required"] = func(context string) bool {
  400. for _, c := range pull.ProtectedBranch.StatusCheckContexts {
  401. if c == context {
  402. return true
  403. }
  404. }
  405. return false
  406. }
  407. ctx.Data["RequiredStatusCheckState"] = pull_service.MergeRequiredContextsCommitStatus(commitStatuses, pull.ProtectedBranch.StatusCheckContexts)
  408. }
  409. ctx.Data["HeadBranchMovedOn"] = headBranchSha != sha
  410. ctx.Data["HeadBranchCommitID"] = headBranchSha
  411. ctx.Data["PullHeadCommitID"] = sha
  412. if pull.HeadRepo == nil || !headBranchExist || headBranchSha != sha {
  413. ctx.Data["IsPullRequestBroken"] = true
  414. if pull.IsSameRepo() {
  415. ctx.Data["HeadTarget"] = pull.HeadBranch
  416. } else if pull.HeadRepo == nil {
  417. ctx.Data["HeadTarget"] = "<deleted>:" + pull.HeadBranch
  418. } else {
  419. ctx.Data["HeadTarget"] = pull.HeadRepo.OwnerName + ":" + pull.HeadBranch
  420. }
  421. }
  422. compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
  423. git.BranchPrefix+pull.BaseBranch, pull.GetGitRefName())
  424. if err != nil {
  425. if strings.Contains(err.Error(), "fatal: Not a valid object name") {
  426. ctx.Data["IsPullRequestBroken"] = true
  427. ctx.Data["BaseTarget"] = pull.BaseBranch
  428. ctx.Data["NumCommits"] = 0
  429. ctx.Data["NumFiles"] = 0
  430. return nil
  431. }
  432. ctx.ServerError("GetCompareInfo", err)
  433. return nil
  434. }
  435. if pull.IsWorkInProgress() {
  436. ctx.Data["IsPullWorkInProgress"] = true
  437. ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()
  438. }
  439. if pull.IsFilesConflicted() {
  440. ctx.Data["IsPullFilesConflicted"] = true
  441. ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
  442. }
  443. ctx.Data["NumCommits"] = compareInfo.Commits.Len()
  444. ctx.Data["NumFiles"] = compareInfo.NumFiles
  445. return compareInfo
  446. }
  447. // ViewPullCommits show commits for a pull request
  448. func ViewPullCommits(ctx *context.Context) {
  449. ctx.Data["PageIsPullList"] = true
  450. ctx.Data["PageIsPullCommits"] = true
  451. issue := checkPullInfo(ctx)
  452. if ctx.Written() {
  453. return
  454. }
  455. pull := issue.PullRequest
  456. var commits *list.List
  457. var prInfo *git.CompareInfo
  458. if pull.HasMerged {
  459. prInfo = PrepareMergedViewPullInfo(ctx, issue)
  460. } else {
  461. prInfo = PrepareViewPullInfo(ctx, issue)
  462. }
  463. if ctx.Written() {
  464. return
  465. } else if prInfo == nil {
  466. ctx.NotFound("ViewPullCommits", nil)
  467. return
  468. }
  469. ctx.Data["Username"] = ctx.Repo.Owner.Name
  470. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  471. commits = prInfo.Commits
  472. commits = models.ValidateCommitsWithEmails(commits)
  473. commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
  474. commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
  475. ctx.Data["Commits"] = commits
  476. ctx.Data["CommitCount"] = commits.Len()
  477. getBranchData(ctx, issue)
  478. ctx.HTML(200, tplPullCommits)
  479. }
  480. // ViewPullFiles render pull request changed files list page
  481. func ViewPullFiles(ctx *context.Context) {
  482. ctx.Data["PageIsPullList"] = true
  483. ctx.Data["PageIsPullFiles"] = true
  484. issue := checkPullInfo(ctx)
  485. if ctx.Written() {
  486. return
  487. }
  488. pull := issue.PullRequest
  489. whitespaceFlags := map[string]string{
  490. "ignore-all": "-w",
  491. "ignore-change": "-b",
  492. "ignore-eol": "--ignore-space-at-eol",
  493. "": ""}
  494. var (
  495. diffRepoPath string
  496. startCommitID string
  497. endCommitID string
  498. gitRepo *git.Repository
  499. )
  500. var headTarget string
  501. var prInfo *git.CompareInfo
  502. if pull.HasMerged {
  503. prInfo = PrepareMergedViewPullInfo(ctx, issue)
  504. } else {
  505. prInfo = PrepareViewPullInfo(ctx, issue)
  506. }
  507. if ctx.Written() {
  508. return
  509. } else if prInfo == nil {
  510. ctx.NotFound("ViewPullFiles", nil)
  511. return
  512. }
  513. diffRepoPath = ctx.Repo.GitRepo.Path
  514. gitRepo = ctx.Repo.GitRepo
  515. headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
  516. if err != nil {
  517. ctx.ServerError("GetRefCommitID", err)
  518. return
  519. }
  520. startCommitID = prInfo.MergeBase
  521. endCommitID = headCommitID
  522. headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
  523. ctx.Data["Username"] = ctx.Repo.Owner.Name
  524. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  525. ctx.Data["AfterCommitID"] = endCommitID
  526. diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,
  527. startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
  528. setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
  529. whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
  530. if err != nil {
  531. ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
  532. return
  533. }
  534. if err = diff.LoadComments(issue, ctx.User); err != nil {
  535. ctx.ServerError("LoadComments", err)
  536. return
  537. }
  538. ctx.Data["Diff"] = diff
  539. ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
  540. baseCommit, err := ctx.Repo.GitRepo.GetCommit(startCommitID)
  541. if err != nil {
  542. ctx.ServerError("GetCommit", err)
  543. return
  544. }
  545. commit, err := gitRepo.GetCommit(endCommitID)
  546. if err != nil {
  547. ctx.ServerError("GetCommit", err)
  548. return
  549. }
  550. if ctx.IsSigned && ctx.User != nil {
  551. if ctx.Data["CanMarkConversation"], err = models.CanMarkConversation(issue, ctx.User); err != nil {
  552. ctx.ServerError("CanMarkConversation", err)
  553. return
  554. }
  555. }
  556. setImageCompareContext(ctx, baseCommit, commit)
  557. setPathsCompareContext(ctx, baseCommit, commit, headTarget)
  558. ctx.Data["RequireHighlightJS"] = true
  559. ctx.Data["RequireSimpleMDE"] = true
  560. ctx.Data["RequireTribute"] = true
  561. if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil {
  562. ctx.ServerError("GetAssignees", err)
  563. return
  564. }
  565. ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.User, issue)
  566. if err != nil && !models.IsErrReviewNotExist(err) {
  567. ctx.ServerError("GetCurrentReview", err)
  568. return
  569. }
  570. getBranchData(ctx, issue)
  571. ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
  572. ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
  573. ctx.HTML(200, tplPullFiles)
  574. }
  575. // UpdatePullRequest merge PR's baseBranch into headBranch
  576. func UpdatePullRequest(ctx *context.Context) {
  577. issue := checkPullInfo(ctx)
  578. if ctx.Written() {
  579. return
  580. }
  581. if issue.IsClosed {
  582. ctx.NotFound("MergePullRequest", nil)
  583. return
  584. }
  585. if issue.PullRequest.HasMerged {
  586. ctx.NotFound("MergePullRequest", nil)
  587. return
  588. }
  589. if err := issue.PullRequest.LoadBaseRepo(); err != nil {
  590. ctx.InternalServerError(err)
  591. return
  592. }
  593. if err := issue.PullRequest.LoadHeadRepo(); err != nil {
  594. ctx.InternalServerError(err)
  595. return
  596. }
  597. allowedUpdate, err := pull_service.IsUserAllowedToUpdate(issue.PullRequest, ctx.User)
  598. if err != nil {
  599. ctx.ServerError("IsUserAllowedToMerge", err)
  600. return
  601. }
  602. // ToDo: add check if maintainers are allowed to change branch ... (need migration & co)
  603. if !allowedUpdate {
  604. ctx.Flash.Error(ctx.Tr("repo.pulls.update_not_allowed"))
  605. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  606. return
  607. }
  608. // default merge commit message
  609. message := fmt.Sprintf("Merge branch '%s' into %s", issue.PullRequest.BaseBranch, issue.PullRequest.HeadBranch)
  610. if err = pull_service.Update(issue.PullRequest, ctx.User, message); err != nil {
  611. if models.IsErrMergeConflicts(err) {
  612. conflictError := err.(models.ErrMergeConflicts)
  613. ctx.Flash.Error(ctx.Tr("repo.pulls.merge_conflict", utils.SanitizeFlashErrorString(conflictError.StdErr), utils.SanitizeFlashErrorString(conflictError.StdOut)))
  614. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  615. return
  616. }
  617. ctx.Flash.Error(err.Error())
  618. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  619. return
  620. }
  621. time.Sleep(1 * time.Second)
  622. ctx.Flash.Success(ctx.Tr("repo.pulls.update_branch_success"))
  623. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  624. }
  625. // MergePullRequest response for merging pull request
  626. func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
  627. issue := checkPullInfo(ctx)
  628. if ctx.Written() {
  629. return
  630. }
  631. if issue.IsClosed {
  632. if issue.IsPull {
  633. ctx.Flash.Error(ctx.Tr("repo.pulls.is_closed"))
  634. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  635. return
  636. }
  637. ctx.Flash.Error(ctx.Tr("repo.issues.closed_title"))
  638. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  639. return
  640. }
  641. pr := issue.PullRequest
  642. allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, ctx.Repo.Permission, ctx.User)
  643. if err != nil {
  644. ctx.ServerError("IsUserAllowedToMerge", err)
  645. return
  646. }
  647. if !allowedMerge {
  648. ctx.Flash.Error(ctx.Tr("repo.pulls.update_not_allowed"))
  649. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  650. return
  651. }
  652. if !pr.CanAutoMerge() {
  653. ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_not_ready"))
  654. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  655. return
  656. }
  657. if pr.HasMerged {
  658. ctx.Flash.Error(ctx.Tr("repo.pulls.has_merged"))
  659. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  660. return
  661. }
  662. if pr.IsWorkInProgress() {
  663. ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_wip"))
  664. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  665. return
  666. }
  667. if err := pull_service.CheckPRReadyToMerge(pr); err != nil {
  668. if !models.IsErrNotAllowedToMerge(err) {
  669. ctx.ServerError("Merge PR status", err)
  670. return
  671. }
  672. if isRepoAdmin, err := models.IsUserRepoAdmin(pr.BaseRepo, ctx.User); err != nil {
  673. ctx.ServerError("IsUserRepoAdmin", err)
  674. return
  675. } else if !isRepoAdmin {
  676. ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_not_ready"))
  677. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  678. return
  679. }
  680. }
  681. if ctx.HasError() {
  682. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  683. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  684. return
  685. }
  686. message := strings.TrimSpace(form.MergeTitleField)
  687. if len(message) == 0 {
  688. if models.MergeStyle(form.Do) == models.MergeStyleMerge {
  689. message = pr.GetDefaultMergeMessage()
  690. }
  691. if models.MergeStyle(form.Do) == models.MergeStyleRebaseMerge {
  692. message = pr.GetDefaultMergeMessage()
  693. }
  694. if models.MergeStyle(form.Do) == models.MergeStyleSquash {
  695. message = pr.GetDefaultSquashMessage()
  696. }
  697. }
  698. form.MergeMessageField = strings.TrimSpace(form.MergeMessageField)
  699. if len(form.MergeMessageField) > 0 {
  700. message += "\n\n" + form.MergeMessageField
  701. }
  702. pr.Issue = issue
  703. pr.Issue.Repo = ctx.Repo.Repository
  704. noDeps, err := models.IssueNoDependenciesLeft(issue)
  705. if err != nil {
  706. return
  707. }
  708. if !noDeps {
  709. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
  710. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  711. return
  712. }
  713. if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
  714. if models.IsErrInvalidMergeStyle(err) {
  715. ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
  716. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  717. return
  718. } else if models.IsErrMergeConflicts(err) {
  719. conflictError := err.(models.ErrMergeConflicts)
  720. ctx.Flash.Error(ctx.Tr("repo.pulls.merge_conflict", utils.SanitizeFlashErrorString(conflictError.StdErr), utils.SanitizeFlashErrorString(conflictError.StdOut)))
  721. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  722. return
  723. } else if models.IsErrRebaseConflicts(err) {
  724. conflictError := err.(models.ErrRebaseConflicts)
  725. ctx.Flash.Error(ctx.Tr("repo.pulls.rebase_conflict", utils.SanitizeFlashErrorString(conflictError.CommitSHA), utils.SanitizeFlashErrorString(conflictError.StdErr), utils.SanitizeFlashErrorString(conflictError.StdOut)))
  726. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  727. return
  728. } else if models.IsErrMergeUnrelatedHistories(err) {
  729. log.Debug("MergeUnrelatedHistories error: %v", err)
  730. ctx.Flash.Error(ctx.Tr("repo.pulls.unrelated_histories"))
  731. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  732. return
  733. } else if git.IsErrPushOutOfDate(err) {
  734. log.Debug("MergePushOutOfDate error: %v", err)
  735. ctx.Flash.Error(ctx.Tr("repo.pulls.merge_out_of_date"))
  736. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  737. return
  738. } else if git.IsErrPushRejected(err) {
  739. log.Debug("MergePushRejected error: %v", err)
  740. pushrejErr := err.(*git.ErrPushRejected)
  741. message := pushrejErr.Message
  742. if len(message) == 0 {
  743. ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected_no_message"))
  744. } else {
  745. ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected", utils.SanitizeFlashErrorString(pushrejErr.Message)))
  746. }
  747. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  748. return
  749. }
  750. ctx.ServerError("Merge", err)
  751. return
  752. }
  753. if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
  754. ctx.ServerError("CreateOrStopIssueStopwatch", err)
  755. return
  756. }
  757. log.Trace("Pull request merged: %d", pr.ID)
  758. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
  759. }
  760. func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
  761. if models.StopwatchExists(user.ID, issue.ID) {
  762. if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
  763. return err
  764. }
  765. }
  766. return nil
  767. }
  768. // CompareAndPullRequestPost response for creating pull request
  769. func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) {
  770. ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
  771. ctx.Data["PageIsComparePull"] = true
  772. ctx.Data["IsDiffCompare"] = true
  773. ctx.Data["RequireHighlightJS"] = true
  774. ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
  775. renderAttachmentSettings(ctx)
  776. var (
  777. repo = ctx.Repo.Repository
  778. attachments []string
  779. )
  780. headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
  781. if ctx.Written() {
  782. return
  783. }
  784. defer headGitRepo.Close()
  785. labelIDs, assigneeIDs, milestoneID, _ := ValidateRepoMetas(ctx, form, true)
  786. if ctx.Written() {
  787. return
  788. }
  789. if setting.Attachment.Enabled {
  790. attachments = form.Files
  791. }
  792. if ctx.HasError() {
  793. auth.AssignForm(form, ctx.Data)
  794. // This stage is already stop creating new pull request, so it does not matter if it has
  795. // something to compare or not.
  796. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  797. if ctx.Written() {
  798. return
  799. }
  800. ctx.HTML(200, tplCompareDiff)
  801. return
  802. }
  803. if util.IsEmptyString(form.Title) {
  804. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  805. if ctx.Written() {
  806. return
  807. }
  808. ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplCompareDiff, form)
  809. return
  810. }
  811. pullIssue := &models.Issue{
  812. RepoID: repo.ID,
  813. Title: form.Title,
  814. PosterID: ctx.User.ID,
  815. Poster: ctx.User,
  816. MilestoneID: milestoneID,
  817. IsPull: true,
  818. Content: form.Content,
  819. }
  820. pullRequest := &models.PullRequest{
  821. HeadRepoID: headRepo.ID,
  822. BaseRepoID: repo.ID,
  823. HeadBranch: headBranch,
  824. BaseBranch: baseBranch,
  825. HeadRepo: headRepo,
  826. BaseRepo: repo,
  827. MergeBase: prInfo.MergeBase,
  828. Type: models.PullRequestGitea,
  829. }
  830. // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
  831. // instead of 500.
  832. if err := pull_service.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil {
  833. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  834. ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
  835. return
  836. } else if git.IsErrPushRejected(err) {
  837. pushrejErr := err.(*git.ErrPushRejected)
  838. message := pushrejErr.Message
  839. if len(message) == 0 {
  840. ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected_no_message"))
  841. } else {
  842. ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected", utils.SanitizeFlashErrorString(pushrejErr.Message)))
  843. }
  844. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
  845. return
  846. }
  847. ctx.ServerError("NewPullRequest", err)
  848. return
  849. }
  850. log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
  851. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
  852. }
  853. // TriggerTask response for a trigger task request
  854. func TriggerTask(ctx *context.Context) {
  855. pusherID := ctx.QueryInt64("pusher")
  856. branch := ctx.Query("branch")
  857. secret := ctx.Query("secret")
  858. if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 {
  859. ctx.Error(404)
  860. log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid")
  861. return
  862. }
  863. owner, repo := parseOwnerAndRepo(ctx)
  864. if ctx.Written() {
  865. return
  866. }
  867. got := []byte(base.EncodeMD5(owner.Salt))
  868. want := []byte(secret)
  869. if subtle.ConstantTimeCompare(got, want) != 1 {
  870. ctx.Error(404)
  871. log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
  872. return
  873. }
  874. pusher, err := models.GetUserByID(pusherID)
  875. if err != nil {
  876. if models.IsErrUserNotExist(err) {
  877. ctx.Error(404)
  878. } else {
  879. ctx.ServerError("GetUserByID", err)
  880. }
  881. return
  882. }
  883. log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
  884. go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, "", "")
  885. ctx.Status(202)
  886. }
  887. // CleanUpPullRequest responses for delete merged branch when PR has been merged
  888. func CleanUpPullRequest(ctx *context.Context) {
  889. issue := checkPullInfo(ctx)
  890. if ctx.Written() {
  891. return
  892. }
  893. pr := issue.PullRequest
  894. // Don't cleanup unmerged and unclosed PRs
  895. if !pr.HasMerged && !issue.IsClosed {
  896. ctx.NotFound("CleanUpPullRequest", nil)
  897. return
  898. }
  899. if err := pr.LoadHeadRepo(); err != nil {
  900. ctx.ServerError("LoadHeadRepo", err)
  901. return
  902. } else if pr.HeadRepo == nil {
  903. // Forked repository has already been deleted
  904. ctx.NotFound("CleanUpPullRequest", nil)
  905. return
  906. } else if err = pr.LoadBaseRepo(); err != nil {
  907. ctx.ServerError("LoadBaseRepo", err)
  908. return
  909. } else if err = pr.HeadRepo.GetOwner(); err != nil {
  910. ctx.ServerError("HeadRepo.GetOwner", err)
  911. return
  912. }
  913. perm, err := models.GetUserRepoPermission(pr.HeadRepo, ctx.User)
  914. if err != nil {
  915. ctx.ServerError("GetUserRepoPermission", err)
  916. return
  917. }
  918. if !perm.CanWrite(models.UnitTypeCode) {
  919. ctx.NotFound("CleanUpPullRequest", nil)
  920. return
  921. }
  922. fullBranchName := pr.HeadRepo.Owner.Name + "/" + pr.HeadBranch
  923. gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  924. if err != nil {
  925. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
  926. return
  927. }
  928. defer gitRepo.Close()
  929. gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
  930. if err != nil {
  931. ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
  932. return
  933. }
  934. defer gitBaseRepo.Close()
  935. defer func() {
  936. ctx.JSON(200, map[string]interface{}{
  937. "redirect": pr.BaseRepo.Link() + "/pulls/" + com.ToStr(issue.Index),
  938. })
  939. }()
  940. if pr.HeadBranch == pr.HeadRepo.DefaultBranch || !gitRepo.IsBranchExist(pr.HeadBranch) {
  941. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  942. return
  943. }
  944. // Check if branch is not protected
  945. if protected, err := pr.HeadRepo.IsProtectedBranch(pr.HeadBranch, ctx.User); err != nil || protected {
  946. if err != nil {
  947. log.Error("HeadRepo.IsProtectedBranch: %v", err)
  948. }
  949. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  950. return
  951. }
  952. // Check if branch has no new commits
  953. headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
  954. if err != nil {
  955. log.Error("GetRefCommitID: %v", err)
  956. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  957. return
  958. }
  959. branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
  960. if err != nil {
  961. log.Error("GetBranchCommitID: %v", err)
  962. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  963. return
  964. }
  965. if headCommitID != branchCommitID {
  966. ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName))
  967. return
  968. }
  969. if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
  970. Force: true,
  971. }); err != nil {
  972. log.Error("DeleteBranch: %v", err)
  973. ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
  974. return
  975. }
  976. if err := repo_service.PushUpdate(
  977. &repo_service.PushUpdateOptions{
  978. RefFullName: git.BranchPrefix + pr.HeadBranch,
  979. OldCommitID: branchCommitID,
  980. NewCommitID: git.EmptySHA,
  981. PusherID: ctx.User.ID,
  982. PusherName: ctx.User.Name,
  983. RepoUserName: pr.HeadRepo.Owner.Name,
  984. RepoName: pr.HeadRepo.Name,
  985. }); err != nil {
  986. log.Error("Update: %v", err)
  987. }
  988. if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, issue.ID, pr.HeadBranch); err != nil {
  989. // Do not fail here as branch has already been deleted
  990. log.Error("DeleteBranch: %v", err)
  991. }
  992. ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))
  993. }
  994. // DownloadPullDiff render a pull's raw diff
  995. func DownloadPullDiff(ctx *context.Context) {
  996. DownloadPullDiffOrPatch(ctx, false)
  997. }
  998. // DownloadPullPatch render a pull's raw patch
  999. func DownloadPullPatch(ctx *context.Context) {
  1000. DownloadPullDiffOrPatch(ctx, true)
  1001. }
  1002. // DownloadPullDiffOrPatch render a pull's raw diff or patch
  1003. func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
  1004. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  1005. if err != nil {
  1006. if models.IsErrIssueNotExist(err) {
  1007. ctx.NotFound("GetIssueByIndex", err)
  1008. } else {
  1009. ctx.ServerError("GetIssueByIndex", err)
  1010. }
  1011. return
  1012. }
  1013. // Return not found if it's not a pull request
  1014. if !issue.IsPull {
  1015. ctx.NotFound("DownloadPullDiff",
  1016. fmt.Errorf("Issue is not a pull request"))
  1017. return
  1018. }
  1019. if err = issue.LoadPullRequest(); err != nil {
  1020. ctx.ServerError("LoadPullRequest", err)
  1021. return
  1022. }
  1023. pr := issue.PullRequest
  1024. if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch); err != nil {
  1025. ctx.ServerError("DownloadDiffOrPatch", err)
  1026. return
  1027. }
  1028. }
  1029. // UpdatePullRequestTarget change pull request's target branch
  1030. func UpdatePullRequestTarget(ctx *context.Context) {
  1031. issue := GetActionIssue(ctx)
  1032. pr := issue.PullRequest
  1033. if ctx.Written() {
  1034. return
  1035. }
  1036. if !issue.IsPull {
  1037. ctx.Error(http.StatusNotFound)
  1038. return
  1039. }
  1040. if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
  1041. ctx.Error(http.StatusForbidden)
  1042. return
  1043. }
  1044. targetBranch := ctx.QueryTrim("target_branch")
  1045. if len(targetBranch) == 0 {
  1046. ctx.Error(http.StatusNoContent)
  1047. return
  1048. }
  1049. if err := pull_service.ChangeTargetBranch(pr, ctx.User, targetBranch); err != nil {
  1050. if models.IsErrPullRequestAlreadyExists(err) {
  1051. err := err.(models.ErrPullRequestAlreadyExists)
  1052. RepoRelPath := ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
  1053. errorMessage := ctx.Tr("repo.pulls.has_pull_request", ctx.Repo.RepoLink, RepoRelPath, err.IssueID)
  1054. ctx.Flash.Error(errorMessage)
  1055. ctx.JSON(http.StatusConflict, map[string]interface{}{
  1056. "error": err.Error(),
  1057. "user_error": errorMessage,
  1058. })
  1059. } else if models.IsErrIssueIsClosed(err) {
  1060. errorMessage := ctx.Tr("repo.pulls.is_closed")
  1061. ctx.Flash.Error(errorMessage)
  1062. ctx.JSON(http.StatusConflict, map[string]interface{}{
  1063. "error": err.Error(),
  1064. "user_error": errorMessage,
  1065. })
  1066. } else if models.IsErrPullRequestHasMerged(err) {
  1067. errorMessage := ctx.Tr("repo.pulls.has_merged")
  1068. ctx.Flash.Error(errorMessage)
  1069. ctx.JSON(http.StatusConflict, map[string]interface{}{
  1070. "error": err.Error(),
  1071. "user_error": errorMessage,
  1072. })
  1073. } else if models.IsErrBranchesEqual(err) {
  1074. errorMessage := ctx.Tr("repo.pulls.nothing_to_compare")
  1075. ctx.Flash.Error(errorMessage)
  1076. ctx.JSON(http.StatusBadRequest, map[string]interface{}{
  1077. "error": err.Error(),
  1078. "user_error": errorMessage,
  1079. })
  1080. } else {
  1081. ctx.ServerError("UpdatePullRequestTarget", err)
  1082. }
  1083. return
  1084. }
  1085. notification.NotifyPullRequestChangeTargetBranch(ctx.User, pr, targetBranch)
  1086. ctx.JSON(http.StatusOK, map[string]interface{}{
  1087. "base_branch": pr.BaseBranch,
  1088. })
  1089. }