Skip to content

Commit

Permalink
Search all assemblies under solution
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Nov 30, 2024
1 parent b257f37 commit b116550
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions Sdk/FeatureImpactAnalyzer/GitHubPullRequestAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Octokit;
using Speckle.Connectors.Common;
using Speckle.Sdk;

namespace FeatureImpactAnalyzer;

Expand All @@ -26,13 +27,13 @@ public async Task<List<FeatureImpactReport>> AnalyzePullRequestChangesAsync(
int pullRequestNumber
)
{
var pullRequest = await _client
.PullRequest.Get(repositoryOwner, repositoryName, pullRequestNumber)
.ConfigureAwait(true);
// var pullRequest = await _client
// .PullRequest.Get(repositoryOwner, repositoryName, pullRequestNumber)
// .ConfigureAwait(true);
var changedFiles = await _client
.PullRequest.Files(repositoryOwner, repositoryName, pullRequestNumber)
.ConfigureAwait(true);
Console.WriteLine($"Changed Files:\n {changedFiles}");
Console.WriteLine($"Changed Files Count:\n {changedFiles.Count}");

var sideEffectReports = new List<FeatureImpactReport>();

Expand Down Expand Up @@ -98,7 +99,7 @@ private List<int> ExtractModifiedLines(string filePatch)
return modifiedLines;
}

private List<string> GetFeatureImpactAttributes(string methodName)
private List<string> GetFeatureImpactAttributesOld(string methodName)
{
var impactedFeatures = new List<string>();

Expand Down Expand Up @@ -127,6 +128,63 @@ var method in type.GetMethods(
return impactedFeatures;
}

private List<string> GetFeatureImpactAttributes(string methodName)
{
var impactedFeatures = new List<string>();

// Load all assemblies in the current AppDomain
var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();

// Dynamically load assemblies from the solution directory
string? solutionDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (!string.IsNullOrEmpty(solutionDirectory))
{
var dllFiles = Directory.GetFiles(solutionDirectory, "*.dll", SearchOption.AllDirectories);
foreach (var dll in dllFiles)
{
try
{
var loadedAssembly = Assembly.LoadFrom(dll);
if (!assemblies.Contains(loadedAssembly))
{
assemblies.Add(loadedAssembly);
}
}
catch (Exception ex) when (!ex.IsFatal())
{
// Log or handle exceptions when loading assemblies
Console.WriteLine($"Failed to load assembly: {dll}. Error: {ex.Message}");
}
}
}

// Process each assembly
foreach (var assembly in assemblies)
{
foreach (var type in assembly.GetTypes())
{
foreach (
var method in type.GetMethods(
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static
)
)
{
if (method.Name == methodName)
{
// Find custom attributes of type FeatureImpactAttribute
var attributes = method.GetCustomAttributes(typeof(FeatureImpactAttribute), true);
foreach (FeatureImpactAttribute attribute in attributes.Cast<FeatureImpactAttribute>())
{
impactedFeatures.AddRange(attribute.Features);
}
}
}
}
}

return impactedFeatures;
}

public async Task CommentPullRequestWithSideEffectsAsync(
string repositoryOwner,
string repositoryName,
Expand Down

0 comments on commit b116550

Please sign in to comment.