Skip to content

Commit

Permalink
Adding link to error log in jobs (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankreyesgarcia authored Mar 5, 2024
1 parent e73a79a commit 50b9428
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String clientError() {
public String logLine() {
return ("2. The failure is identified from the logs generated in the build process\n " +
"\n" +
">%s.").formatted(breakingChange.getErrorInfo().getErrorInfo().getErrorMessage());
">[%s](%s)").formatted(breakingChange.getErrorInfo().getErrorInfo().getErrorMessage(), breakingChange.getErrorInfo().getErrorInfo().getErrorLogGithubLink());
}

@Override
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/se/kth/log_Analyzer/MavenErrorLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ public static class ErrorInfo {
String errorMessage;
String clientLineContent;
String clientGithubLink;
int errorLinePositionInFile;
String errorLogGithubLink;

public ErrorInfo(String clientLinePosition, String clientFilePath, String errorMessage) {
public ErrorInfo(String clientLinePosition, String clientFilePath, String errorMessage, int errorLinePositionInFile) {
this.clientLinePosition = clientLinePosition;
this.clientFilePath = clientFilePath;
this.errorMessage = errorMessage;
this.clientLineContent = "";
this.errorLinePositionInFile = errorLinePositionInFile;

}

public ErrorInfo(String clientLinePosition, String clientFilePath, String errorMessage, String clientLineContent) {
Expand All @@ -53,12 +57,13 @@ public ErrorInfo(String clientLinePosition, String clientFilePath, String errorM
this.clientLineContent = clientLineContent;
}

public ErrorInfo(String clientLinePosition, String clientFilePath, String errorMessage, String clientLineContent, String clientGithubLink) {
public ErrorInfo(String clientLinePosition, String clientFilePath, String errorMessage, String clientLineContent, String clientGithubLink, int errorLinePositionInFile) {
this.clientLinePosition = clientLinePosition;
this.clientFilePath = clientFilePath;
this.errorMessage = errorMessage;
this.clientLineContent = clientLineContent;
this.clientGithubLink = clientGithubLink;
this.errorLinePositionInFile = errorLinePositionInFile;
}

@Override
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/se/kth/log_Analyzer/MavenLogAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ private MavenErrorLog extractLineNumbersWithPaths(String logFilePath) throws IOE
Pattern errorPattern = Pattern.compile("\\[ERROR\\] .*:\\[(\\d+),\\d+\\]");
Pattern pathPattern = Pattern.compile("/[^:/]+(/[^\\[\\]:]+)");

int lineNumberInFile = 0;
while ((line = reader.readLine()) != null) {
lineNumberInFile++;
Map<Integer, String> lines = new HashMap<>();
Matcher matcher = errorPattern.matcher(line);
if (matcher.find()) {
Expand All @@ -51,10 +53,12 @@ private MavenErrorLog extractLineNumbersWithPaths(String logFilePath) throws IOE
lines.put(lineNumber, line);
if (pathMatcher.find()) {
currentPath = pathMatcher.group();

}
if (currentPath != null) {
mavenErrorLogs.addErrorInfo(currentPath, new MavenErrorLog.ErrorInfo(String.valueOf(lineNumber), currentPath, line));

MavenErrorLog.ErrorInfo errorInfo = new MavenErrorLog.ErrorInfo(String.valueOf(lineNumber), currentPath, line, lineNumberInFile);
errorInfo.setErrorLogGithubLink(generateLogsLink(projectURL, 4, lineNumberInFile));
mavenErrorLogs.addErrorInfo(currentPath, errorInfo);
}
}
}
Expand All @@ -64,4 +68,8 @@ private MavenErrorLog extractLineNumbersWithPaths(String logFilePath) throws IOE
}
return mavenErrorLogs;
}

private String generateLogsLink(String projectURL, int step, int lineNumber) {
return "https://github.com/chains-project/breaking-good/actions/runs/8110103454/job/22166641300#step:%d:%d".formatted(step, lineNumber);
}
}

0 comments on commit 50b9428

Please sign in to comment.