diff --git a/scripts/momentOfTruthPostProcessing.js b/scripts/momentOfTruthPostProcessing.js index a747daa2dc0e..29f6c7e0638b 100644 --- a/scripts/momentOfTruthPostProcessing.js +++ b/scripts/momentOfTruthPostProcessing.js @@ -5,7 +5,8 @@ const fs = require('fs'), utils = require('../test/util/utils'), - path = require('path'); + path = require('path'), + gitHubPost = require('./postToGitHub'); let pullRequestNumber = utils.getPullRequestNumber(); let targetBranch = utils.getTargetBranch(); @@ -31,7 +32,7 @@ let githubFooter = `[AutoRest Linter Guidelines](https://github.com/Azure/azure- `\n\nThanks for your co-operation.`; let fileSummaryHeader = (file_name, file_href) => `## Config file: [${file_name}](${file_href})\n`; -let fileSummaryNewTemplate = (issue_type, issue_count, issue_table) => `### ${iconFor(issue_type)} ${issue_count} new ${pluralize(issue_type, issue_count)}\n\n${issue_table}\n`; +let fileSummaryNewTemplate = (issue_type, issue_count, issue_table) => `

${iconFor(issue_type)} ${issue_count} new ${pluralize(issue_type, issue_count)}


\n\n${issue_table}\n
`; let fileSummaryExistingTemplate = (issue_type, issue_count, issue_table) => `
${iconFor(issue_type)} ${issue_count} existing ${pluralize(issue_type, issue_count)}
\n\n${issue_table}\n
\n\n`; let potentialNewWarningErrorSummaryHeader = ` @@ -65,7 +66,10 @@ try { } function compareJsonRef(beforeJsonRef, afterJsonRef) { - return (beforeJsonRef.replace(/json:\d+:\d+/, '') == afterJsonRef.replace(/json:\d+:\d+/, '')); + beforeJsonRef = beforeJsonRef.replace(/.*\.json:\d+:\d+/, '') + afterJsonRef = afterJsonRef.replace(/.*\.json:\d+:\d+/, '') + + return (beforeJsonRef == afterJsonRef); } function getOutputMessages(newSDKErrorsCount, newARMErrorsCount, newSDKWarningsCount, newARMWarningsCount) { @@ -356,6 +360,7 @@ function postProcessing() { console.log("Existing ARM Errors: ", existingARMErrors.length); console.log("Existing ARM Warnings: ", existingARMWarnings.length); console.log(); + if (newSDKErrors.length > 0) { console.log(`Potential new SDK errors`) console.log("========================"); @@ -403,6 +408,12 @@ function postProcessing() { console.log(JSON.stringify(output, null, 2)); console.log("---"); + if(process.env.TRAVIS_REPO_SLUG != undefined && process.env.TRAVIS_REPO_SLUG.endsWith("-pr")) { + let slug = process.env.TRAVIS_REPO_SLUG; + slug = slug.split("/")[1]; + gitHubPost.postGithubComment("Azure", slug, pullRequestNumber, output.text); + } + if (newSDKErrorsCount > 0 || newARMErrorsCount > 0) { process.exitCode = 1; } diff --git a/scripts/postToGitHub.js b/scripts/postToGitHub.js new file mode 100644 index 000000000000..f162b6ad8b8a --- /dev/null +++ b/scripts/postToGitHub.js @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +'use strict'; + +const octokit = require('@octokit/rest')(); +let token = process.env.GITHUB_TOKEN; + +if(token != undefined) { + octokit.authenticate({ + type: 'token', + token: token + }); +} + +module.exports = { + postGithubComment: function(owner, repository, prNumber, commentBody) { + octokit.issues.createComment({ + "owner": owner, + "repo": repository, + "number": prNumber, + "body": commentBody + }).then(data => { + console.log("Comment has been posted"); + }). catch(err => { + console.log(err); + }); + } +} \ No newline at end of file