public void MatchesCaptureGroupsFromCustomMessages() { // Arrange var format = @"^Merged PR #(?<PullRequestNumber>\d+) into (?<TargetBranch>[^\s]*) from (?:(?<SourceBranch>[^\s]*))"; var definition = "Mycustom"; config.MergeMessageFormats = new Dictionary <string, string> { [definition] = format }; var pr = 1234; var target = "master"; var source = "feature/2.0/example"; // Act var sut = new MergeMessage($"Merged PR #{pr} into {target} from {source}", config); // Assert sut.FormatName.ShouldBe(definition); sut.TargetBranch.ShouldBe(target); sut.MergedBranch.ShouldBe(source); sut.IsMergedPullRequest.ShouldBeTrue(); sut.PullRequestNumber.ShouldBe(pr); sut.Version.ShouldBe(new SemanticVersion(2)); }
internal async void InitAllList() { #pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 GetUnreadCount(); Timeline.Refresh(); if (Settings.IsMergeMentionAndComment) { MergeMessage.Refresh(); } else { Mention.Refresh(); Comment.Refresh(); CommentMention.Refresh(); } Favor.Refresh(); Message.Refresh(); #pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 try { (await Core.Api.Friendships.Groups.GetGroups()).Lists.ForEach(item => Groups.Add(item)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Groups))); } catch (Exception ex) when(ex is WebException || ex is HttpRequestException || ex is TaskCanceledException || ex is NullReferenceException) { } }
private static MergeMessage Inner(Commit mergeCommit, GitVersionContext context) { if (mergeCommit.Parents.Count() < 2) { return(null); } var mergeMessage = new MergeMessage(mergeCommit.Message, context.FullConfiguration); return(mergeMessage); }
public void EmptyMessageString(string message) { // Act var sut = new MergeMessage(message, _config); // Assert sut.TargetBranch.ShouldBeNull(); sut.MergedBranch.ShouldBeEmpty(); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBeNull(); sut.Version.ShouldBeNull(); }
private VersionField TryFindIncrementFromMergeMessage(ICommit?mergeCommit) { if (mergeCommit != null) { var mergeMessage = new MergeMessage(mergeCommit.Message, context.FullConfiguration); var config = context.FullConfiguration.GetConfigForBranch(mergeMessage.MergedBranch); if (config?.Increment != null && config.Increment != IncrementStrategy.Inherit) { return(config.Increment.Value.ToVersionField()); } } // Fallback to config increment value return(FindDefaultIncrementForBranch(context)); }
public void ParsesMergeMessage( string message, string expectedMergedBranch, string expectedTargetBranch, SemanticVersion expectedVersion) { // Act var sut = new MergeMessage(message, _config); // Assert sut.TargetBranch.ShouldBe(expectedTargetBranch); sut.MergedBranch.ShouldBe(expectedMergedBranch); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBeNull(); sut.Version.ShouldBe(expectedVersion); }
public void ParsesRemoteTrackingMergeMessage( string message, string expectedMergedBranch, string expectedTargetBranch, SemanticVersion expectedVersion) { // Act var sut = new MergeMessage(message, config); // Assert sut.FormatName.ShouldBe("RemoteTracking"); sut.TargetBranch.ShouldBe(expectedTargetBranch); sut.MergedBranch.ShouldBe(expectedMergedBranch); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBe(null); sut.Version.ShouldBe(expectedVersion); }
public void EmptyTagPrefix(string prefix) { // Arrange var message = "Updated some code."; var config = new Config { TagPrefix = prefix }; // Act var sut = new MergeMessage(message, config); // Assert sut.TargetBranch.ShouldBeNull(); sut.MergedBranch.ShouldBeEmpty(); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBeNull(); sut.Version.ShouldBeNull(); }
public void ParsesBitBucketPullMergeMessagev7( string message, string expectedMergedBranch, string expectedTargetBranch, SemanticVersion expectedVersion, int?expectedPullRequestNumber) { // Act var sut = new MergeMessage(message, config); // Assert sut.FormatName.ShouldBe("BitBucketPullv7"); sut.TargetBranch.ShouldBe(expectedTargetBranch); sut.MergedBranch.ShouldBe(expectedMergedBranch); sut.IsMergedPullRequest.ShouldBeTrue(); sut.PullRequestNumber.ShouldBe(expectedPullRequestNumber); sut.Version.ShouldBe(expectedVersion); }
public void ParseTfsGermanDEMessage( string message, string expectedMergedBranch, string expectedTargetBranch, SemanticVersion expectedVersion, int?expectedPullRequestNumber) { // Act var sut = new MergeMessage(message, _config); // Assert sut.MatchDefinition.ShouldBe("TfsMergeMessageGermanDE"); sut.TargetBranch.ShouldBe(expectedTargetBranch); sut.MergedBranch.ShouldBe(expectedMergedBranch); sut.IsMergedPullRequest.ShouldBeTrue(); sut.PullRequestNumber.ShouldBe(expectedPullRequestNumber); sut.Version.ShouldBe(expectedVersion); }
private static VersionField TryFindIncrementFromMergeMessage(Commit mergeCommit, GitVersionContext context) { if (mergeCommit != null) { var mergeMessage = new MergeMessage(mergeCommit.Message, context.FullConfiguration); if (mergeMessage.MergedBranch != null) { var config = context.FullConfiguration.GetConfigForBranch(mergeMessage.MergedBranch); if (config != null && config.Increment.HasValue && config.Increment != IncrementStrategy.Inherit) { return(config.Increment.Value.ToVersionField()); } } } // Fallback to patch return(VersionField.Patch); }
public void MatchesSingleCustomMessage() { // Arrange var message = "My custom message"; var definition = "Mycustom"; config.MergeMessageFormats = new Dictionary <string, string> { [definition] = message }; // Act var sut = new MergeMessage(message, config); // Assert sut.FormatName.ShouldBe(definition); sut.TargetBranch.ShouldBeNull(); sut.MergedBranch.ShouldBeEmpty(); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBe(null); sut.Version.ShouldBeNull(); }
public void ReturnsAfterFirstMatchingPattern() { // Arrange var format = @"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*"; var definition = "Mycustom"; config.MergeMessageFormats = new Dictionary <string, string> { [definition] = format, ["Default2"] = format, ["Default3"] = format }; // Act var sut = new MergeMessage("Merge branch 'this'", config); // Assert sut.FormatName.ShouldBe(definition); sut.TargetBranch.ShouldBeNull(); sut.MergedBranch.ShouldBe("this"); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBe(null); sut.Version.ShouldBeNull(); }
public void MatchesMultipleCustomMessages() { // Arrange var format = "My custom message"; var definition = "Mycustom"; config.MergeMessageFormats = new Dictionary <string, string> { ["Default2"] = "some example", ["Default3"] = "another example", [definition] = format }; // Act var sut = new MergeMessage(format, config); // Assert sut.FormatName.ShouldBe(definition); sut.TargetBranch.ShouldBeNull(); sut.MergedBranch.ShouldBeEmpty(); sut.IsMergedPullRequest.ShouldBeFalse(); sut.PullRequestNumber.ShouldBe(null); sut.Version.ShouldBeNull(); }
private static bool TryParse(Commit mergeCommit, GitVersionContext context, out MergeMessage mergeMessage) { mergeMessage = Inner(mergeCommit, context); return(mergeMessage != null); }
public async void RefreshWithoutGetUnreadCount() { if (Settings.IsMergeMentionAndComment) { switch (Header.FindIndex(item => item.IsActive)) { case 0: await Timeline.Refresh(); break; case 1: await MergeMessage.Refresh(); Header[1].UnreadCount = 0; break; case 2: await Favor.Refresh(); Header[2].UnreadCount = 0; break; case 3: await Message.Refresh(); Header[3].UnreadCount = 0; break; default: break; } } else { switch (Header.FindIndex(item => item.IsActive)) { case 0: await Timeline.Refresh(); break; case 1: await Mention.Refresh(); Header[1].UnreadCount = 0; break; case 2: await Comment.Refresh(); Header[2].UnreadCount = 0; break; case 3: await CommentMention.Refresh(); Header[3].UnreadCount = 0; break; case 4: await Favor.Refresh(); break; case 5: await Message.Refresh(); Header[5].UnreadCount = 0; break; default: break; } } UpdateUnreadHelper.Count = Header.Sum(item => item.UnreadCount); }