// // Runs the review request // private void TriggerTortoiseRequest(Reviewboard.ReviewRequestResult requestResults) { m_logger.Log("Triggering TortoiseSVN dialog"); // 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 Reviewboard.ReviewRequestResult originalResults = args.Argument as Reviewboard.ReviewRequestResult; TortoiseSvn.OpenCommitDialog(originalResults.Properties, originalResults.Url, m_logger); }; // 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 using TortoiseSVN - {0}", args.Error.Message); string body = string.Format("Exception thrown when trying to commit to SVN\n\nException: {0}\n\nDescription: {1}", args.Error.GetType().Name, args.Error.Message); MessageBox.Show(this, body, @"Unable to commit", MessageBoxButtons.OK, MessageBoxIcon.Error); // Done OnReviewFinished(FinishReason.Error); } else { // Done OnReviewFinished(FinishReason.Success); } }; // Kick off the request updateThread.RunWorkerAsync(requestResults); }
// // Validates the Jira ticket if needed // bool ValidateJiraTicket(string jiraId) { // If we have no ticker, we're fine if (string.IsNullOrEmpty(jiraId) == true) { return(true); } // Get our credentials string serverName = Names.Url[(int)Names.Type.Jira]; Simple credentials = Credentials.Create(serverName, m_logger) as Simple; if (credentials == null) { m_logger.Log("Unable to create credentials for '{0}'", serverName); throw new FileNotFoundException(@"Unable to find the credentials for " + serverName); } // Split out ticket IDs so we validate them all string[] jiras = jiraId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (jiras == null || jiras.Length == 0) { jiras = new string[] { jiraId } } ; // Validate the ticker foreach (string thisTicket in jiras) { string ticketToCheck = thisTicket.Trim(); bool tickerValid = RB_Tools.Shared.Targets.Jira.ValidateJiraTicker(credentials, ticketToCheck).Result; if (tickerValid == false) { string message = string.Format("Unable to find ticket '{0}' on {1}", jiraId, serverName); m_logger.Log(message); throw new InvalidOperationException(message); } } // We're done return(true); } // // Requests a new review // object RequestReview(ReviewRequestProperties thisRequest) { if (thisRequest.ReviewProperties.ReviewLevel == RB_Tools.Shared.Review.Properties.Level.FullReview) { // Get our credentials string serverName = Names.Url[(int)Names.Type.Reviewboard]; Simple credentials = Credentials.Create(serverName, m_logger) as Simple; if (credentials == null) { m_logger.Log("Unable to create credentials for '{0}'", serverName); throw new FileNotFoundException(@"Unable to find the credentials for " + serverName); } // Request the review m_logger.Log("Requesting review"); Reviewboard.ReviewRequestResult result = Reviewboard.RequestReview( thisRequest.WorkingCopy, credentials.Server, credentials.User, credentials.Password, thisRequest.ReviewProperties, m_logger); // Save the result m_logger.Log("Review request finished"); return(result); } else { // Save the result m_logger.Log("Review request skipped as a review is not being carried out"); return(new Reviewboard.ReviewRequestResult(null, null, thisRequest.ReviewProperties)); } }
// // 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); }