public async Task <bool> UpdateItemWithSourceControlInfoAsync(Item item, GitCommitInfo commitInfo) { WorkItem azureWorkItem = await InternalGetByExternalIDAsync(item.ID); JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = "ArtifactLink", url = $"vstfs:///Git/Ref/{commitInfo.ProjectID}%2F{commitInfo.RepositoryID}%2FGBfeatures%2F{commitInfo.BranchName}", attributes = new { name = "Branch", comment = "Comment" }, } }); int.TryParse(item.ID, out int azureItemID); WorkItem remoteResult = await ProcessWorkItemTrackingHttpAction(x => x.UpdateWorkItemAsync(patchDocument, azureWorkItem.Id.GetValueOrDefault())); return(remoteResult != null); }
public void Setup() { _commitInfo = new GitCommitInfo(); _repoDirectory = DirectoryUtil.GetGitRepositoryDirectory(); _commitInfo.LocalPath = _repoDirectory; _commitInfo.OpenRepository(); }
public void Branches_Success() { string gitOutput = "65a8e52|Personal|1621856829|Merge branch 'fix/PrinterJams' into alpha| (tag: Ver1.1.0-alpha.0006b, origin/alpha, alpha)"; GitCommitInfo git = new GitCommitInfo(gitOutput); Assert.AreEqual(2, git.Branches.Count, "A10:"); Assert.AreEqual("origin/alpha", git.Branches[0], "A20:"); Assert.AreEqual("alpha", git.Branches[1], "A30:"); }
public void MultipleGitTags() { string gitOutput = "51514b1|Personal|1621683273|Merging Branch: fix/somestuff | 1.0.14| (tag: moreinfo, tag: Ver1.0.14, origin/main, main)"; GitCommitInfo git = new GitCommitInfo(gitOutput); Assert.AreEqual(2, git.Tags.Count, "A10:"); Assert.AreEqual("moreinfo", git.Tags[0], "A20:"); Assert.AreEqual("Ver1.0.14", git.Tags[1], "A30:"); }
public void ConstructorFromStringBasics_Success() { string gitOutput = "dab4612|Bob Marley|1621171608|fax increased| (origin/beta)"; GitCommitInfo git = new GitCommitInfo(gitOutput); Assert.AreEqual("dab4612", git.CommitHash, "A10:"); Assert.AreEqual("Bob Marley", git.Committer, "A20:"); Assert.AreEqual("fax increased", git.Message, "A30:"); Assert.AreEqual(0, git.Tags.Count, "A40:"); Assert.AreEqual(1, git.Branches.Count, "A50:"); Assert.AreEqual("origin/beta", git.Branches[0], "A60:"); DateTime d1 = new DateTime(2021, 5, 16, 9, 26, 48); Assert.AreEqual(d1, git.DateCommitted, "A70:"); }
public async Task <OperationResult <GitCommitInfo> > CreateNewBranch(string name) { OperationResult <GitCommitInfo> result = new OperationResult <GitCommitInfo>(); using (var connection = new VssConnection(_azureDevopsConfiguration.Uri, new VssBasicCredential(string.Empty, _azureDevopsConfiguration.Token))) using (var client = connection.GetClient <GitHttpClient>()) { var repositories = await client.GetRepositoriesAsync(_azureDevopsConfiguration.ProjectName); var repository = repositories?.First(r => string.Compare(r.Name, _azureDevopsConfiguration.GITSourceControl.RepositoryName, true) == 0); if (repository == null) { throw new Exception($"Unable to find repository {_azureDevopsConfiguration.GITSourceControl.RepositoryName} in the project {_azureDevopsConfiguration.ProjectName}. List of repositories : {String.Join(",", repositories.Select(r => r.Name).ToArray())})"); } var masterBranch = await client.GetBranchAsync(repository.Id, _azureDevopsConfiguration.GITSourceControl.MasterBranch); if (masterBranch == null) { throw new Exception($"Unable to find masterBranch {_azureDevopsConfiguration.GITSourceControl.MasterBranch}"); } string branchCommitID = await InnerCreateBranch(name, client, repository.Id, masterBranch.Commit.CommitId); GitCommitInfo gci = new GitCommitInfo(); gci.ProjectID = repository.ProjectReference.Id.ToString(); gci.RepositoryID = repository.Id.ToString(); gci.CommitID = branchCommitID; gci.BranchName = name; result.Item = gci; result.HasSucceed = !string.IsNullOrWhiteSpace(branchCommitID); } return(result); }
private static List <GitCommitInfo> ParseGitCommitsSinceLastPackage(ConfigFile config, string gitPath) { List <GitCommitInfo> commitsSinceLastPackage = new List <GitCommitInfo>(); string solutionDir = Path.GetDirectoryName(config.SolutionPath); // Retrieve the git history for the repository ProcessStartInfo gitStartInfo = new ProcessStartInfo { FileName = gitPath, WorkingDirectory = solutionDir, Arguments = "--no-pager log --name-only --oneline --since=\"2015\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; Process gitProc = new Process(); gitProc.StartInfo = gitStartInfo; gitProc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (string.IsNullOrEmpty(e.Data)) { return; } // Begin of a new commit if (e.Data.Contains(' ')) { string line = e.Data.Trim(); int indexOfSeparator = line.IndexOf(' '); string commitId = line.Substring(0, indexOfSeparator); if (Regex.IsMatch(commitId, @"\b[0-9a-f]{5,40}\b")) { string commitTitleAndMessage = line.Substring(indexOfSeparator, line.Length - indexOfSeparator).Trim(); string[] commitMessageToken = commitTitleAndMessage.Split('#'); string commitTitle; string commitMessage; // Received the expected commit message format in the form // // Title / Headline // #CHANGE: Description // #ADD: More Description // ... if (commitMessageToken.Length > 1) { commitTitle = commitMessageToken[0].Trim(); commitMessage = "#" + string.Join(Environment.NewLine + "#", commitMessageToken, 1, commitMessageToken.Length - 1); } // Received an unexpected message format else { commitMessageToken = commitTitleAndMessage.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); commitTitle = commitMessageToken[0]; commitMessage = string.Empty; } // Stop reading as soon as we see a package update commit if (string.Equals(commitTitle, PackageUpdateCommitTitle, StringComparison.InvariantCultureIgnoreCase) && commitMessage.IndexOf(PackageUpdateCommitMessageBegin, StringComparison.InvariantCultureIgnoreCase) >= 0) { gitProc.CancelOutputRead(); if (!gitProc.HasExited) { gitProc.Kill(); } return; } // Start collecting files for the new commit commitsSinceLastPackage.Add(new GitCommitInfo { Id = commitId, Title = commitTitle, Message = commitMessage }); return; } } // File list entry GitCommitInfo commitInfo = commitsSinceLastPackage[commitsSinceLastPackage.Count - 1]; string filePathFull = Path.GetFullPath(Path.Combine(solutionDir, e.Data)); commitInfo.FilePaths.Add(filePathFull); return; }; gitProc.Start(); gitProc.BeginOutputReadLine(); gitProc.WaitForExit(); return(commitsSinceLastPackage); }
public Task <bool> UpdateItemWithSourceControlInfoAsync(Item item, GitCommitInfo commitInfo) { throw new NotImplementedException(); }
private static List <GitCommitInfo> ParseGitCommitsSinceLastPackage(ConfigFile config, string gitPath) { StringBuilder commitMessageBuilder = new StringBuilder(); List <GitCommitInfo> commitsSinceLastPackage = new List <GitCommitInfo>(); // Retrieve the git history for the repository string solutionDir = Path.GetDirectoryName(config.SolutionPath); ProcessStartInfo gitStartInfo = new ProcessStartInfo { FileName = gitPath, WorkingDirectory = solutionDir, Arguments = "--no-pager log --name-only --abbrev-commit --format=medium --since=\"2015\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; Process gitProc = new Process(); gitProc.StartInfo = gitStartInfo; gitProc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { // Starting the next commit? Process the last we accumulated if (e.Data.StartsWith("commit ") && commitMessageBuilder.Length > 0) { // Parse the accumulated multi-line commit message bool continueRead; GitCommitInfo commitInfo = ParseGitCommitMessageChunk( commitMessageBuilder.ToString(), solutionDir, out continueRead); if (commitInfo != null) { commitsSinceLastPackage.Add(commitInfo); } // Stop reading once the parse method decided we have the oldest commit we need if (!continueRead) { gitProc.CancelOutputRead(); if (!gitProc.HasExited) { gitProc.Kill(); } } // Start over with the next commit message commitMessageBuilder.Clear(); } commitMessageBuilder.AppendLine(e.Data); }; gitProc.Start(); gitProc.BeginOutputReadLine(); gitProc.WaitForExit(); // Handle the remaining output if (commitMessageBuilder.Length > 0) { bool continueRead; GitCommitInfo commitInfo = ParseGitCommitMessageChunk( commitMessageBuilder.ToString(), solutionDir, out continueRead); if (commitInfo != null) { commitsSinceLastPackage.Add(commitInfo); } } return(commitsSinceLastPackage); }
/// <summary> /// Calculate version of project when Target is Beta /// </summary> /// <param name="comparisonBranch"></param> private void CalculateBetaVersion(GitBranchInfo comparisonBranch) { // Find the parents max version number. GitCommitInfo commitBeta = comparisonBranch.LatestCommitOnBranch; // Look for the highest version number from one of its parents and keep it. SemVersion newestVersion = new SemVersion(0, 0, 0); foreach (string commitHash in commitBeta.ParentCommits) { GitCommitInfo commitInfo = CISession.GitProcessor.GetCommitInfo(commitHash); SemVersion parentVersion = commitInfo.GetGreatestVersionTag(); if (parentVersion > newestVersion) { newestVersion = parentVersion; } } SemVersionPreRelease updatedBeta; // Build New PreRelease tag based upon old, but with new number and type set to Beta. if (mostRecentBranchTypeVersion > newestVersion) { newestVersion = mostRecentBranchTypeVersion; updatedBeta = new SemVersionPreRelease(newestVersion.Prerelease); } else { // Get pre-release of the newest version, which is not a beta branch SemVersionPreRelease preOld = new SemVersionPreRelease(newestVersion.Prerelease); // Get pre-release of most current beta branch version SemVersionPreRelease currentBeta = new SemVersionPreRelease(mostRecentBranchTypeVersion.Prerelease); // Update the beta to be of the Increment Type if (currentBeta.IncrementType < preOld.IncrementType) { updatedBeta = new SemVersionPreRelease(currentBeta.ReleaseType, currentBeta.ReleaseNumber, preOld.IncrementType); } else { updatedBeta = currentBeta; } newestVersion = new SemVersion(newestVersion.Major, newestVersion.Minor, newestVersion.Patch, updatedBeta.Tag()); } // Increase version if (incrementMinor) { updatedBeta.BumpMinor(); } else if (incrementPatch) { updatedBeta.BumpPatch(); } else if (incrementMajor) { updatedBeta.BumpMajor(); } else { updatedBeta.BumpVersion(); } newVersion = new SemVersion(newestVersion.Major, newestVersion.Minor, newestVersion.Patch, updatedBeta.Tag()); }