/// <summary> /// Detect valid scope based on the change list in the PR /// Get affected files and find scope based on directory that contains .sln file /// </summary> /// <returns></returns> List <string> GetRPScopes() { TaskLogger.LogInfo("Trying to get Pr info for PrNumber:'{0}'", GH_PRNumber.ToString()); FileSystemUtility fileSysUtil = new FileSystemUtility(); IEnumerable <string> prFileList = null; List <string> finalScopePathList = new List <string>(); if (!string.IsNullOrWhiteSpace(GH_RepositoryHtmlUrl)) { TaskLogger.LogInfo("Trying to get Pr info using PrNumber:'{0}', GitHubUrl:'{1}'", GH_PRNumber.ToString(), GH_RepositoryHtmlUrl); string repoName = string.Empty; //Split the url string[] tokens = GH_RepositoryHtmlUrl.Split(new char[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); //Get the last token which represents the repository name if (tokens != null) { repoName = tokens[tokens.Length - 1]; } prFileList = GHSvc.PR.GetPullRequestFileList(repoName, GH_PRNumber); } else if (GH_RepositoryId > 0) { TaskLogger.LogInfo("Trying to get Pr info using PrNumber:'{0}', GitHub Repo Id:'{1}'", GH_PRNumber.ToString(), GH_RepositoryId.ToString()); prFileList = GHSvc.PR.GetPullRequestFileList(GH_RepositoryId, GH_PRNumber); } TaskLogger.LogInfo(MessageImportance.Low, prFileList, "List of files from PR"); Dictionary <string, string> RPDirs = FindScopeFromPullRequestFileList(prFileList); //Dictionary<string, string> RPDirs = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); if (RPDirs.NotNullOrAny <KeyValuePair <string, string> >()) { finalScopePathList = RPDirs.Select <KeyValuePair <string, string>, string>((item) => item.Key).ToList <string>(); } //foreach(string filePath in prFileList) //{ // string slnDirPath = fileSysUtil.TraverUptoRootWithFileExtension(filePath); // if (Directory.Exists(slnDirPath)) // { // if(!RPDirs.ContainsKey(slnDirPath)) // { // RPDirs.Add(slnDirPath, slnDirPath); // } // } // else // { // TaskLogger.LogWarning("RPScope Detection: '{0}' does not exists", slnDirPath); // } //} //TaskLogger.LogInfo("Number of RPs detected", RPDirs); //return RPDirs.Select<KeyValuePair<string, string>, string>((item) => item.Key).ToList<string>(); return(finalScopePathList); }
/// <summary> /// Detect valid scope based on the change list in the PR /// Get affected files and find scope based on directory that contains .sln file /// </summary> /// <returns></returns> List <string> GetRPScopes() { FileSystemUtility fileSysUtil = new FileSystemUtility(); IEnumerable <string> prFileList = null; List <string> finalScopePathList = new List <string>(); List <string> intermediateList = new List <string>(); if (!string.IsNullOrWhiteSpace(GitHubRepositoryHtmlUrl)) { TaskLogger.LogInfo("Trying to get Pr info using PrNumber:'{0}', GitHubUrl:'{1}'", GH_PRNumber.ToString(), GitHubRepositoryHtmlUrl); string repoName = string.Empty; //Split the url string[] tokens = GitHubRepositoryHtmlUrl.Split(new char[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); //Get the last token which represents the repository name if (tokens != null) { repoName = tokens[tokens.Length - 1]; } if (GHSvc.IsRepoAuthorized(repoName)) { prFileList = GHSvc.PR.GetPullRequestFileList(repoName, GH_PRNumber); } } else { TaskLogger.LogWarning("You are not authorized to access '{0}', skipping detecting RP Scope", GitHubRepositoryHtmlUrl); } if (prFileList != null) { TaskLogger.LogInfo(MessageImportance.Low, prFileList, "List of files from PR"); Dictionary <string, string> RPDirs = FindScopeFromPullRequestFileList(prFileList); if (RPDirs.NotNullOrAny <KeyValuePair <string, string> >()) { intermediateList = RPDirs.Select <KeyValuePair <string, string>, string>((item) => item.Key).ToList <string>(); } if (DetectEnv.IsRunningUnderNonWindows) { foreach (string scopePath in intermediateList) { string newPath = scopePath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); finalScopePathList.Add(newPath); } } else { finalScopePathList = intermediateList; } } return(finalScopePathList); }