Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions scripts/momentOfTruthPostProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) => `### <a name="${issue_type.replace(/\s/g, "-")}s"></a>${iconFor(issue_type)} ${issue_count} new ${pluralize(issue_type, issue_count)}\n\n${issue_table}\n`;
let fileSummaryNewTemplate = (issue_type, issue_count, issue_table) => `<details><summary><h3 style="display: inline"><a name="${issue_type.replace(/\s/g, "-")}s"></a>${iconFor(issue_type)} ${issue_count} new ${pluralize(issue_type, issue_count)}</h3></summary><br>\n\n${issue_table}\n</details>`;
let fileSummaryExistingTemplate = (issue_type, issue_count, issue_table) => `<details><summary>${iconFor(issue_type)} ${issue_count} existing ${pluralize(issue_type, issue_count)}</summary><br>\n\n${issue_table}\n</details>\n\n`;

let potentialNewWarningErrorSummaryHeader = `
Expand Down Expand Up @@ -65,7 +66,10 @@ try {
}

function compareJsonRef(beforeJsonRef, afterJsonRef) {
return (beforeJsonRef.replace(/json:\d+:\d+/, '') == afterJsonRef.replace(/json:\d+:\d+/, ''));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the intent behind this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to the issue specified by Joel.

beforeJsonRef = beforeJsonRef.replace(/.*\.json:\d+:\d+/, '')
afterJsonRef = afterJsonRef.replace(/.*\.json:\d+:\d+/, '')

return (beforeJsonRef == afterJsonRef);
}

function getOutputMessages(newSDKErrorsCount, newARMErrorsCount, newSDKWarningsCount, newARMWarningsCount) {
Expand Down Expand Up @@ -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("========================");
Expand Down Expand Up @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions scripts/postToGitHub.js
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we concerned that every time a commit is pushed, a new build will run and this will create a new comment? If so, maybe we can put an identifier in the comment and then either create a new comment or update the existing one if found. SwaggerToSdk is already doing this (it matches on the header text) but you should also be able to do it by inserting an HTML comment like <!-- momentoftruth --> which will be invisible to the user but will make it easy to locate the comment to update.

octokit.issues.createComment({
"owner": owner,
"repo": repository,
"number": prNumber,
"body": commentBody
}).then(data => {
console.log("Comment has been posted");
}). catch(err => {
console.log(err);
});
}
}