// // Outputs what properties we are using // private void OutputRequestProperties(ReviewRequestProperties thisRequest) { if (thisRequest.ReviewProperties.ReviewLevel == RB_Tools.Shared.Review.Properties.Level.FullReview) { m_logger.Log("Starting review request on '{0}'", thisRequest.WorkingCopy); m_logger.Log(" * Path: {0}", thisRequest.ReviewProperties.Path); m_logger.Log(" * Review ID: {0}", thisRequest.ReviewProperties.ReviewId); m_logger.Log(" * Summary: {0}", thisRequest.ReviewProperties.Summary); m_logger.Log(" * Description:\n{0}", thisRequest.ReviewProperties.Description); m_logger.Log(" * Testing:\n{0}", thisRequest.ReviewProperties.Testing); m_logger.Log(" * Jira ID: {0}", thisRequest.ReviewProperties.JiraId); m_logger.Log(" * Review Level: {0}", thisRequest.ReviewProperties.ReviewLevel); m_logger.Log(" * Copies As Adds: {0}", thisRequest.ReviewProperties.CopiesAsAdds); m_logger.Log(" * Source Type: {0}", thisRequest.ReviewProperties.Contents.Source); // Groups if (thisRequest.ReviewProperties.Groups != null && thisRequest.ReviewProperties.Groups.Count > 0) { m_logger.Log("Posting to groups:"); foreach (string thisGroup in thisRequest.ReviewProperties.Groups) { m_logger.Log(" * {0}", thisGroup); } } // Content files if (thisRequest.ReviewProperties.Contents.Files != null && thisRequest.ReviewProperties.Contents.Files.Length > 0) { m_logger.Log("Reviewing files:"); foreach (string thisFile in thisRequest.ReviewProperties.Contents.Files) { m_logger.Log(" * {0}", thisFile); } } // Content patch if (string.IsNullOrEmpty(thisRequest.ReviewProperties.Contents.Patch) == false) { m_logger.Log("Review patch:"); m_logger.Log(" * {0}:", thisRequest.ReviewProperties.Contents.Patch); } } else { m_logger.Log("Skipping review request"); } }
// // Runs the review request // private void TriggerReviewRequest(Review.Review.Properties reviewProperties) { m_logger.Log("Triggering review request"); // Build up the background work BackgroundWorker updateThread = new BackgroundWorker(); // Called when we need to trigger the request updateThread.DoWork += (object objectSender, DoWorkEventArgs args) => { // Pull out the properties of the request ReviewRequestProperties thisRequest = args.Argument as ReviewRequestProperties; OutputRequestProperties(thisRequest); // Do we need to validate the Jira ticket? bool ticketValid = ValidateJiraTicket(thisRequest.ReviewProperties.JiraId); if (ticketValid == false) { args.Result = new Reviewboard.ReviewRequestResult(null, "Unable to validate the given Jira ticket", thisRequest.ReviewProperties); return; } // Carry out the review args.Result = RequestReview(thisRequest); }; // Called when the thread is complete updateThread.RunWorkerCompleted += (object objectSender, RunWorkerCompletedEventArgs args) => { // Check if we had an error if (args.Error != null) { m_logger.Log("Error raised during review request - {0}", args.Error.Message); string body = string.Format("Exception thrown when trying to raise a new review\n\nException: {0}\n\nDescription: {1}", args.Error.GetType().Name, args.Error.Message); // Was it an authentication error? bool authenticationRequired = false; if (args.Error.Message.Contains("username or password was not correct") == true) { authenticationRequired = true; body += "\n\nDo you want to attempt to reauthenticate with the server?"; } // Show the options MessageBoxButtons buttonTypes = (authenticationRequired == true ? MessageBoxButtons.YesNo : MessageBoxButtons.OK); DialogResult result = MessageBox.Show(this, body, @"Unable to raise review", buttonTypes, MessageBoxIcon.Error); // Continue? if (result == DialogResult.Yes && authenticationRequired == true) { RB_Tools.Shared.Authentication.Targets.Reviewboard.Authenticate(m_logger); } OnReviewFinished(FinishReason.Error); } else { // Pull out the results of the review Reviewboard.ReviewRequestResult requestResult = args.Result as Reviewboard.ReviewRequestResult; // If we don't have a review URL, we failed if (string.IsNullOrWhiteSpace(requestResult.Error) == false) { m_logger.Log("Error raised during review request - {0}", requestResult.Error); // Raise the error and we're done MessageBox.Show(this, requestResult.Error, @"Unable to raise review", MessageBoxButtons.OK, MessageBoxIcon.Error); OnReviewFinished(FinishReason.Error); } else { if (requestResult.Properties.ReviewLevel == RB_Tools.Shared.Review.Properties.Level.FullReview) { m_logger.Log("Review posted successful - {0}", requestResult.Url); } // Open the browser, doing this manually so we can open on the diff if (string.IsNullOrWhiteSpace(requestResult.Url) == false) { System.Diagnostics.Process.Start(requestResult.Url); } // If it's just a patch file, we don't need to do anything else if (m_reviewSource.Source == Review.Review.Source.Patch) { m_logger.Log("Patch review completed, process finished"); OnReviewFinished(FinishReason.Success); } else { m_logger.Log("File review finished, moving onto next stage"); // Flag the actual review as done so we lose the path file // and then it doesn't show up in TortoiseSVN OnReviewFinished(FinishReason.Interim); TriggerTortoiseRequest(requestResult); } } } }; // Kick off the request ReviewRequestProperties requestProperties = new ReviewRequestProperties(reviewProperties, m_requestDirectory); updateThread.RunWorkerAsync(requestProperties); }