This repository contains a .NET Core library for interacting with the SonarCloud API. The library wraps the API endpoints and provides a strongly-typed, easy-to-use interface for making API calls from your .NET applications.
- Easy integration with SonarCloud API
- Strongly-typed responses
- Supports .NET Core applications
- Asynchronous API calls
- Error handling and logging
To install the package, use the following command in your .NET Core project:
dotnet add package PMDEvers.SonarCloud.NET
Alternatively, you can add it manually to your .csproj
file:
<PackageReference Include="PMDEvers.SonarCloud.NET" Version="0.1.0" />
Here are some basic examples of how to use the library:
First, initialize the SonarCloudClient
with your SonarCloud token:
using SonarCloud.NET;
using SonarCloud.NET.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSonarCloudClient(o => {
o.AccessToken = "<sonarcloud-token-here>";
});
To fetch information about a specific project:
var result = await client.Projects.Search(new() {
Organization = "my-org"
});
foreach(var project in result.Components)
{
Console.WriteLine(project.Name);
}
If you're using writing a script or console application:
public static async Task Main(string[] args)
{
var sc = new ServiceCollection();
sc.AddSonarCloudClient(cfg => cfg.AccessToken = MY_API_KEY);
sc.AddLogging();
var provider = sc.BuildServiceProvider();
var sonarClient = provider.GetService<ISonarCloudApiClient>();
}
You must provide a SonarCloud token to authenticate your requests. You can generate a token from your SonarCloud account under the Security section.
Be mindful of the API rate limits imposed by SonarCloud. The client includes built-in handling for rate limit responses, but you should design your application to respect these limits and implement retry logic as needed.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any bugs or have feature requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.