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

pull.go 35 kB

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