in src/VstsDemoBuilder/Services/ProjectService.cs [1668:1724]
private void CreatePullRequest(Project model, string pullRequestJsonPath, VstsRestAPI.Configuration _workItemConfig)
{
try
{
if (File.Exists(pullRequestJsonPath))
{
string commentFile = Path.GetFileName(pullRequestJsonPath);
string repositoryId = string.Empty;
if (model.SelectedTemplate == "MyHealthClinic") { repositoryId = model.Environment.repositoryIdList["MyHealthClinic"]; }
if (model.SelectedTemplate == "SmartHotel360") { repositoryId = model.Environment.repositoryIdList["PublicWeb"]; }
else { repositoryId = model.Environment.repositoryIdList.ContainsKey(model.SelectedTemplate) ? model.Environment.repositoryIdList[model.SelectedTemplate] : ""; }
pullRequestJsonPath = model.ReadJsonFile(pullRequestJsonPath);
pullRequestJsonPath = pullRequestJsonPath.Replace("$reviewer$", model.Environment.UserUniqueId);
Repository objRepository = new Repository(_workItemConfig);
string[] pullReqResponse = new string[2];
pullReqResponse = objRepository.CreatePullRequest(pullRequestJsonPath, repositoryId);
if (pullReqResponse.Length > 0)
{
if (!string.IsNullOrEmpty(pullReqResponse[0]) && !string.IsNullOrEmpty(pullReqResponse[1]))
{
model.Environment.pullRequests.Add(pullReqResponse[1], pullReqResponse[0]);
commentFile = GetJsonFilePath(model.IsPrivatePath, model.PrivateTemplatePath, model.SelectedTemplate, @"\PullRequests\Comments\" + commentFile);
//string.Format(templatesFolder + @"{0}\PullRequests\Comments\{1}", model.SelectedTemplate, commentFile);
if (File.Exists(commentFile))
{
commentFile = model.ReadJsonFile(commentFile);
PullRequestComments.Comments commentsList = JsonConvert.DeserializeObject<PullRequestComments.Comments>(commentFile);
if (commentsList.count > 0)
{
foreach (PullRequestComments.Value thread in commentsList.value)
{
string threadID = objRepository.CreateCommentThread(repositoryId, pullReqResponse[0], JsonConvert.SerializeObject(thread));
if (!string.IsNullOrEmpty(threadID))
{
if (thread.Replies != null && thread.Replies.Count > 0)
{
foreach (var reply in thread.Replies)
{
objRepository.AddCommentToThread(repositoryId, pullReqResponse[0], threadID, JsonConvert.SerializeObject(reply));
}
}
}
}
}
}
}
}
}
}
catch (Exception ex)
{
logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
AddMessage(model.id.ErrorId(), "Error while creating pull Requests: " + ex.Message);
}
}