Skip to content

Commit

Permalink
Feature/better error handling for pull request commenting (#79)
Browse files Browse the repository at this point in the history
Better documentation.
Better error handling for pull request commenting.
Getting of the last iteration id of the pull request is fixed.
  • Loading branch information
jkanczler authored Aug 23, 2018
1 parent 951cea8 commit 333aa7a
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 26 deletions.
17 changes: 10 additions & 7 deletions DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ Errors and Warnings can be treated differently:

Warnings means the task will partially succeed, in case of errors the task will fail. If there are no errors and no warnings, then the task will succeed. You can treat the errors as warnings, so in case of errors, the task will just partially succeed. Or if you would like to ignore the warnings, those should be handled as info.

Errors and Warnings can be reported as pull request comments. Currently only two loaders are supported:
* ts-loader
* tslint-loader

Even general webpack errors and warnings are not supported yet. More support will come!

Don't forget to turn on the following agent phase setting:
![Prerequisite for pull request commenting](https://raw.githubusercontent.com/Dealogic/webpack-vsts-extension/master/screenshots/PullRequestCommentingPrerequisite.png)

![webpack arguments](https://raw.githubusercontent.com/Dealogic/webpack-vsts-extension/master/screenshots/WebpackArguments.png)

The webpack build errors and warnings are reported under the issues / build section on the summary page:
Expand All @@ -62,12 +71,6 @@ The webpack build result section is added onto the summary page to summarize the

![webpack build result](https://raw.githubusercontent.com/Dealogic/webpack-vsts-extension/master/screenshots/WebpackBuildResult.png)

Errors and Warnings can be reported as pull request comments. Currently only two loaders are supported:
* ts-loader
* tslint-loader

Even general webpack errors and warnings are not supported yet. More support will come!

### <a id="advanced-settings"></a>Advanced Settings

- Working folder where webpack command is run. If you leave it blank it is the root of the repo.
Expand Down Expand Up @@ -109,7 +112,7 @@ stats.js Location | true | ./node_modules/webpack/lib/Stats.js | Location of the

## <a id="release-notes"></a>Release Notes

* 4.1.0 (22/08/2018)
* 4.1.1 (23/08/2018)
* Errors and warnings can be reported as pull request comments (ts-loader and tslint-loader are supported, more will come).
* 4.0.4 (24/05/2018)
* Dependencies are updated to fix security vulnerabilities (though it was just in one of the samples).
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
next-version: 4.1.0
next-version: 4.1.1
assembly-informational-format: '{SemVer}'
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ Errors and Warnings can be treated differently:

Warnings means the task will partially succeed, in case of errors the task will fail. If there are no errors and no warnings, then the task will succeed. You can treat the errors as warnings, so in case of errors, the task will just partially succeed. Or if you would like to ignore the warnings, those should be handled as info.

Errors and Warnings can be reported as pull request comments. Currently only two loaders are supported:
* ts-loader
* tslint-loader

Even general webpack errors and warnings are not supported yet. More support will come!

Don't forget to turn on the following agent phase setting:
![Prerequisite for pull request commenting](https://raw.githubusercontent.com/Dealogic/webpack-vsts-extension/master/screenshots/PullRequestCommentingPrerequisite.png)

![webpack arguments](https://raw.githubusercontent.com/Dealogic/webpack-vsts-extension/master/screenshots/WebpackArguments.png)

The webpack build errors and warnings are reported under the issues / build section on the summary page:
Expand All @@ -62,12 +71,6 @@ The webpack build result section is added onto the summary page to summarize the

![webpack build result](https://raw.githubusercontent.com/Dealogic/webpack-vsts-extension/master/screenshots/WebpackBuildResult.png)

Errors and Warnings can be reported as pull request comments. Currently only two loaders are supported:
* ts-loader
* tslint-loader

Even general webpack errors and warnings are not supported yet. More support will come!

### <a id="advanced-settings"></a>Advanced Settings

- Working folder where webpack command is run. If you leave it blank it is the root of the repo.
Expand Down Expand Up @@ -109,7 +112,7 @@ stats.js Location | true | ./node_modules/webpack/lib/Stats.js | Location of the

## <a id="release-notes"></a>Release Notes

* 4.1.0 (22/08/2018)
* 4.1.1 (23/08/2018)
* Errors and warnings can be reported as pull request comments (ts-loader and tslint-loader are supported, more will come).
* 4.0.4 (24/05/2018)
* Dependencies are updated to fix security vulnerabilities (though it was just in one of the samples).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wepback-vsts-extension",
"version": "4.1.0",
"version": "4.1.1",
"description": "webpack Visual Studio Team System (VSTS) Extension",
"main": "index.js",
"scripts": {
Expand Down
Binary file added screenshots/PullRequestCommentingPrerequisite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/WebpackArguments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tasks/webpack-build-task/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-build-task",
"version": "4.1.0",
"version": "4.1.1",
"description": "Webpack build task for Visual Studio Team System (VSTS)",
"main": "index.js",
"scripts": {},
Expand Down
2 changes: 1 addition & 1 deletion tasks/webpack-build-task/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 4,
"Minor": 1,
"Patch": 0
"Patch": 1
},
"minimumAgentVersion": "1.95.0",
"groups": [
Expand Down
7 changes: 6 additions & 1 deletion tasks/webpack-build-task/taskResultPublisher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ const publishTaskResult = async (
}
}

await publishResultAsPullRequestComments(enablePullRequestComments, taskDisplayName, errorsArray, warningsArray);
try {
await publishResultAsPullRequestComments(enablePullRequestComments, taskDisplayName, errorsArray, warningsArray);
} catch (error) {
console.log("Couldn't publish result as pull request comments. The reason is:");
console.log(error);
}

const taskFailed = (hasErrors && treatErrorsAs === errors) || (hasWarnings && treatWarningsAs === errors);
const taskPartiallySucceeded = !taskFailed && ((hasErrors && treatErrorsAs === warnings) || (hasWarnings && treatWarningsAs === warnings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,31 @@ const parseMessages = (taskDisplayName: string, messagesToParse: string[]) => {
};

const getGitApi = async () => {
const accessToken = tl.getVariable("System.AccessToken");
const collectionUri = tl.getVariable("System.TeamFoundationCollectionUri");
try {
const accessToken = tl.getVariable("System.AccessToken");

const authHandler = vstsApi.getBearerHandler(accessToken);
const connection = new vstsApi.WebApi(collectionUri, authHandler);
if (!accessToken) {
console.log("Please allow scripts to access OAuth token in the additional optionts of the agent phase.");

return await connection.getGitApi();
return null;
}

const collectionUri = tl.getVariable("System.TeamFoundationCollectionUri");

const authHandler = vstsApi.getBearerHandler(accessToken);
const connection = new vstsApi.WebApi(collectionUri, authHandler);

return await connection.getGitApi();
} catch (err) {
console.log("Could not connect to VSTS API.");

throw err;
}
};

const getThreads = async (gitApi: GitApi, project: string, repositoryId: string, pullRequestId: number) => {
const pullRequestIterations = await gitApi.getPullRequestIterations(repositoryId, pullRequestId, project);
const lastIterationId = pullRequestIterations[pullRequestIterations.length].id;
const lastIterationId = pullRequestIterations[pullRequestIterations.length - 1].id;

return await gitApi.getThreads(repositoryId, pullRequestId, project, lastIterationId, lastIterationId);
};
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "webpack-vsts-extension",
"version": "4.1.0",
"version": "4.1.1",
"name": "webpack",
"description": "bundle your assets, scripts, images, styles",
"publisher": "Dealogic",
Expand Down

0 comments on commit 333aa7a

Please sign in to comment.