Skip to content

Commit

Permalink
better content for pull request comments (#81)
Browse files Browse the repository at this point in the history
Better content for pull request comments
  • Loading branch information
jkanczler authored Aug 23, 2018
1 parent 7ce84f4 commit 6924dd3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IMessage from "./IMessage";

export default (taskDisplayName: string, message: string): IMessage => {
export default (message: string): IMessage => {
if (message.indexOf("/tslint-loader/") === -1) {
return null;
}
Expand All @@ -10,7 +10,6 @@ export default (taskDisplayName: string, message: string): IMessage => {
const filePath = lines[0].slice(1);
const line = Number(lines[2].slice(1, lines[2].indexOf(",")));
const offset = Number(lines[2].slice(lines[2].indexOf(",") + 1, lines[2].indexOf("]")));
const messageWithTaskDisplayName = `${taskDisplayName}: ${message}`;

return {
filePath,
Expand All @@ -22,6 +21,6 @@ export default (taskDisplayName: string, message: string): IMessage => {
line,
offset
},
message: messageWithTaskDisplayName
message
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IMessage from "./IMessage";

export default (taskDisplayName: string, message: string): IMessage => {
export default (message: string): IMessage => {
const lines = message.split("\n");

if (!lines[2].startsWith("[tsl] ")) {
Expand All @@ -11,7 +11,6 @@ export default (taskDisplayName: string, message: string): IMessage => {
const sublines = lines[2].split("\r\n");
const line = Number(lines[2].slice(sublines[0].lastIndexOf("(") + 1, sublines[0].lastIndexOf(",")));
const offset = Number(lines[2].slice(sublines[0].lastIndexOf(",") + 1, sublines[0].lastIndexOf(")")));
const messageWithTaskDisplayName = `${taskDisplayName}: ${message}`;

return {
filePath,
Expand All @@ -23,6 +22,6 @@ export default (taskDisplayName: string, message: string): IMessage => {
line,
offset
},
message: messageWithTaskDisplayName
message
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ const threadEqualsToMessage = (thread: GitPullRequestCommentThread, message: IMe
&& thread.threadContext.rightFileStart.offset === message.start.offset
);

const parseMessages = (taskDisplayName: string, messagesToParse: string[]) => {
const parseMessages = (taskDisplayName: string, messagesToParse: string[], isError: boolean) => {
const parsedMessages: IMessage[] = [];

for (const item of messagesToParse) {
let parsedMessage = parseTsLoaderMessage(taskDisplayName, item);
let parsedMessage = parseTsLoaderMessage(item);

if (!parsedMessage) {
parsedMessage = parseTsLintLoaderMessage(taskDisplayName, item);
parsedMessage = parseTsLintLoaderMessage(item);
}

if (parsedMessage) {
parsedMessage.message = `${ isError ? "Error" : "Warning" } from task '${taskDisplayName}':\r\n${parsedMessage.message}"}`;

parsedMessages.push(parsedMessage);
}
}
Expand Down Expand Up @@ -108,7 +110,8 @@ const publishResultAsPullRequestComments = async (
return;
}

const parsedMessages = parseMessages(taskDisplayName, errorsAndWarningsArray);
let parsedMessages = parseMessages(taskDisplayName, errorsArray, true);
parsedMessages = [...parsedMessages, ...parseMessages(taskDisplayName, warningsArray, false)];

const gitApi = await getGitApi();
const threads = await getThreads(gitApi, project, repositoryId, pullRequestId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { assert } from "chai";

export default () => {
const unparsedTsLintLoaderMessage = "./src/index.ts\nModule Error (from ./node_modules/tslint-loader/index.js):\n[132, 281]: Missing semicolon\n";
const parsedMessage = parseTsLintLoaderMessage("task", unparsedTsLintLoaderMessage);
const parsedMessage = parseTsLintLoaderMessage(unparsedTsLintLoaderMessage);

assert.equal(parsedMessage.filePath, "/src/index.ts");
assert.equal(parsedMessage.message, `task: ${unparsedTsLintLoaderMessage}`);
assert.equal(parsedMessage.message, unparsedTsLintLoaderMessage);
assert.equal(parsedMessage.start.line, 132);
assert.equal(parsedMessage.start.offset, 281);
assert.equal(parsedMessage.end.line, 132);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { assert } from "chai";
export default () => {
// tslint:disable-next-line:max-line-length
const unparsedTsLoaderMessage = `C:\\W\\Playground\\webpack-format-messages\\src\\index.ts\n./src/index.ts\n[tsl] ERROR in C:\\W\\Playground\\webpack-format-messages\\src\\index.ts(456,918)\r\n TS2339: Property \'lo\' does not exist on type \'Console\'.`;
const parsedMessage = parseTsLoaderMessage("task", unparsedTsLoaderMessage);
const parsedMessage = parseTsLoaderMessage(unparsedTsLoaderMessage);

assert.equal(parsedMessage.filePath, "/src/index.ts");
assert.equal(parsedMessage.message, `task: ${unparsedTsLoaderMessage}`);
assert.equal(parsedMessage.message, unparsedTsLoaderMessage);
assert.equal(parsedMessage.start.line, 456);
assert.equal(parsedMessage.start.offset, 918);
assert.equal(parsedMessage.end.line, 456);
Expand Down

0 comments on commit 6924dd3

Please sign in to comment.