Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProjectBranchListener #5144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/SLCore.UnitTests/Listener/BranchListenerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Collections.Generic;
using System.Threading.Tasks;
using SonarLint.VisualStudio.SLCore.Core;
using SonarLint.VisualStudio.SLCore.Listener;
using SonarLint.VisualStudio.TestInfrastructure;

namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener
{
[TestClass]
public class BranchListenerTests
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<BranchListener, ISLCoreListener>();
}

[TestMethod]
public void Mef_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<BranchListener>();
}

[TestMethod]
public async Task MatchSonarProjectBranch_ReturnsMainBranch()
{
var param = new MatchSonarProjectBranchParams
{
configurationScopeId = "scopeId",
mainSonarBranchName = "mainBranch",
allSonarBranchesNames = new List<string> { "branch1", "branch2", "mainBranch" }
};

var testSubject = new BranchListener();

var result = await testSubject.MatchSonarProjectBranch(param);

result.matchedSonarBranch.Should().Be("mainBranch");
}

[TestMethod]
[DataRow(null)]
[DataRow(5)]
[DataRow("something")]
public void DidChangeMatchedSonarProjectBranch_ReturnsTaskCompleted(object parameter)
{
var testSubject = new BranchListener();

var result = testSubject.DidChangeMatchedSonarProjectBranch(parameter);

result.Should().Be(Task.CompletedTask);
}
}
}
64 changes: 64 additions & 0 deletions src/SLCore/Listener/BranchListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using SonarLint.VisualStudio.SLCore.Core;

namespace SonarLint.VisualStudio.SLCore.Listener
{
[Export(typeof(ISLCoreListener))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class BranchListener : ISLCoreListener
{
/// <summary>
/// Stub method for compability with SLCore.
/// </summary>
/// <param name="parameters">Parameter's here for compability we discard it</param>
/// <remarks>This will be implemented properly in the future when needed but features we support does not need branch awareness for now</remarks>
public async Task<MatchSonarProjectBranchResponse> MatchSonarProjectBranch(MatchSonarProjectBranchParams parameters)
{
return new MatchSonarProjectBranchResponse { matchedSonarBranch = parameters.mainSonarBranchName };
}

/// <summary>
/// Stub method for compability with SLCore.
/// </summary>
/// <param name="parameters">Parameter's here for compability we discard it</param>
/// <remarks>This will be implemented properly in the future when needed but features we support does not need branch awareness for now</remarks>
public Task DidChangeMatchedSonarProjectBranch(object parameters)
{
return Task.CompletedTask;
}
}

public class MatchSonarProjectBranchParams
{
public string configurationScopeId;
public string mainSonarBranchName;
public List<string> allSonarBranchesNames;
}

public class MatchSonarProjectBranchResponse
{
public string matchedSonarBranch;
}
}