Skip to content

Commit 76fae48

Browse files
Make compatibility with GitExtensions v4.1 & Gerrit server v3.7.0 (#74)
* Fix missing method implementation OsShellUtil.OpenUrlInDefaultBrowser exception - Due to the move of GitCommands Fix the parsing of the remote command lines output to retrieve the gerrit change URI - Keep the legacy parsing using 'New Changes' line - Following gerrit v3.7.0 remote outputs modifications take care of '[NEW]' at the end of line - Use a global regex on the command line ouput to retrieve the change URI in bot cases - Add a unit test with both use cases with command outputs test resource files Update the README to indicates supported version (master-branch needs to be updated at release time depending of the new version the plugin will take) * Update README typo to respect conventions * Update following review recommendations
1 parent 6b1ba20 commit 76fae48

12 files changed

+129
-29
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ Use the following pattern to link revision data to Gerrit:
2525

2626
## Compatibility Version Matrix
2727

28-
| Git Extensions | Gerrit Plugin |
29-
|--------------------|---------------------|
30-
| v <= 3.5.x | v <= 1.3.2 |
31-
| 3.5.x < v <= 4.0.0 | 2.0.0 <= v <= 2.0.1 |
32-
| 4.0.1 <= v | 2.0.5 <= v |
28+
| Git Extensions | Gerrit Plugin |
29+
|---------------------|---------------------|
30+
| v <= 3.5.x | v <= 1.3.2 |
31+
| 3.5.x < v <= 4.0.0 | 2.0.0 <= v <= 2.0.1 |
32+
| 4.0.1 <= v <= 4.0.2 | 2.0.5 |
33+
| 4.1 <= v | master-branch |
3334

3435
## GitExtensions Plugin Template infomration
3536

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using System.IO;
3+
4+
namespace GitExtensions.GerritPlugin.Tests
5+
{
6+
[TestFixture]
7+
public class GerritUtilTests
8+
{
9+
[TestCase("NewChange_GerritLegacy", true)]
10+
[TestCase("UpdatedChange_GerritLegacy", false)]
11+
[TestCase("NewChange_GerritNew", true)]
12+
[TestCase("UpdatedChange_GerritNew", false)]
13+
[TestCase("UnparsableUri", false)]
14+
public void TestPublishedGerritChangeUriParsing(string commandPromptFileName, bool hadNewChange)
15+
{
16+
var commandPrompt = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "TestResources", $"{commandPromptFileName}.txt"));
17+
Assert.That(GerritUtil.HadNewChange(commandPrompt, out var changeUri), Is.EqualTo(hadNewChange));
18+
19+
var expectedChangeUri = hadNewChange ? "https://my.domain.test/c/MyProjectPath/MyProject/+/2664" : null;
20+
Assert.That(changeUri, Is.EqualTo(expectedChangeUri), "We ddidn't get the right change URI from remote command output");
21+
}
22+
}
23+
}

UnitTests/GitExtensions.GerritPlugin.Tests/GitExtensions.GerritPlugin.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\src\GitExtensions.GerritPlugin\GitExtensions.GerritPlugin.csproj" />
1717
</ItemGroup>
18+
19+
<ItemGroup>
20+
<None Update="TestResources\**\*.*">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</None>
23+
</ItemGroup>
1824
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
remote: Resolving deltas: 100% (122/122)
2+
remote: Processing changes: refs: 1, updated: 1, done
3+
remote:
4+
remote: SUCCESS
5+
remote:
6+
remote: New Changes:
7+
remote: https://my.domain.test/c/MyProjectPath/MyProject/+/2664 Testing a publish with only updates
8+
remote:
9+
remote:
10+
remote:
11+
To https://my.domain.test/MyProjectPath/MyProject
12+
* [new reference] HEAD -> refs/for/main
13+
Done
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
remote: Resolving deltas: 100% (122/122)
2+
remote: Processing changes: refs: 1, updated: 1, done
3+
remote:
4+
remote: SUCCESS
5+
remote:
6+
remote: https://my.domain.test/c/MyProjectPath/MyProject/+/2664 Testing a publish with new change [NEW]
7+
remote:
8+
remote:
9+
remote:
10+
To https://my.domain.test/MyProjectPath/MyProject
11+
* [new reference] HEAD -> refs/for/main
12+
Done
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
remote: Resolving deltas: 100% (122/122)
2+
remote: Processing changes: refs: 1, updated: 1, done
3+
remote:
4+
remote: SUCCESS
5+
remote:
6+
remote: https://my.domain.test/ Testing a publish with badly formated remote output [NEW]
7+
remote:
8+
remote:
9+
remote:
10+
To https://my.domain.test/MyProjectPath/MyProject
11+
* [new reference] HEAD -> refs/for/main
12+
Done
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
remote: Resolving deltas: 100% (122/122)
2+
remote: Processing changes: refs: 1, updated: 1, done
3+
remote:
4+
remote: SUCCESS
5+
remote:
6+
remote: Updated Changes:
7+
remote: https://my.domain.test/c/MyProjectPath/MyProject/+/2664 Testing a publish with only updates
8+
remote:
9+
remote:
10+
remote:
11+
To https://my.domain.test/MyProjectPath/MyProject
12+
* [new reference] HEAD -> refs/for/main
13+
Done
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
remote: Resolving deltas: 100% (122/122)
2+
remote: Processing changes: refs: 1, updated: 1, done
3+
remote:
4+
remote: SUCCESS
5+
remote:
6+
remote: https://my.domain.test/c/MyProjectPath/MyProject/+/2664 Testing a publish with only updates
7+
remote:
8+
remote:
9+
remote:
10+
To https://my.domain.test/MyProjectPath/MyProject
11+
* [new reference] HEAD -> refs/for/main
12+
Done

src/GitExtensions.GerritPlugin/FormGerritChangeSubmitted.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Windows.Forms;
2+
using GitCommands;
23
using GitUI;
34

45
namespace GitExtensions.GerritPlugin

src/GitExtensions.GerritPlugin/FormGerritPublish.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using GitUIPluginInterfaces;
1111
using JetBrains.Annotations;
1212
using ResourceManager;
13+
using System.Text.RegularExpressions;
1314

1415
namespace GitExtensions.GerritPlugin
1516
{
@@ -104,31 +105,9 @@ private bool PublishChange(IWin32Window owner)
104105

105106
if (!pushCommand.ErrorOccurred)
106107
{
107-
bool hadNewChanges = false;
108-
string change = null;
109-
110-
foreach (string line in pushCommand.CommandOutput.Split('\n'))
111-
{
112-
if (hadNewChanges)
113-
{
114-
const char esc = (char)27;
115-
change = line
116-
.RemovePrefix("remote:")
117-
.SubstringUntilLast(esc)
118-
.Trim()
119-
.SubstringUntil(' ');
120-
break;
121-
}
122-
123-
if (line.Contains("New Changes"))
124-
{
125-
hadNewChanges = true;
126-
}
127-
}
128-
129-
if (change != null)
108+
if(GerritUtil.HadNewChange(pushCommand.CommandOutput, out var changeUri))
130109
{
131-
FormGerritChangeSubmitted.ShowSubmitted(owner, change);
110+
FormGerritChangeSubmitted.ShowSubmitted(owner, changeUri);
132111
}
133112
}
134113

0 commit comments

Comments
 (0)