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

1402 lines
42 KiB

Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
Pull request review/approval and comment on code (#3748) * Initial ui components for pull request review * Add Review Add IssueComment types Signed-off-by: Jonas Franz <info@jonasfranz.software> (cherry picked from commit 2b4daab) Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace ReviewComment with Content Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add load functions Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add create review comment implementation Add migration for review Other small changes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Simplified create and find functions for review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved "Pending" to first position Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add GetCurrentReview to simplify fetching current review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Preview for listing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Move new comment form to its own file Signed-off-by: Jonas Franz <info@jonasfranz.software> * Implement Review form Show Review comments on comment stream Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for single comments Showing buttons in context Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add pending tag to pending review comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add unit tests for Review Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fetch all review ids at once Add unit tests Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improved comment rendering in "Files" view by adding Comments to DiffLine Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for invalidating comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Switched back to code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Moved review migration from v64 to v65 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Rebuild css Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Improve translations Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests by updating fixtures and updating outdated test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Comments will be shown at the right place now Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for deleting CodeComments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems caused by files in subdirectories Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for showing code comments of reviews in conversation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for "Show/Hide outdated" Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update code.gitea.io/git Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add support for new webhooks Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update comparison Signed-off-by: Jonas Franz <info@jonasfranz.software> * Resolve conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Minor UI improvements * update code.gitea.io/git * Fix ui bug reported by @lunny causing wrong position of add button Add functionality to "Cancel" button Add scale effects to add button Hide "Cancel" button for existing comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Prepare solving conflicts Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show add button only if no comments already exist for the line Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing vendor files Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if reviewer is nil Signed-off-by: Jonas Franz <info@jonasfranz.software> * Show forms only to users who are logged in Signed-off-by: Jonas Franz <info@jonasfranz.software> * Revert "Show forms only to users who are logged in" This reverts commit c083682 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Save patch in comment Render patch for code comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add link to comment in code Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add reply form to comment list Show forms only to signed in users Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix problems introduced by checking for singed in user Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add v70 Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update generated stylesheet Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix preview Beginn with new review comment patch system Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add new algo to generate diff for line range Remove old algo used for cutting big diffs (it was very buggy) * Add documentation and example for CutDiffAroundLine * Fix example of CutDiffAroundLine * Fix some comment UI rendering bugs * Add code comment edit mode * Send notifications / actions to users until review gets published Fix diff generation bug Fix wrong hashtag * Fix vet errors * Send notifications also for single comments * Fix some notification bugs, fix link * Fix: add comment icon is only shown on code lines * Add lint comment * Add unit tests for git diff * Add more error messages * Regenerated css Signed-off-by: Jonas Franz <info@jonasfranz.software> * fmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Regenerated CSS with latest less version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by updating comment type to new ID Signed-off-by: Jonas Franz <info@jonasfranz.software> * Introducing CodeComments as type for map[string]map[int64][]*Comment Other minor code improvements Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix data-tab issues Signed-off-by: Jonas Franz <info@jonasfranz.software> * Remove unnecessary change Signed-off-by: Jonas Franz <info@jonasfranz.software> * refactored checkForInvalidation Signed-off-by: Jonas Franz <info@jonasfranz.software> * Append comments instead of setting Signed-off-by: Jonas Franz <info@jonasfranz.software> * Use HeadRepo instead of BaseRepo Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update migration Signed-off-by: Jonas Franz <info@jonasfranz.de> * Regenerated CSS Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add copyright Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update index.css Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "io/ioutil"
  8. "os"
  9. "path"
  10. "path/filepath"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "code.gitea.io/git"
  15. "code.gitea.io/gitea/modules/base"
  16. "code.gitea.io/gitea/modules/cache"
  17. "code.gitea.io/gitea/modules/log"
  18. "code.gitea.io/gitea/modules/process"
  19. "code.gitea.io/gitea/modules/setting"
  20. "code.gitea.io/gitea/modules/sync"
  21. "code.gitea.io/gitea/modules/util"
  22. api "code.gitea.io/sdk/gitea"
  23. "github.com/Unknwon/com"
  24. "github.com/go-xorm/xorm"
  25. )
  26. var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)
  27. // PullRequestType defines pull request type
  28. type PullRequestType int
  29. // Enumerate all the pull request types
  30. const (
  31. PullRequestGitea PullRequestType = iota
  32. PullRequestGit
  33. )
  34. // PullRequestStatus defines pull request status
  35. type PullRequestStatus int
  36. // Enumerate all the pull request status
  37. const (
  38. PullRequestStatusConflict PullRequestStatus = iota
  39. PullRequestStatusChecking
  40. PullRequestStatusMergeable
  41. PullRequestStatusManuallyMerged
  42. )
  43. // PullRequest represents relation between pull request and repositories.
  44. type PullRequest struct {
  45. ID int64 `xorm:"pk autoincr"`
  46. Type PullRequestType
  47. Status PullRequestStatus
  48. IssueID int64 `xorm:"INDEX"`
  49. Issue *Issue `xorm:"-"`
  50. Index int64
  51. HeadRepoID int64 `xorm:"INDEX"`
  52. HeadRepo *Repository `xorm:"-"`
  53. BaseRepoID int64 `xorm:"INDEX"`
  54. BaseRepo *Repository `xorm:"-"`
  55. HeadUserName string
  56. HeadBranch string
  57. BaseBranch string
  58. ProtectedBranch *ProtectedBranch `xorm:"-"`
  59. MergeBase string `xorm:"VARCHAR(40)"`
  60. HasMerged bool `xorm:"INDEX"`
  61. MergedCommitID string `xorm:"VARCHAR(40)"`
  62. MergerID int64 `xorm:"INDEX"`
  63. Merger *User `xorm:"-"`
  64. MergedUnix util.TimeStamp `xorm:"updated INDEX"`
  65. }
  66. // Note: don't try to get Issue because will end up recursive querying.
  67. func (pr *PullRequest) loadAttributes(e Engine) (err error) {
  68. if pr.HasMerged && pr.Merger == nil {
  69. pr.Merger, err = getUserByID(e, pr.MergerID)
  70. if IsErrUserNotExist(err) {
  71. pr.MergerID = -1
  72. pr.Merger = NewGhostUser()
  73. } else if err != nil {
  74. return fmt.Errorf("getUserByID [%d]: %v", pr.MergerID, err)
  75. }
  76. }
  77. return nil
  78. }
  79. // LoadAttributes loads pull request attributes from database
  80. func (pr *PullRequest) LoadAttributes() error {
  81. return pr.loadAttributes(x)
  82. }
  83. // LoadIssue loads issue information from database
  84. func (pr *PullRequest) LoadIssue() (err error) {
  85. return pr.loadIssue(x)
  86. }
  87. func (pr *PullRequest) loadIssue(e Engine) (err error) {
  88. if pr.Issue != nil {
  89. return nil
  90. }
  91. pr.Issue, err = getIssueByID(e, pr.IssueID)
  92. return err
  93. }
  94. // LoadProtectedBranch loads the protected branch of the base branch
  95. func (pr *PullRequest) LoadProtectedBranch() (err error) {
  96. if pr.BaseRepo == nil {
  97. if pr.BaseRepoID == 0 {
  98. return nil
  99. }
  100. pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
  101. if err != nil {
  102. return
  103. }
  104. }
  105. pr.ProtectedBranch, err = GetProtectedBranchBy(pr.BaseRepo.ID, pr.BaseBranch)
  106. return
  107. }
  108. // GetDefaultMergeMessage returns default message used when merging pull request
  109. func (pr *PullRequest) GetDefaultMergeMessage() string {
  110. if pr.HeadRepo == nil {
  111. var err error
  112. pr.HeadRepo, err = GetRepositoryByID(pr.HeadRepoID)
  113. if err != nil {
  114. log.Error(4, "GetRepositoryById[%d]: %v", pr.HeadRepoID, err)
  115. return ""
  116. }
  117. }
  118. return fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.HeadUserName, pr.HeadRepo.Name, pr.BaseBranch)
  119. }
  120. // GetDefaultSquashMessage returns default message used when squash and merging pull request
  121. func (pr *PullRequest) GetDefaultSquashMessage() string {
  122. if err := pr.LoadIssue(); err != nil {
  123. log.Error(4, "LoadIssue: %v", err)
  124. return ""
  125. }
  126. return fmt.Sprintf("%s (#%d)", pr.Issue.Title, pr.Issue.Index)
  127. }
  128. // GetGitRefName returns git ref for hidden pull request branch
  129. func (pr *PullRequest) GetGitRefName() string {
  130. return fmt.Sprintf("refs/pull/%d/head", pr.Index)
  131. }
  132. // APIFormat assumes following fields have been assigned with valid values:
  133. // Required - Issue
  134. // Optional - Merger
  135. func (pr *PullRequest) APIFormat() *api.PullRequest {
  136. return pr.apiFormat(x)
  137. }
  138. func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
  139. var (
  140. baseBranch *Branch
  141. headBranch *Branch
  142. baseCommit *git.Commit
  143. headCommit *git.Commit
  144. err error
  145. )
  146. if err = pr.Issue.loadRepo(e); err != nil {
  147. log.Error(log.ERROR, "loadRepo[%d]: %v", pr.ID, err)
  148. return nil
  149. }
  150. apiIssue := pr.Issue.apiFormat(e)
  151. if pr.BaseRepo == nil {
  152. pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
  153. if err != nil {
  154. log.Error(log.ERROR, "GetRepositoryById[%d]: %v", pr.ID, err)
  155. return nil
  156. }
  157. }
  158. if pr.HeadRepo == nil {
  159. pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
  160. if err != nil {
  161. log.Error(log.ERROR, "GetRepositoryById[%d]: %v", pr.ID, err)
  162. return nil
  163. }
  164. }
  165. if baseBranch, err = pr.BaseRepo.GetBranch(pr.BaseBranch); err != nil {
  166. return nil
  167. }
  168. if baseCommit, err = baseBranch.GetCommit(); err != nil {
  169. return nil
  170. }
  171. if headBranch, err = pr.HeadRepo.GetBranch(pr.HeadBranch); err != nil {
  172. return nil
  173. }
  174. if headCommit, err = headBranch.GetCommit(); err != nil {
  175. return nil
  176. }
  177. apiBaseBranchInfo := &api.PRBranchInfo{
  178. Name: pr.BaseBranch,
  179. Ref: pr.BaseBranch,
  180. Sha: baseCommit.ID.String(),
  181. RepoID: pr.BaseRepoID,
  182. Repository: pr.BaseRepo.innerAPIFormat(e, AccessModeNone, false),
  183. }
  184. apiHeadBranchInfo := &api.PRBranchInfo{
  185. Name: pr.HeadBranch,
  186. Ref: pr.HeadBranch,
  187. Sha: headCommit.ID.String(),
  188. RepoID: pr.HeadRepoID,
  189. Repository: pr.HeadRepo.innerAPIFormat(e, AccessModeNone, false),
  190. }
  191. pr.Issue.loadRepo(e)
  192. apiPullRequest := &api.PullRequest{
  193. ID: pr.ID,
  194. Index: pr.Index,
  195. Poster: apiIssue.Poster,
  196. Title: apiIssue.Title,
  197. Body: apiIssue.Body,
  198. Labels: apiIssue.Labels,
  199. Milestone: apiIssue.Milestone,
  200. Assignee: apiIssue.Assignee,
  201. Assignees: apiIssue.Assignees,
  202. State: apiIssue.State,
  203. Comments: apiIssue.Comments,
  204. HTMLURL: pr.Issue.HTMLURL(),
  205. DiffURL: pr.Issue.DiffURL(),
  206. PatchURL: pr.Issue.PatchURL(),
  207. HasMerged: pr.HasMerged,
  208. Base: apiBaseBranchInfo,
  209. Head: apiHeadBranchInfo,
  210. MergeBase: pr.MergeBase,
  211. Deadline: apiIssue.Deadline,
  212. Created: pr.Issue.CreatedUnix.AsTimePtr(),
  213. Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
  214. }
  215. if pr.Status != PullRequestStatusChecking {
  216. mergeable := pr.Status != PullRequestStatusConflict && !pr.IsWorkInProgress()
  217. apiPullRequest.Mergeable = mergeable
  218. }
  219. if pr.HasMerged {
  220. apiPullRequest.Merged = pr.MergedUnix.AsTimePtr()
  221. apiPullRequest.MergedCommitID = &pr.MergedCommitID
  222. apiPullRequest.MergedBy = pr.Merger.APIFormat()
  223. }
  224. return apiPullRequest
  225. }
  226. func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
  227. pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
  228. if err != nil && !IsErrRepoNotExist(err) {
  229. return fmt.Errorf("getRepositoryByID(head): %v", err)
  230. }
  231. return nil
  232. }
  233. // GetHeadRepo loads the head repository
  234. func (pr *PullRequest) GetHeadRepo() error {
  235. return pr.getHeadRepo(x)
  236. }
  237. // GetBaseRepo loads the target repository
  238. func (pr *PullRequest) GetBaseRepo() (err error) {
  239. if pr.BaseRepo != nil {
  240. return nil
  241. }
  242. pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
  243. if err != nil {
  244. return fmt.Errorf("GetRepositoryByID(base): %v", err)
  245. }
  246. return nil
  247. }
  248. // IsChecking returns true if this pull request is still checking conflict.
  249. func (pr *PullRequest) IsChecking() bool {
  250. return pr.Status == PullRequestStatusChecking
  251. }
  252. // CanAutoMerge returns true if this pull request can be merged automatically.
  253. func (pr *PullRequest) CanAutoMerge() bool {
  254. return pr.Status == PullRequestStatusMergeable
  255. }
  256. // MergeStyle represents the approach to merge commits into base branch.
  257. type MergeStyle string
  258. const (
  259. // MergeStyleMerge create merge commit
  260. MergeStyleMerge MergeStyle = "merge"
  261. // MergeStyleRebase rebase before merging
  262. MergeStyleRebase MergeStyle = "rebase"
  263. // MergeStyleRebaseMerge rebase before merging with merge commit (--no-ff)
  264. MergeStyleRebaseMerge MergeStyle = "rebase-merge"
  265. // MergeStyleSquash squash commits into single commit before merging
  266. MergeStyleSquash MergeStyle = "squash"
  267. )
  268. // CheckUserAllowedToMerge checks whether the user is allowed to merge
  269. func (pr *PullRequest) CheckUserAllowedToMerge(doer *User) (err error) {
  270. if doer == nil {
  271. return ErrNotAllowedToMerge{
  272. "Not signed in",
  273. }
  274. }
  275. if pr.BaseRepo == nil {
  276. if err = pr.GetBaseRepo(); err != nil {
  277. return fmt.Errorf("GetBaseRepo: %v", err)
  278. }
  279. }
  280. if protected, err := pr.BaseRepo.IsProtectedBranchForMerging(pr, pr.BaseBranch, doer); err != nil {
  281. return fmt.Errorf("IsProtectedBranch: %v", err)
  282. } else if protected {
  283. return ErrNotAllowedToMerge{
  284. "The branch is protected",
  285. }
  286. }
  287. return nil
  288. }
  289. // Merge merges pull request to base repository.
  290. // FIXME: add repoWorkingPull make sure two merges does not happen at same time.
  291. func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle MergeStyle, message string) (err error) {
  292. if err = pr.GetHeadRepo(); err != nil {
  293. return fmt.Errorf("GetHeadRepo: %v", err)
  294. } else if err = pr.GetBaseRepo(); err != nil {
  295. return fmt.Errorf("GetBaseRepo: %v", err)
  296. }
  297. prUnit, err := pr.BaseRepo.GetUnit(UnitTypePullRequests)
  298. if err != nil {
  299. return err
  300. }
  301. prConfig := prUnit.PullRequestsConfig()
  302. if err := pr.CheckUserAllowedToMerge(doer); err != nil {
  303. return fmt.Errorf("CheckUserAllowedToMerge: %v", err)
  304. }
  305. // Check if merge style is correct and allowed
  306. if !prConfig.IsMergeStyleAllowed(mergeStyle) {
  307. return ErrInvalidMergeStyle{pr.BaseRepo.ID, mergeStyle}
  308. }
  309. defer func() {
  310. go HookQueue.Add(pr.BaseRepo.ID)
  311. go AddTestPullRequestTask(doer, pr.BaseRepo.ID, pr.BaseBranch, false)
  312. }()
  313. headRepoPath := RepoPath(pr.HeadUserName, pr.HeadRepo.Name)
  314. // Clone base repo.
  315. tmpBasePath := path.Join(LocalCopyPath(), "merge-"+com.ToStr(time.Now().Nanosecond())+".git")
  316. if err := os.MkdirAll(path.Dir(tmpBasePath), os.ModePerm); err != nil {
  317. return fmt.Errorf("Failed to create dir %s: %v", tmpBasePath, err)
  318. }
  319. defer os.RemoveAll(path.Dir(tmpBasePath))
  320. var stderr string
  321. if _, stderr, err = process.GetManager().ExecTimeout(5*time.Minute,
  322. fmt.Sprintf("PullRequest.Merge (git clone): %s", tmpBasePath),
  323. "git", "clone", baseGitRepo.Path, tmpBasePath); err != nil {
  324. return fmt.Errorf("git clone: %s", stderr)
  325. }
  326. // Check out base branch.
  327. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  328. fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
  329. "git", "checkout", pr.BaseBranch); err != nil {
  330. return fmt.Errorf("git checkout: %s", stderr)
  331. }
  332. // Add head repo remote.
  333. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  334. fmt.Sprintf("PullRequest.Merge (git remote add): %s", tmpBasePath),
  335. "git", "remote", "add", "head_repo", headRepoPath); err != nil {
  336. return fmt.Errorf("git remote add [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  337. }
  338. // Merge commits.
  339. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  340. fmt.Sprintf("PullRequest.Merge (git fetch): %s", tmpBasePath),
  341. "git", "fetch", "head_repo"); err != nil {
  342. return fmt.Errorf("git fetch [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  343. }
  344. switch mergeStyle {
  345. case MergeStyleMerge:
  346. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  347. fmt.Sprintf("PullRequest.Merge (git merge --no-ff --no-commit): %s", tmpBasePath),
  348. "git", "merge", "--no-ff", "--no-commit", "head_repo/"+pr.HeadBranch); err != nil {
  349. return fmt.Errorf("git merge --no-ff --no-commit [%s]: %v - %s", tmpBasePath, err, stderr)
  350. }
  351. sig := doer.NewGitSig()
  352. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  353. fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
  354. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  355. "-m", message); err != nil {
  356. return fmt.Errorf("git commit [%s]: %v - %s", tmpBasePath, err, stderr)
  357. }
  358. case MergeStyleRebase:
  359. // Checkout head branch
  360. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  361. fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
  362. "git", "checkout", "-b", "head_repo_"+pr.HeadBranch, "head_repo/"+pr.HeadBranch); err != nil {
  363. return fmt.Errorf("git checkout: %s", stderr)
  364. }
  365. // Rebase before merging
  366. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  367. fmt.Sprintf("PullRequest.Merge (git rebase): %s", tmpBasePath),
  368. "git", "rebase", "-q", pr.BaseBranch); err != nil {
  369. return fmt.Errorf("git rebase [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  370. }
  371. // Checkout base branch again
  372. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  373. fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
  374. "git", "checkout", pr.BaseBranch); err != nil {
  375. return fmt.Errorf("git checkout: %s", stderr)
  376. }
  377. // Merge fast forward
  378. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  379. fmt.Sprintf("PullRequest.Merge (git rebase): %s", tmpBasePath),
  380. "git", "merge", "--ff-only", "-q", "head_repo_"+pr.HeadBranch); err != nil {
  381. return fmt.Errorf("git merge --ff-only [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  382. }
  383. case MergeStyleRebaseMerge:
  384. // Checkout head branch
  385. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  386. fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
  387. "git", "checkout", "-b", "head_repo_"+pr.HeadBranch, "head_repo/"+pr.HeadBranch); err != nil {
  388. return fmt.Errorf("git checkout: %s", stderr)
  389. }
  390. // Rebase before merging
  391. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  392. fmt.Sprintf("PullRequest.Merge (git rebase): %s", tmpBasePath),
  393. "git", "rebase", "-q", pr.BaseBranch); err != nil {
  394. return fmt.Errorf("git rebase [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  395. }
  396. // Checkout base branch again
  397. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  398. fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
  399. "git", "checkout", pr.BaseBranch); err != nil {
  400. return fmt.Errorf("git checkout: %s", stderr)
  401. }
  402. // Prepare merge with commit
  403. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  404. fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
  405. "git", "merge", "--no-ff", "--no-commit", "-q", "head_repo_"+pr.HeadBranch); err != nil {
  406. return fmt.Errorf("git merge --no-ff [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  407. }
  408. // Set custom message and author and create merge commit
  409. sig := doer.NewGitSig()
  410. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  411. fmt.Sprintf("PullRequest.Merge (git commit): %s", tmpBasePath),
  412. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  413. "-m", message); err != nil {
  414. return fmt.Errorf("git commit [%s]: %v - %s", tmpBasePath, err, stderr)
  415. }
  416. case MergeStyleSquash:
  417. // Merge with squash
  418. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  419. fmt.Sprintf("PullRequest.Merge (git squash): %s", tmpBasePath),
  420. "git", "merge", "-q", "--squash", "head_repo/"+pr.HeadBranch); err != nil {
  421. return fmt.Errorf("git merge --squash [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
  422. }
  423. sig := pr.Issue.Poster.NewGitSig()
  424. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  425. fmt.Sprintf("PullRequest.Merge (git squash): %s", tmpBasePath),
  426. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  427. "-m", message); err != nil {
  428. return fmt.Errorf("git commit [%s]: %v - %s", tmpBasePath, err, stderr)
  429. }
  430. default:
  431. return ErrInvalidMergeStyle{pr.BaseRepo.ID, mergeStyle}
  432. }
  433. // Push back to upstream.
  434. if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
  435. fmt.Sprintf("PullRequest.Merge (git push): %s", tmpBasePath),
  436. "git", "push", baseGitRepo.Path, pr.BaseBranch); err != nil {
  437. return fmt.Errorf("git push: %s", stderr)
  438. }
  439. pr.MergedCommitID, err = baseGitRepo.GetBranchCommitID(pr.BaseBranch)
  440. if err != nil {
  441. return fmt.Errorf("GetBranchCommit: %v", err)
  442. }
  443. pr.MergedUnix = util.TimeStampNow()
  444. pr.Merger = doer
  445. pr.MergerID = doer.ID
  446. if err = pr.setMerged(); err != nil {
  447. log.Error(4, "setMerged [%d]: %v", pr.ID, err)
  448. }
  449. if err = MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
  450. log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
  451. }
  452. // Reset cached commit count
  453. cache.Remove(pr.Issue.Repo.GetCommitsCountCacheKey(pr.BaseBranch, true))
  454. // Reload pull request information.
  455. if err = pr.LoadAttributes(); err != nil {
  456. log.Error(4, "LoadAttributes: %v", err)
  457. return nil
  458. }
  459. mode, _ := AccessLevel(doer, pr.Issue.Repo)
  460. if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
  461. Action: api.HookIssueClosed,
  462. Index: pr.Index,
  463. PullRequest: pr.APIFormat(),
  464. Repository: pr.Issue.Repo.APIFormat(mode),
  465. Sender: doer.APIFormat(),
  466. }); err != nil {
  467. log.Error(4, "PrepareWebhooks: %v", err)
  468. } else {
  469. go HookQueue.Add(pr.Issue.Repo.ID)
  470. }
  471. l, err := baseGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase)
  472. if err != nil {
  473. log.Error(4, "CommitsBetweenIDs: %v", err)
  474. return nil
  475. }
  476. // It is possible that head branch is not fully sync with base branch for merge commits,
  477. // so we need to get latest head commit and append merge commit manually
  478. // to avoid strange diff commits produced.
  479. mergeCommit, err := baseGitRepo.GetBranchCommit(pr.BaseBranch)
  480. if err != nil {
  481. log.Error(4, "GetBranchCommit: %v", err)
  482. return nil
  483. }
  484. if mergeStyle == MergeStyleMerge {
  485. l.PushFront(mergeCommit)
  486. }
  487. p := &api.PushPayload{
  488. Ref: git.BranchPrefix + pr.BaseBranch,
  489. Before: pr.MergeBase,
  490. After: mergeCommit.ID.String(),
  491. CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
  492. Commits: ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()),
  493. Repo: pr.BaseRepo.APIFormat(mode),
  494. Pusher: pr.HeadRepo.MustOwner().APIFormat(),
  495. Sender: doer.APIFormat(),
  496. }
  497. if err = PrepareWebhooks(pr.BaseRepo, HookEventPush, p); err != nil {
  498. log.Error(4, "PrepareWebhooks: %v", err)
  499. } else {
  500. go HookQueue.Add(pr.BaseRepo.ID)
  501. }
  502. return nil
  503. }
  504. // setMerged sets a pull request to merged and closes the corresponding issue
  505. func (pr *PullRequest) setMerged() (err error) {
  506. if pr.HasMerged {
  507. return fmt.Errorf("PullRequest[%d] already merged", pr.Index)
  508. }
  509. if pr.MergedCommitID == "" || pr.MergedUnix == 0 || pr.Merger == nil {
  510. return fmt.Errorf("Unable to merge PullRequest[%d], some required fields are empty", pr.Index)
  511. }
  512. pr.HasMerged = true
  513. sess := x.NewSession()
  514. defer sess.Close()
  515. if err = sess.Begin(); err != nil {
  516. return err
  517. }
  518. if err = pr.loadIssue(sess); err != nil {
  519. return err
  520. }
  521. if err = pr.Issue.loadRepo(sess); err != nil {
  522. return err
  523. }
  524. if err = pr.Issue.Repo.getOwner(sess); err != nil {
  525. return err
  526. }
  527. if err = pr.Issue.changeStatus(sess, pr.Merger, true); err != nil {
  528. return fmt.Errorf("Issue.changeStatus: %v", err)
  529. }
  530. if _, err = sess.ID(pr.ID).Cols("has_merged, status, merged_commit_id, merger_id, merged_unix").Update(pr); err != nil {
  531. return fmt.Errorf("update pull request: %v", err)
  532. }
  533. if err = sess.Commit(); err != nil {
  534. return fmt.Errorf("Commit: %v", err)
  535. }
  536. return nil
  537. }
  538. // manuallyMerged checks if a pull request got manually merged
  539. // When a pull request got manually merged mark the pull request as merged
  540. func (pr *PullRequest) manuallyMerged() bool {
  541. commit, err := pr.getMergeCommit()
  542. if err != nil {
  543. log.Error(4, "PullRequest[%d].getMergeCommit: %v", pr.ID, err)
  544. return false
  545. }
  546. if commit != nil {
  547. pr.MergedCommitID = commit.ID.String()
  548. pr.MergedUnix = util.TimeStamp(commit.Author.When.Unix())
  549. pr.Status = PullRequestStatusManuallyMerged
  550. merger, _ := GetUserByEmail(commit.Author.Email)
  551. // When the commit author is unknown set the BaseRepo owner as merger
  552. if merger == nil {
  553. if pr.BaseRepo.Owner == nil {
  554. if err = pr.BaseRepo.getOwner(x); err != nil {
  555. log.Error(4, "BaseRepo.getOwner[%d]: %v", pr.ID, err)
  556. return false
  557. }
  558. }
  559. merger = pr.BaseRepo.Owner
  560. }
  561. pr.Merger = merger
  562. pr.MergerID = merger.ID
  563. if err = pr.setMerged(); err != nil {
  564. log.Error(4, "PullRequest[%d].setMerged : %v", pr.ID, err)
  565. return false
  566. }
  567. log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String())
  568. return true
  569. }
  570. return false
  571. }
  572. // getMergeCommit checks if a pull request got merged
  573. // Returns the git.Commit of the pull request if merged
  574. func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
  575. if pr.BaseRepo == nil {
  576. var err error
  577. pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
  578. if err != nil {
  579. return nil, fmt.Errorf("GetRepositoryByID: %v", err)
  580. }
  581. }
  582. indexTmpPath := filepath.Join(os.TempDir(), "gitea-"+pr.BaseRepo.Name+"-"+strconv.Itoa(time.Now().Nanosecond()))
  583. defer os.Remove(indexTmpPath)
  584. headFile := pr.GetGitRefName()
  585. // Check if a pull request is merged into BaseBranch
  586. _, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git merge-base --is-ancestor): %d", pr.BaseRepo.ID),
  587. []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()},
  588. "git", "merge-base", "--is-ancestor", headFile, pr.BaseBranch)
  589. if err != nil {
  590. // Errors are signaled by a non-zero status that is not 1
  591. if strings.Contains(err.Error(), "exit status 1") {
  592. return nil, nil
  593. }
  594. return nil, fmt.Errorf("git merge-base --is-ancestor: %v %v", stderr, err)
  595. }
  596. commitIDBytes, err := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
  597. if err != nil {
  598. return nil, fmt.Errorf("ReadFile(%s): %v", headFile, err)
  599. }
  600. commitID := string(commitIDBytes)
  601. if len(commitID) < 40 {
  602. return nil, fmt.Errorf(`ReadFile(%s): invalid commit-ID "%s"`, headFile, commitID)
  603. }
  604. cmd := commitID[:40] + ".." + pr.BaseBranch
  605. // Get the commit from BaseBranch where the pull request got merged
  606. mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID),
  607. []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()},
  608. "git", "rev-list", "--ancestry-path", "--merges", "--reverse", cmd)
  609. if err != nil {
  610. return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %v %v", stderr, err)
  611. } else if len(mergeCommit) < 40 {
  612. // PR was fast-forwarded, so just use last commit of PR
  613. mergeCommit = commitID[:40]
  614. }
  615. gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
  616. if err != nil {
  617. return nil, fmt.Errorf("OpenRepository: %v", err)
  618. }
  619. commit, err := gitRepo.GetCommit(mergeCommit[:40])
  620. if err != nil {
  621. return nil, fmt.Errorf("GetCommit: %v", err)
  622. }
  623. return commit, nil
  624. }
  625. // patchConflicts is a list of conflict description from Git.
  626. var patchConflicts = []string{
  627. "patch does not apply",
  628. "already exists in working directory",
  629. "unrecognized input",
  630. "error:",
  631. }
  632. // testPatch checks if patch can be merged to base repository without conflict.
  633. func (pr *PullRequest) testPatch(e Engine) (err error) {
  634. if pr.BaseRepo == nil {
  635. pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
  636. if err != nil {
  637. return fmt.Errorf("GetRepositoryByID: %v", err)
  638. }
  639. }
  640. patchPath, err := pr.BaseRepo.patchPath(e, pr.Index)
  641. if err != nil {
  642. return fmt.Errorf("BaseRepo.PatchPath: %v", err)
  643. }
  644. // Fast fail if patch does not exist, this assumes data is corrupted.
  645. if !com.IsFile(patchPath) {
  646. log.Trace("PullRequest[%d].testPatch: ignored corrupted data", pr.ID)
  647. return nil
  648. }
  649. repoWorkingPool.CheckIn(com.ToStr(pr.BaseRepoID))
  650. defer repoWorkingPool.CheckOut(com.ToStr(pr.BaseRepoID))
  651. log.Trace("PullRequest[%d].testPatch (patchPath): %s", pr.ID, patchPath)
  652. pr.Status = PullRequestStatusChecking
  653. indexTmpPath := filepath.Join(os.TempDir(), "gitea-"+pr.BaseRepo.Name+"-"+strconv.Itoa(time.Now().Nanosecond()))
  654. defer os.Remove(indexTmpPath)
  655. var stderr string
  656. _, stderr, err = process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("testPatch (git read-tree): %d", pr.BaseRepo.ID),
  657. []string{"GIT_DIR=" + pr.BaseRepo.RepoPath(), "GIT_INDEX_FILE=" + indexTmpPath},
  658. "git", "read-tree", pr.BaseBranch)
  659. if err != nil {
  660. return fmt.Errorf("git read-tree --index-output=%s %s: %v - %s", indexTmpPath, pr.BaseBranch, err, stderr)
  661. }
  662. prUnit, err := pr.BaseRepo.getUnit(e, UnitTypePullRequests)
  663. if err != nil {
  664. return err
  665. }
  666. prConfig := prUnit.PullRequestsConfig()
  667. args := []string{"apply", "--check", "--cached"}
  668. if prConfig.IgnoreWhitespaceConflicts {
  669. args = append(args, "--ignore-whitespace")
  670. }
  671. args = append(args, patchPath)
  672. _, stderr, err = process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID),
  673. []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()},
  674. "git", args...)
  675. if err != nil {
  676. for i := range patchConflicts {
  677. if strings.Contains(stderr, patchConflicts[i]) {
  678. log.Trace("PullRequest[%d].testPatch (apply): has conflict", pr.ID)
  679. fmt.Println(stderr)
  680. pr.Status = PullRequestStatusConflict
  681. return nil
  682. }
  683. }
  684. return fmt.Errorf("git apply --check: %v - %s", err, stderr)
  685. }
  686. return nil
  687. }
  688. // NewPullRequest creates new pull request with labels for repository.
  689. func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []string, pr *PullRequest, patch []byte, assigneeIDs []int64) (err error) {
  690. sess := x.NewSession()
  691. defer sess.Close()
  692. if err = sess.Begin(); err != nil {
  693. return err
  694. }
  695. if err = newIssue(sess, pull.Poster, NewIssueOptions{
  696. Repo: repo,
  697. Issue: pull,
  698. LabelIDs: labelIDs,
  699. Attachments: uuids,
  700. IsPull: true,
  701. AssigneeIDs: assigneeIDs,
  702. }); err != nil {
  703. if IsErrUserDoesNotHaveAccessToRepo(err) {
  704. return err
  705. }
  706. return fmt.Errorf("newIssue: %v", err)
  707. }
  708. pr.Index = pull.Index
  709. if err = repo.savePatch(sess, pr.Index, patch); err != nil {
  710. return fmt.Errorf("SavePatch: %v", err)
  711. }
  712. pr.BaseRepo = repo
  713. if err = pr.testPatch(sess); err != nil {
  714. return fmt.Errorf("testPatch: %v", err)
  715. }
  716. // No conflict appears after test means mergeable.
  717. if pr.Status == PullRequestStatusChecking {
  718. pr.Status = PullRequestStatusMergeable
  719. }
  720. pr.IssueID = pull.ID
  721. if _, err = sess.Insert(pr); err != nil {
  722. return fmt.Errorf("insert pull repo: %v", err)
  723. }
  724. if err = sess.Commit(); err != nil {
  725. return fmt.Errorf("Commit: %v", err)
  726. }
  727. UpdateIssueIndexer(pull.ID)
  728. if err = NotifyWatchers(&Action{
  729. ActUserID: pull.Poster.ID,
  730. ActUser: pull.Poster,
  731. OpType: ActionCreatePullRequest,
  732. Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
  733. RepoID: repo.ID,
  734. Repo: repo,
  735. IsPrivate: repo.IsPrivate,
  736. }); err != nil {
  737. log.Error(4, "NotifyWatchers: %v", err)
  738. }
  739. pr.Issue = pull
  740. pull.PullRequest = pr
  741. mode, _ := AccessLevel(pull.Poster, repo)
  742. if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{
  743. Action: api.HookIssueOpened,
  744. Index: pull.Index,
  745. PullRequest: pr.APIFormat(),
  746. Repository: repo.APIFormat(mode),
  747. Sender: pull.Poster.APIFormat(),
  748. }); err != nil {
  749. log.Error(4, "PrepareWebhooks: %v", err)
  750. } else {
  751. go HookQueue.Add(repo.ID)
  752. }
  753. return nil
  754. }
  755. // PullRequestsOptions holds the options for PRs
  756. type PullRequestsOptions struct {
  757. Page int
  758. State string
  759. SortType string
  760. Labels []string
  761. MilestoneID int64
  762. }
  763. func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) {
  764. sess := x.Where("pull_request.base_repo_id=?", baseRepoID)
  765. sess.Join("INNER", "issue", "pull_request.issue_id = issue.id")
  766. switch opts.State {
  767. case "closed", "open":
  768. sess.And("issue.is_closed=?", opts.State == "closed")
  769. }
  770. if labelIDs, err := base.StringsToInt64s(opts.Labels); err != nil {
  771. return nil, err
  772. } else if len(labelIDs) > 0 {
  773. sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
  774. In("issue_label.label_id", labelIDs)
  775. }
  776. if opts.MilestoneID > 0 {
  777. sess.And("issue.milestone_id=?", opts.MilestoneID)
  778. }
  779. return sess, nil
  780. }
  781. // PullRequests returns all pull requests for a base Repo by the given conditions
  782. func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest, int64, error) {
  783. if opts.Page <= 0 {
  784. opts.Page = 1
  785. }
  786. countSession, err := listPullRequestStatement(baseRepoID, opts)
  787. if err != nil {
  788. log.Error(4, "listPullRequestStatement", err)
  789. return nil, 0, err
  790. }
  791. maxResults, err := countSession.Count(new(PullRequest))
  792. if err != nil {
  793. log.Error(4, "Count PRs", err)
  794. return nil, maxResults, err
  795. }
  796. prs := make([]*PullRequest, 0, ItemsPerPage)
  797. findSession, err := listPullRequestStatement(baseRepoID, opts)
  798. sortIssuesSession(findSession, opts.SortType)
  799. if err != nil {
  800. log.Error(4, "listPullRequestStatement", err)
  801. return nil, maxResults, err
  802. }
  803. findSession.Limit(ItemsPerPage, (opts.Page-1)*ItemsPerPage)
  804. return prs, maxResults, findSession.Find(&prs)
  805. }
  806. // GetUnmergedPullRequest returns a pull request that is open and has not been merged
  807. // by given head/base and repo/branch.
  808. func GetUnmergedPullRequest(headRepoID, baseRepoID int64, headBranch, baseBranch string) (*PullRequest, error) {
  809. pr := new(PullRequest)
  810. has, err := x.
  811. Where("head_repo_id=? AND head_branch=? AND base_repo_id=? AND base_branch=? AND has_merged=? AND issue.is_closed=?",
  812. headRepoID, headBranch, baseRepoID, baseBranch, false, false).
  813. Join("INNER", "issue", "issue.id=pull_request.issue_id").
  814. Get(pr)
  815. if err != nil {
  816. return nil, err
  817. } else if !has {
  818. return nil, ErrPullRequestNotExist{0, 0, headRepoID, baseRepoID, headBranch, baseBranch}
  819. }
  820. return pr, nil
  821. }
  822. // GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
  823. // by given head information (repo and branch).
  824. func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {
  825. prs := make([]*PullRequest, 0, 2)
  826. return prs, x.
  827. Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ?",
  828. repoID, branch, false, false).
  829. Join("INNER", "issue", "issue.id = pull_request.issue_id").
  830. Find(&prs)
  831. }
  832. // GetUnmergedPullRequestsByBaseInfo returns all pull requests that are open and has not been merged
  833. // by given base information (repo and branch).
  834. func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequest, error) {
  835. prs := make([]*PullRequest, 0, 2)
  836. return prs, x.
  837. Where("base_repo_id=? AND base_branch=? AND has_merged=? AND issue.is_closed=?",
  838. repoID, branch, false, false).
  839. Join("INNER", "issue", "issue.id=pull_request.issue_id").
  840. Find(&prs)
  841. }
  842. // GetPullRequestByIndex returns a pull request by the given index
  843. func GetPullRequestByIndex(repoID int64, index int64) (*PullRequest, error) {
  844. pr := &PullRequest{
  845. BaseRepoID: repoID,
  846. Index: index,
  847. }
  848. has, err := x.Get(pr)
  849. if err != nil {
  850. return nil, err
  851. } else if !has {
  852. return nil, ErrPullRequestNotExist{0, 0, 0, repoID, "", ""}
  853. }
  854. if err = pr.LoadAttributes(); err != nil {
  855. return nil, err
  856. }
  857. if err = pr.LoadIssue(); err != nil {
  858. return nil, err
  859. }
  860. return pr, nil
  861. }
  862. func getPullRequestByID(e Engine, id int64) (*PullRequest, error) {
  863. pr := new(PullRequest)
  864. has, err := e.ID(id).Get(pr)
  865. if err != nil {
  866. return nil, err
  867. } else if !has {
  868. return nil, ErrPullRequestNotExist{id, 0, 0, 0, "", ""}
  869. }
  870. return pr, pr.loadAttributes(e)
  871. }
  872. // GetPullRequestByID returns a pull request by given ID.
  873. func GetPullRequestByID(id int64) (*PullRequest, error) {
  874. return getPullRequestByID(x, id)
  875. }
  876. func getPullRequestByIssueID(e Engine, issueID int64) (*PullRequest, error) {
  877. pr := &PullRequest{
  878. IssueID: issueID,
  879. }
  880. has, err := e.Get(pr)
  881. if err != nil {
  882. return nil, err
  883. } else if !has {
  884. return nil, ErrPullRequestNotExist{0, issueID, 0, 0, "", ""}
  885. }
  886. return pr, pr.loadAttributes(e)
  887. }
  888. // GetPullRequestByIssueID returns pull request by given issue ID.
  889. func GetPullRequestByIssueID(issueID int64) (*PullRequest, error) {
  890. return getPullRequestByIssueID(x, issueID)
  891. }
  892. // Update updates all fields of pull request.
  893. func (pr *PullRequest) Update() error {
  894. _, err := x.ID(pr.ID).AllCols().Update(pr)
  895. return err
  896. }
  897. // UpdateCols updates specific fields of pull request.
  898. func (pr *PullRequest) UpdateCols(cols ...string) error {
  899. _, err := x.ID(pr.ID).Cols(cols...).Update(pr)
  900. return err
  901. }
  902. // UpdatePatch generates and saves a new patch.
  903. func (pr *PullRequest) UpdatePatch() (err error) {
  904. if err = pr.GetHeadRepo(); err != nil {
  905. return fmt.Errorf("GetHeadRepo: %v", err)
  906. } else if pr.HeadRepo == nil {
  907. log.Trace("PullRequest[%d].UpdatePatch: ignored cruppted data", pr.ID)
  908. return nil
  909. }
  910. if err = pr.GetBaseRepo(); err != nil {
  911. return fmt.Errorf("GetBaseRepo: %v", err)
  912. }
  913. headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
  914. if err != nil {
  915. return fmt.Errorf("OpenRepository: %v", err)
  916. }
  917. // Add a temporary remote.
  918. tmpRemote := com.ToStr(time.Now().UnixNano())
  919. if err = headGitRepo.AddRemote(tmpRemote, RepoPath(pr.BaseRepo.MustOwner().Name, pr.BaseRepo.Name), true); err != nil {
  920. return fmt.Errorf("AddRemote: %v", err)
  921. }
  922. defer func() {
  923. headGitRepo.RemoveRemote(tmpRemote)
  924. }()
  925. remoteBranch := "remotes/" + tmpRemote + "/" + pr.BaseBranch
  926. pr.MergeBase, err = headGitRepo.GetMergeBase(remoteBranch, pr.HeadBranch)
  927. if err != nil {
  928. return fmt.Errorf("GetMergeBase: %v", err)
  929. } else if err = pr.Update(); err != nil {
  930. return fmt.Errorf("Update: %v", err)
  931. }
  932. patch, err := headGitRepo.GetPatch(pr.MergeBase, pr.HeadBranch)
  933. if err != nil {
  934. return fmt.Errorf("GetPatch: %v", err)
  935. }
  936. if err = pr.BaseRepo.SavePatch(pr.Index, patch); err != nil {
  937. return fmt.Errorf("BaseRepo.SavePatch: %v", err)
  938. }
  939. return nil
  940. }
  941. // PushToBaseRepo pushes commits from branches of head repository to
  942. // corresponding branches of base repository.
  943. // FIXME: Only push branches that are actually updates?
  944. func (pr *PullRequest) PushToBaseRepo() (err error) {
  945. log.Trace("PushToBaseRepo[%d]: pushing commits to base repo '%s'", pr.BaseRepoID, pr.GetGitRefName())
  946. headRepoPath := pr.HeadRepo.RepoPath()
  947. headGitRepo, err := git.OpenRepository(headRepoPath)
  948. if err != nil {
  949. return fmt.Errorf("OpenRepository: %v", err)
  950. }
  951. tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID)
  952. if err = headGitRepo.AddRemote(tmpRemoteName, pr.BaseRepo.RepoPath(), false); err != nil {
  953. return fmt.Errorf("headGitRepo.AddRemote: %v", err)
  954. }
  955. // Make sure to remove the remote even if the push fails
  956. defer headGitRepo.RemoveRemote(tmpRemoteName)
  957. headFile := pr.GetGitRefName()
  958. // Remove head in case there is a conflict.
  959. file := path.Join(pr.BaseRepo.RepoPath(), headFile)
  960. _ = os.Remove(file)
  961. if err = git.Push(headRepoPath, git.PushOptions{
  962. Remote: tmpRemoteName,
  963. Branch: fmt.Sprintf("%s:%s", pr.HeadBranch, headFile),
  964. Force: true,
  965. }); err != nil {
  966. return fmt.Errorf("Push: %v", err)
  967. }
  968. return nil
  969. }
  970. // AddToTaskQueue adds itself to pull request test task queue.
  971. func (pr *PullRequest) AddToTaskQueue() {
  972. go pullRequestQueue.AddFunc(pr.ID, func() {
  973. pr.Status = PullRequestStatusChecking
  974. if err := pr.UpdateCols("status"); err != nil {
  975. log.Error(5, "AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
  976. }
  977. })
  978. }
  979. // PullRequestList defines a list of pull requests
  980. type PullRequestList []*PullRequest
  981. func (prs PullRequestList) loadAttributes(e Engine) error {
  982. if len(prs) == 0 {
  983. return nil
  984. }
  985. // Load issues.
  986. issueIDs := prs.getIssueIDs()
  987. issues := make([]*Issue, 0, len(issueIDs))
  988. if err := e.
  989. Where("id > 0").
  990. In("id", issueIDs).
  991. Find(&issues); err != nil {
  992. return fmt.Errorf("find issues: %v", err)
  993. }
  994. set := make(map[int64]*Issue)
  995. for i := range issues {
  996. set[issues[i].ID] = issues[i]
  997. }
  998. for i := range prs {
  999. prs[i].Issue = set[prs[i].IssueID]
  1000. }
  1001. return nil
  1002. }
  1003. func (prs PullRequestList) getIssueIDs() []int64 {
  1004. issueIDs := make([]int64, 0, len(prs))
  1005. for i := range prs {
  1006. issueIDs = append(issueIDs, prs[i].IssueID)
  1007. }
  1008. return issueIDs
  1009. }
  1010. // LoadAttributes load all the prs attributes
  1011. func (prs PullRequestList) LoadAttributes() error {
  1012. return prs.loadAttributes(x)
  1013. }
  1014. func (prs PullRequestList) invalidateCodeComments(e Engine, doer *User, repo *git.Repository, branch string) error {
  1015. if len(prs) == 0 {
  1016. return nil
  1017. }
  1018. issueIDs := prs.getIssueIDs()
  1019. var codeComments []*Comment
  1020. if err := e.
  1021. Where("type = ? and invalidated = ?", CommentTypeCode, false).
  1022. In("issue_id", issueIDs).
  1023. Find(&codeComments); err != nil {
  1024. return fmt.Errorf("find code comments: %v", err)
  1025. }
  1026. for _, comment := range codeComments {
  1027. if err := comment.CheckInvalidation(repo, doer, branch); err != nil {
  1028. return err
  1029. }
  1030. }
  1031. return nil
  1032. }
  1033. // InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
  1034. func (prs PullRequestList) InvalidateCodeComments(doer *User, repo *git.Repository, branch string) error {
  1035. return prs.invalidateCodeComments(x, doer, repo, branch)
  1036. }
  1037. func addHeadRepoTasks(prs []*PullRequest) {
  1038. for _, pr := range prs {
  1039. log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID)
  1040. if err := pr.UpdatePatch(); err != nil {
  1041. log.Error(4, "UpdatePatch: %v", err)
  1042. continue
  1043. } else if err := pr.PushToBaseRepo(); err != nil {
  1044. log.Error(4, "PushToBaseRepo: %v", err)
  1045. continue
  1046. }
  1047. pr.AddToTaskQueue()
  1048. }
  1049. }
  1050. // AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
  1051. // and generate new patch for testing as needed.
  1052. func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool) {
  1053. log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
  1054. prs, err := GetUnmergedPullRequestsByHeadInfo(repoID, branch)
  1055. if err != nil {
  1056. log.Error(4, "Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err)
  1057. return
  1058. }
  1059. if isSync {
  1060. requests := PullRequestList(prs)
  1061. if err = requests.LoadAttributes(); err != nil {
  1062. log.Error(4, "PullRequestList.LoadAttributes: %v", err)
  1063. }
  1064. if invalidationErr := checkForInvalidation(requests, repoID, doer, branch); invalidationErr != nil {
  1065. log.Error(4, "checkForInvalidation: %v", invalidationErr)
  1066. }
  1067. if err == nil {
  1068. for _, pr := range prs {
  1069. pr.Issue.PullRequest = pr
  1070. if err = pr.Issue.LoadAttributes(); err != nil {
  1071. log.Error(4, "LoadAttributes: %v", err)
  1072. continue
  1073. }
  1074. if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
  1075. Action: api.HookIssueSynchronized,
  1076. Index: pr.Issue.Index,
  1077. PullRequest: pr.Issue.PullRequest.APIFormat(),
  1078. Repository: pr.Issue.Repo.APIFormat(AccessModeNone),
  1079. Sender: doer.APIFormat(),
  1080. }); err != nil {
  1081. log.Error(4, "PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
  1082. continue
  1083. }
  1084. go HookQueue.Add(pr.Issue.Repo.ID)
  1085. }
  1086. }
  1087. }
  1088. addHeadRepoTasks(prs)
  1089. log.Trace("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch)
  1090. prs, err = GetUnmergedPullRequestsByBaseInfo(repoID, branch)
  1091. if err != nil {
  1092. log.Error(4, "Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err)
  1093. return
  1094. }
  1095. for _, pr := range prs {
  1096. pr.AddToTaskQueue()
  1097. }
  1098. }
  1099. func checkForInvalidation(requests PullRequestList, repoID int64, doer *User, branch string) error {
  1100. repo, err := GetRepositoryByID(repoID)
  1101. if err != nil {
  1102. return fmt.Errorf("GetRepositoryByID: %v", err)
  1103. }
  1104. gitRepo, err := git.OpenRepository(repo.RepoPath())
  1105. if err != nil {
  1106. return fmt.Errorf("git.OpenRepository: %v", err)
  1107. }
  1108. go func() {
  1109. err := requests.InvalidateCodeComments(doer, gitRepo, branch)
  1110. if err != nil {
  1111. log.Error(4, "PullRequestList.InvalidateCodeComments: %v", err)
  1112. }
  1113. }()
  1114. return nil
  1115. }
  1116. // ChangeUsernameInPullRequests changes the name of head_user_name
  1117. func ChangeUsernameInPullRequests(oldUserName, newUserName string) error {
  1118. pr := PullRequest{
  1119. HeadUserName: strings.ToLower(newUserName),
  1120. }
  1121. _, err := x.
  1122. Cols("head_user_name").
  1123. Where("head_user_name = ?", strings.ToLower(oldUserName)).
  1124. Update(pr)
  1125. return err
  1126. }
  1127. // checkAndUpdateStatus checks if pull request is possible to leaving checking status,
  1128. // and set to be either conflict or mergeable.
  1129. func (pr *PullRequest) checkAndUpdateStatus() {
  1130. // Status is not changed to conflict means mergeable.
  1131. if pr.Status == PullRequestStatusChecking {
  1132. pr.Status = PullRequestStatusMergeable
  1133. }
  1134. // Make sure there is no waiting test to process before leaving the checking status.
  1135. if !pullRequestQueue.Exist(pr.ID) {
  1136. if err := pr.UpdateCols("status"); err != nil {
  1137. log.Error(4, "Update[%d]: %v", pr.ID, err)
  1138. }
  1139. }
  1140. }
  1141. // IsWorkInProgress determine if the Pull Request is a Work In Progress by its title
  1142. func (pr *PullRequest) IsWorkInProgress() bool {
  1143. if err := pr.LoadIssue(); err != nil {
  1144. log.Error(4, "LoadIssue: %v", err)
  1145. return false
  1146. }
  1147. for _, prefix := range setting.Repository.PullRequest.WorkInProgressPrefixes {
  1148. if strings.HasPrefix(strings.ToUpper(pr.Issue.Title), prefix) {
  1149. return true
  1150. }
  1151. }
  1152. return false
  1153. }
  1154. // GetWorkInProgressPrefix returns the prefix used to mark the pull request as a work in progress.
  1155. // It returns an empty string when none were found
  1156. func (pr *PullRequest) GetWorkInProgressPrefix() string {
  1157. if err := pr.LoadIssue(); err != nil {
  1158. log.Error(4, "LoadIssue: %v", err)
  1159. return ""
  1160. }
  1161. for _, prefix := range setting.Repository.PullRequest.WorkInProgressPrefixes {
  1162. if strings.HasPrefix(strings.ToUpper(pr.Issue.Title), prefix) {
  1163. return pr.Issue.Title[0:len(prefix)]
  1164. }
  1165. }
  1166. return ""
  1167. }
  1168. // TestPullRequests checks and tests untested patches of pull requests.
  1169. // TODO: test more pull requests at same time.
  1170. func TestPullRequests() {
  1171. prs := make([]*PullRequest, 0, 10)
  1172. err := x.Where("status = ?", PullRequestStatusChecking).Find(&prs)
  1173. if err != nil {
  1174. log.Error(3, "Find Checking PRs", err)
  1175. return
  1176. }
  1177. var checkedPRs = make(map[int64]struct{})
  1178. // Update pull request status.
  1179. for _, pr := range prs {
  1180. checkedPRs[pr.ID] = struct{}{}
  1181. if err := pr.GetBaseRepo(); err != nil {
  1182. log.Error(3, "GetBaseRepo: %v", err)
  1183. continue
  1184. }
  1185. if pr.manuallyMerged() {
  1186. continue
  1187. }
  1188. if err := pr.testPatch(x); err != nil {
  1189. log.Error(3, "testPatch: %v", err)
  1190. continue
  1191. }
  1192. pr.checkAndUpdateStatus()
  1193. }
  1194. // Start listening on new test requests.
  1195. for prID := range pullRequestQueue.Queue() {
  1196. log.Trace("TestPullRequests[%v]: processing test task", prID)
  1197. pullRequestQueue.Remove(prID)
  1198. id := com.StrTo(prID).MustInt64()
  1199. if _, ok := checkedPRs[id]; ok {
  1200. continue
  1201. }
  1202. pr, err := GetPullRequestByID(id)
  1203. if err != nil {
  1204. log.Error(4, "GetPullRequestByID[%s]: %v", prID, err)
  1205. continue
  1206. } else if pr.manuallyMerged() {
  1207. continue
  1208. } else if err = pr.testPatch(x); err != nil {
  1209. log.Error(4, "testPatch[%d]: %v", pr.ID, err)
  1210. continue
  1211. }
  1212. pr.checkAndUpdateStatus()
  1213. }
  1214. }
  1215. // InitTestPullRequests runs the task to test all the checking status pull requests
  1216. func InitTestPullRequests() {
  1217. go TestPullRequests()
  1218. }