private static void UpdateIssue(IProvider project, IssueUpdate issue, NetworkCredential credential, Action<string> stdout) { project.UpdateIssue(issue, credential, stdout, stdout); }
private static void UpdateIssue(string project, IssueUpdate update, NetworkCredential credential, Action <string> stdout, Action <string> stderr) { string commentPath = null; var comment = update.Comment; if (comment.Length > 0) { if (comment.IndexOfAny(new[] { '\r', '\n', '\f' }) >= 0) { commentPath = Path.GetTempFileName(); File.WriteAllText(commentPath, comment, Encoding.UTF8); comment = "@" + commentPath; } else if (comment[0] == '@') { comment = "@" + comment; } } try { var commandLine = Environment.GetEnvironmentVariable("GURTLE_ISSUE_UPDATE_CMD") ?? string.Empty; stderr("GURTLE_ISSUE_UPDATE_CMD: " + commandLine); var args = CommandLineToArgs(commandLine); var command = args.First(); for (var i = 0; i < args.Length; i++) { stderr(string.Format("[{0}]: {1}", i, args[i])); } args = args.Skip(1) .Select(arg => arg.FormatWith(CultureInfo.InvariantCulture, new { credential.UserName, credential.Password, Project = project, Issue = update.Issue, Status = update.Status, Comment = comment, })) .Select(arg => EncodeCommandLineArg(arg)) .ToArray(); var formattedCommandLineArgs = string.Join(" ", args); stderr(formattedCommandLineArgs.Replace(credential.Password, "**********")); using (var process = Process.Start(new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = true, FileName = command, Arguments = formattedCommandLineArgs, RedirectStandardError = true, RedirectStandardOutput = true, })) { Debug.Assert(process != null); stderr("PID: " + process.Id); process.OutputDataReceived += (sender, e) => stdout(e.Data); process.ErrorDataReceived += (sender, e) => stderr(e.Data); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception( string.Format("Issue update command failed with an exit code of {0}.", process.ExitCode)); } } } finally { if (!string.IsNullOrEmpty(commentPath) && File.Exists(commentPath)) { File.Delete(commentPath); } } }
private static void UpdateIssue(string project, IssueUpdate issue, NetworkCredential credential, Action <string> stdout) { UpdateIssue(project, issue, credential, stdout, stdout); }
private IssueUpdatePage CreateIssuePage(IssueUpdate issue) { Debug.Assert(issue != null); var page = new IssueUpdatePage { Dock = DockStyle.Fill, Summary = issue.Issue.Summary, Comment = issue.Comment, Status = issue.Status, Url = _project.IssueDetailUrl(issue.Issue.Id) }; page.RevisionClicked += (sender, args) => Process.Start(_project.RevisionDetailUrl(args.Revision).ToString()); return page; }
internal void UpdateIssue(IssueUpdate update, NetworkCredential credential, Action<string> stdout, Action<string> stderr) { string commentPath = null; var comment = update.Comment; if (comment.Length > 0) { if (comment.IndexOfAny(new[] { '\r', '\n', '\f' }) >= 0) { commentPath = Path.GetTempFileName(); File.WriteAllText(commentPath, comment, Encoding.UTF8); comment = "@" + commentPath; } else if (comment[0] == '@') { comment = "@" + comment; } } try { var commandLine = Environment.GetEnvironmentVariable("GURTLE_ISSUE_UPDATE_CMD") ?? string.Empty; stderr("GURTLE_ISSUE_UPDATE_CMD: " + commandLine); var args = CommandLineUtils.CommandLineToArgs(commandLine); var command = args.First(); for (var i = 0; i < args.Length; i++) stderr(string.Format("[{0}]: {1}", i, args[i])); args = args.Skip(1) .Select(arg => arg.FormatWith(CultureInfo.InvariantCulture, new { credential.UserName, credential.Password, Project = this, Issue = update.Issue, Status = update.Status, Comment = comment, })) .Select(arg => CommandLineUtils.EncodeCommandLineArg(arg)) .ToArray(); var formattedCommandLineArgs = string.Join(" ", args); stderr(formattedCommandLineArgs.Replace(credential.Password, "**********")); using (var process = Process.Start(new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = true, FileName = command, Arguments = formattedCommandLineArgs, RedirectStandardError = true, RedirectStandardOutput = true, })) { Debug.Assert(process != null); stderr("PID: " + process.Id); process.OutputDataReceived += (sender, e) => stdout(e.Data); process.ErrorDataReceived += (sender, e) => stderr(e.Data); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception( string.Format("Issue update command failed with an exit code of {0}.", process.ExitCode)); } } } finally { if (!string.IsNullOrEmpty(commentPath) && File.Exists(commentPath)) File.Delete(commentPath); } }
private static void UpdateIssue(string project, IssueUpdate issue, NetworkCredential credential, Action<string> stdout) { UpdateIssue(project, issue, credential, stdout, stdout); }