Skip to content

Commit

Permalink
Merge branch 'master' into rienafairefr-templating
Browse files Browse the repository at this point in the history
* master: (758 commits)
  Add support for free form requests (OpenAPITools#2288)
  [typescript-rxjs] drop unneeded function wrapping  (OpenAPITools#2332)
  [typescript-fetch] Guard array mapping against undefined on optional array model properties (OpenAPITools#2324)
  Fix regex in Python server model code (OpenAPITools#2314)
  Add .travis.yml and Gemfile.lock to ruby security test folder (OpenAPITools#2330)
  Add a link to CSDN article (OpenAPITools#2331)
  [Maven] fix Spaces in Windows user path breaks build on test goal (OpenAPITools#2318)
  [PHP] fix bad links in Model docs (OpenAPITools#2316)
  [java]: fix datatype for non-multipart file request body (OpenAPITools#2271)
  Removed JFCote from core team (OpenAPITools#2315)
  [R sample] fix CircleCI error of outdated sample (OpenAPITools#2313)
  [Java] Bean Validation for decimalmin/max incorrect when exclusive set (OpenAPITools#2115)
  Java Spring : fix defaultValue annotation double quoted in api operation (OpenAPITools#2267)
  Java RESTEASY : fix defaultValue annotation double quoted in api operation (OpenAPITools#2268)
  [PHP] Username checks OpenAPITools#1408 (OpenAPITools#1892)
  [typescript-fetch] remove namespaces in enums (OpenAPITools#2123)
  [java-server-msf4j] fix and upgrade (OpenAPITools#2303)
  fix test script path in CONTRIBUTING.md (OpenAPITools#2290)
  Dart queryargs (OpenAPITools#2250)
  add Blueplanet language (OpenAPITools#2184)
  ...
  • Loading branch information
jimschubert committed Mar 9, 2019
2 parents 0ee5694 + 3739584 commit a55eee6
Show file tree
Hide file tree
Showing 10,685 changed files with 599,603 additions and 116,720 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.mustache linguist-vendored=true
117 changes: 117 additions & 0 deletions .github/.test/auto-labeler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
let fs = require('fs');
let path = require('path');
let util = require('util');
let yaml = require('./js-yaml.js');
let samples = require('./samples.json');

class LabelMatch {
constructor (match, label) {
this.match = match;
this.label = label;
}
}

class FileError {
constructor (file, actualLabels, expectedLabels) {
this.file = file;
this.actual = actualLabels;
this.expected = expectedLabels;
}
}

class TextError {
constructor (text, actualLabels, expectedLabels) {
this.text = text;
this.actual = actualLabels;
this.expected = expectedLabels;
}
}

let labels = [];

function labelsForFile(file) {
let body = fs.readFileSync(file);
return labelsForText(body)
}

function labelsForText(text) {
let addLabels = new Set();
let body = text;
for (const v of labels) {
if (v.match.test(body)) {
addLabels.add(v.label)
}
// reset regex state
v.match.lastIndex = 0
}
return addLabels;
}

try {
let config = yaml.safeLoad(fs.readFileSync('../auto-labeler.yml', 'utf8'));

if (config && config.labels && Object.keys(config.labels).length > 0) {
for (const labelName in config.labels) {
if (config.labels.hasOwnProperty(labelName)) {
let matchAgainst = config.labels[labelName];
if (Array.isArray(matchAgainst)) {
matchAgainst.forEach(regex => {
// noinspection JSCheckFunctionSignatures
labels.push(new LabelMatch(new RegExp(regex, 'g'), labelName));
})
}
}
}
}

if (labels.length === 0) {
// noinspection ExceptionCaughtLocallyJS
throw new Error("Expected to parse config.labels, but failed.")
}

let fileErrors = [];
samples.files.forEach(function(tester){
let file = path.normalize(path.join('..', '..', 'bin', tester.input));
let expectedLabels = new Set(tester.matches);
let actualLabels = labelsForFile(file);
let difference = new Set([...actualLabels].filter(x => !expectedLabels.has(x)));
if (difference.size > 0) {
fileErrors.push(new FileError(file, actualLabels, expectedLabels));
}
});

let textErrors = [];
samples.text.forEach(function(tester){
let expectedLabels = new Set(tester.matches);
let actualLabels = labelsForText(tester.input);
let difference = new Set([...actualLabels].filter(x => !expectedLabels.has(x)));
if (difference.size > 0) {
textErrors.push(new TextError(tester.input, actualLabels, expectedLabels));
}
});

// These are separate (file vs text) in case we want to preview where these would fail in the file. not priority at the moment.
if (fileErrors.length > 0) {
console.warn('There were %d file tester errors', fileErrors.length);
fileErrors.forEach(function(errs) {
console.log("file: %j\n actual: %j\n expected: %j", errs.file, util.inspect(errs.actual), util.inspect(errs.expected))
});
}

if (textErrors.length > 0) {
console.warn('There were %d text tester errors', textErrors.length);
textErrors.forEach(function(errs){
console.log("input: %j\n actual: %j\n expected: %j", errs.text, util.inspect(errs.actual), util.inspect(errs.expected))
})
}

let totalErrors = fileErrors.length + textErrors.length;
if (totalErrors === 0) {
console.log('Success!');
} else {
console.log('Failure: %d total errors', totalErrors);
}
} catch (e) {
console.log(e);
}

Loading

0 comments on commit a55eee6

Please sign in to comment.