private async Task <RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch) { var remoteInfo = new RemoteInfo(); var localFolder = repositoryUri; if (await _gitDriver.IsGitRepo(repositoryUri)) { // Check the origin remotes var origin = await _gitDriver.GetRemoteForPlatform(repositoryUri, PlatformHost); if (origin != null) { remoteInfo.LocalRepositoryUri = await _gitDriver.DiscoverRepo(repositoryUri); // Set to the folder, because we found a remote git repository repositoryUri = origin.Url; remoteInfo.BranchName = targetBranch ?? await _gitDriver.GetCurrentHead(remoteInfo.LocalRepositoryUri); remoteInfo.RemoteName = origin.Name; remoteInfo.WorkingFolder = localFolder; } } else { throw new NuKeeperException("No git repository found"); } return(RepositorySettings(repositoryUri, remoteInfo)); }
private async Task <RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch) { var remoteInfo = new RemoteInfo(); var localFolder = repositoryUri; if (await _gitDriver.IsGitRepo(repositoryUri)) { // Check the origin remotes var origin = await _gitDriver.GetRemoteForPlatform(repositoryUri, PlatformHost); if (origin != null) { remoteInfo.LocalRepositoryUri = await _gitDriver.DiscoverRepo(repositoryUri); // Set to the folder, because we found a remote git repository repositoryUri = origin.Url; remoteInfo.BranchName = targetBranch ?? await _gitDriver.GetCurrentHead(remoteInfo.LocalRepositoryUri); remoteInfo.RemoteName = origin.Name; remoteInfo.WorkingFolder = localFolder; } } else { throw new NuKeeperException("No git repository found"); } // URL pattern is // https://{org}.visualstudio.com/{project}/_git/{repo} or // https://{org}.visualstudio.com/_git/{repo} for the default repo var path = repositoryUri.AbsolutePath; var pathParts = path.Split('/') .Where(s => !string.IsNullOrWhiteSpace(s)) .ToList(); var org = repositoryUri.Host.Split('.')[0]; string repoName, project; if (pathParts.Count == 3) { project = pathParts[0]; repoName = pathParts[2]; } else if (pathParts.Count == 4) { project = pathParts[1]; repoName = pathParts[3]; } else if (pathParts.Count == 2) { project = pathParts[1]; repoName = pathParts[1]; } else { throw new NuKeeperException("Unknown local format. Format should be https://{org}.visualstudio.com/_git/{repo}"); } return(RepositorySettings(org, project, repoName, remoteInfo)); }
private async Task <RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch) { var remoteInfo = new RemoteInfo(); var localCopy = repositoryUri; if (await _gitDriver.IsGitRepo(repositoryUri)) { // Check the origin remotes var origin = await _gitDriver.GetRemoteForPlatform(repositoryUri, PlatformHost); if (origin != null) { remoteInfo.LocalRepositoryUri = await _gitDriver.DiscoverRepo(localCopy); // Set to the folder, because we found a remote git repository repositoryUri = origin.Url; remoteInfo.WorkingFolder = localCopy; remoteInfo.BranchName = targetBranch ?? await _gitDriver.GetCurrentHead(remoteInfo.LocalRepositoryUri); remoteInfo.RemoteName = origin.Name; } } else { throw new NuKeeperException("No git repository found"); } // URL pattern is // https://dev.azure.com/{org}/{project}/_git/{repo}/ // for a organisation or // https://dev.azure.com/{owner}/_git/{repo} // for a private repository var path = repositoryUri.AbsolutePath; var pathParts = path.Split('/') .Where(s => !string.IsNullOrWhiteSpace(s)) .ToArray(); var indexOfGit = Array.FindIndex(pathParts, t => t.Equals("_git", StringComparison.InvariantCultureIgnoreCase)); if (indexOfGit == 2 && pathParts.Length == 4) { return(CreateRepositorySettings( pathParts[0], //org repositoryUri, //uri Uri.UnescapeDataString(pathParts[1]), // project Uri.UnescapeDataString(pathParts[3]) // reponame )); } else if (indexOfGit == 1 && pathParts.Length == 3) { return(CreateRepositorySettings( null, //org repositoryUri, //uri Uri.UnescapeDataString(pathParts[0]), // project Uri.UnescapeDataString(pathParts[2]) // reponame )); } return(null); }
private async Task <RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch) { var remoteInfo = new RemoteInfo(); var localFolder = repositoryUri; if (await _gitDriver.IsGitRepo(repositoryUri)) { // Check the origin remotes var origin = await _gitDriver.GetRemoteForPlatform(repositoryUri, PlatformHost); if (origin != null) { remoteInfo.LocalRepositoryUri = await _gitDriver.DiscoverRepo(repositoryUri); // Set to the folder, because we found a remote git repository repositoryUri = origin.Url; remoteInfo.BranchName = targetBranch ?? await _gitDriver.GetCurrentHead(remoteInfo.LocalRepositoryUri); remoteInfo.RemoteName = origin.Name; remoteInfo.WorkingFolder = localFolder; } } else { throw new NuKeeperException("No git repository found"); } // general pattern is https://github.com/owner/reponame.git // from this we extract owner and repo name var path = repositoryUri.AbsolutePath; var pathParts = path.Split('/') .Where(s => !string.IsNullOrWhiteSpace(s)) .ToList(); var repoOwner = pathParts[0]; var repoName = pathParts[1].Replace(".git", string.Empty); return(new RepositorySettings { ApiUri = new Uri("https://api.github.com/"), RepositoryUri = repositoryUri, RepositoryName = repoName, RepositoryOwner = repoOwner, RemoteInfo = remoteInfo }); }
private async Task <RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch) { var remoteInfo = new RemoteInfo(); var localCopy = repositoryUri; if (await _gitDriver.IsGitRepo(repositoryUri)) { // Check the origin remotes var origin = await _gitDriver.GetRemoteForPlatform(repositoryUri, PlatformHost); if (origin != null) { remoteInfo.LocalRepositoryUri = await _gitDriver.DiscoverRepo(localCopy); // Set to the folder, because we found a remote git repository repositoryUri = origin.Url; remoteInfo.WorkingFolder = localCopy; remoteInfo.BranchName = targetBranch ?? await _gitDriver.GetCurrentHead(remoteInfo.LocalRepositoryUri); remoteInfo.RemoteName = origin.Name; } } else { throw new NuKeeperException("No git repository found"); } // URL pattern is // https://dev.azure.com/{org}/{project}/_git/{repo}/ var path = repositoryUri.AbsolutePath; var pathParts = path.Split('/') .Where(s => !string.IsNullOrWhiteSpace(s)) .ToList(); if (pathParts.Count != 4) { return(null); } var org = pathParts[0]; var project = Uri.UnescapeDataString(pathParts[1]); var repoName = Uri.UnescapeDataString(pathParts[3]); return(CreateRepositorySettings(org, repositoryUri, project, repoName, remoteInfo)); }
private async Task <RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch) { var remoteInfo = new RemoteInfo(); var localFolder = repositoryUri; if (await _gitDriver.IsGitRepo(repositoryUri)) { // Check the origin remotes var origin = (await _gitDriver.GetRemotes(repositoryUri)).FirstOrDefault(); if (origin != null) { var repo = await _gitDriver.DiscoverRepo(repositoryUri); // Set to the folder, because we found a remote git repository if (repo != null && (repo.Segments.Last() == @".git/")) { var newSegments = repo.Segments.Take(repo.Segments.Length - 1).ToArray(); newSegments[newSegments.Length - 1] = newSegments[newSegments.Length - 1].TrimEnd('/'); var ub = new UriBuilder(repo); ub.Path = string.Concat(newSegments); //ub.Query=string.Empty; //maybe? repo = ub.Uri; } remoteInfo.LocalRepositoryUri = repo; repositoryUri = origin.Url; remoteInfo.BranchName = targetBranch ?? await _gitDriver.GetCurrentHead(remoteInfo.LocalRepositoryUri); remoteInfo.RemoteName = origin.Name; remoteInfo.WorkingFolder = localFolder; } } else { throw new NuKeeperException("No git repository found"); } var remoteSettings = await CreateSettingsFromRemote(repositoryUri, targetBranch); return(await InternalCreateRepositorySettings(remoteSettings.ApiUri, remoteSettings.RepositoryUri, remoteSettings.RepositoryName, remoteSettings.RepositoryOwner, remoteInfo)); }