Skip to content

Commit c2684e5

Browse files
committed
Support authless pipeline analysis with mcp and copilot agent
1 parent 703c7de commit c2684e5

File tree

6 files changed

+145
-55
lines changed

6 files changed

+145
-55
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- @azure Rule - Use Azure Best Practices: When generating code for Azure, running terminal commands for Azure, or performing operations related to Azure, invoke your `azure_development-get_best_practices` tool if available.
1+
- @azure Rule - Use Azure Best Practices: When generating code for Azure, running terminal commands for Azure, or performing operations related to Azure, invoke your `azure_development-get_best_practices` tool if available.

.github/workflows/copilot-setup-steps.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ jobs:
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
17+
18+
- uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: 9.0.x
21+
22+
- name: Build azsdk cli
23+
run: |
24+
set -ex
25+
dotnet publish -f net8.0 -c Release -r linux-x64 -p:PublishSingleFile=true --self-contained --output ./artifacts/linux-x64 ./tools/azsdk-cli/Azure.Sdk.Tools.Cli/Azure.Sdk.Tools.Cli.csproj
26+
cp ./artifacts/linux-x64/azsdk $GITHUB_WORKSPACE/azsdk
27+
$GITHUB_WORKSPACE/azsdk --help

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/LogAnalysisHelper.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Security.Policy;
12
using Azure.Sdk.Tools.Cli.Models;
23

34
namespace Azure.Sdk.Tools.Cli.Helpers;
@@ -39,6 +40,9 @@ public class LogAnalysisHelper(ILogger<LogAnalysisHelper> logger) : ILogAnalysis
3940
{
4041
private readonly ILogger<LogAnalysisHelper> logger = logger;
4142

43+
public const int DEFAULT_BEFORE_LINES = 20;
44+
public const int DEFAULT_AFTER_LINES = 20;
45+
4246
// Built-in error keywords for robust error detection
4347
private static readonly HashSet<Keyword> defaultErrorKeywords =
4448
[
@@ -75,6 +79,12 @@ public class LogAnalysisHelper(ILogger<LogAnalysisHelper> logger) : ILogAnalysis
7579
];
7680

7781
public async Task<List<LogEntry>> AnalyzeLogContent(string filePath, List<string>? keywordOverrides, int? beforeLines, int? afterLines)
82+
{
83+
using var stream = new StreamReader(filePath);
84+
return await AnalyzeLogContent(stream, keywordOverrides, beforeLines, afterLines, filePath: filePath);
85+
}
86+
87+
public async Task<List<LogEntry>> AnalyzeLogContent(StreamReader reader, List<string>? keywordOverrides, int? beforeLines, int? afterLines, string url = "", string filePath = "")
7888
{
7989
var keywords = defaultErrorKeywords;
8090
if (keywordOverrides?.Count > 0)
@@ -86,14 +96,13 @@ public async Task<List<LogEntry>> AnalyzeLogContent(string filePath, List<string
8696
}
8797
}
8898

89-
beforeLines ??= 3;
90-
afterLines ??= 20;
99+
beforeLines ??= DEFAULT_BEFORE_LINES;
100+
afterLines ??= DEFAULT_AFTER_LINES;
91101
var before = new Queue<string>((int)beforeLines);
92102
var after = new Queue<string>((int)afterLines);
93103
var maxAfterLines = afterLines ?? 100;
94104

95105
var errors = new List<LogEntry>();
96-
using var reader = new StreamReader(filePath);
97106

98107
var lineNumber = 0;
99108
string? line;
@@ -127,12 +136,20 @@ public async Task<List<LogEntry>> AnalyzeLogContent(string filePath, List<string
127136
var fullContext = before.Concat(after).ToList();
128137
before.Clear();
129138
after.Clear();
130-
errors.Add(new LogEntry
139+
var entry = new LogEntry
131140
{
132-
File = filePath,
133141
Line = lineNumber,
134142
Message = string.Join(Environment.NewLine, fullContext)
135-
});
143+
};
144+
if (!string.IsNullOrEmpty(url))
145+
{
146+
entry.Url = url;
147+
}
148+
if (!string.IsNullOrEmpty(filePath))
149+
{
150+
entry.File = filePath;
151+
}
152+
errors.Add(entry);
136153
}
137154
}
138155

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/TokenUsageHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public void LogCost()
6969
Console.WriteLine("--------------------------------------------------------------------------------");
7070
}
7171

72-
public static TokenUsageHelper operator +(TokenUsageHelper a, TokenUsageHelper b) => new()
72+
public static TokenUsageHelper operator +(TokenUsageHelper a, TokenUsageHelper? b) => new()
7373
{
74-
Models = a.Models.Union(b.Models).ToList(),
75-
PromptTokens = a.PromptTokens + b.PromptTokens,
76-
CompletionTokens = a.CompletionTokens + b.CompletionTokens,
77-
InputCost = a.InputCost + b.InputCost,
78-
OutputCost = a.OutputCost + b.OutputCost,
74+
Models = a.Models.Union(b?.Models ?? []).ToList(),
75+
PromptTokens = a.PromptTokens + (b?.PromptTokens ?? 0),
76+
CompletionTokens = a.CompletionTokens + (b?.CompletionTokens ?? 0),
77+
InputCost = a.InputCost + (b?.InputCost ?? 0),
78+
OutputCost = a.OutputCost + (b?.OutputCost ?? 0),
7979
};
8080
}

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Models/Responses/LogAnalysisResponse.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override string ToString()
3737
output += $"### Suggested Fix:" + Environment.NewLine +
3838
$"{SuggestedFix}" + Environment.NewLine + Environment.NewLine +
3939
$"### Errors:" + Environment.NewLine +
40-
$"{string.Join(Environment.NewLine+Environment.NewLine, Errors.Select(e => $"--> {e.File}:{e.Line}{Environment.NewLine}{e.Message}"))}" +
40+
$"{string.Join(Environment.NewLine + Environment.NewLine, Errors.Select(e => $"--> {e.File}:{e.Line}{Environment.NewLine}{e.Message}"))}" +
4141
Environment.NewLine;
4242
}
4343

@@ -49,7 +49,10 @@ public class LogEntry
4949
{
5050
[JsonPropertyName("file")]
5151
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
52-
public string File { get; set; } = string.Empty;
52+
public string File { get; set; }
53+
[JsonPropertyName("url")]
54+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
55+
public string Url { get; set; }
5356
[JsonPropertyName("line")]
5457
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
5558
public int? Line { get; set; }

0 commit comments

Comments
 (0)