Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from teppeis/ajv@5
Browse files Browse the repository at this point in the history
update to ajv@5
  • Loading branch information
teppeis committed Apr 22, 2017
2 parents 9e15f97 + cc2e3c7 commit bb45c71
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 84 deletions.
37 changes: 29 additions & 8 deletions .circleci/config.yml
Expand Up @@ -3,19 +3,31 @@ jobs:
build:
docker:
- image: node:6
working_directory: ~/wd
working_directory: ~/working_directory
steps:
- checkout
- run:
name: Trigger Jobs
# Generate CircleCI API token with `all` privilege and set to $CIRCLE_API_TOKEN
command: |
function trigger_job() {
job_name=$1
curl --user ${CIRCLE_API_TOKEN}: \
echo "trigger_job $job_name"
http_code=$(curl --user ${CIRCLE_API_TOKEN}: \
--data build_parameters[CIRCLE_JOB]=$job_name \
--data revision=$CIRCLE_SHA1 \
https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/tree/$CIRCLE_BRANCH
}
-o curl.output \
-w '%{http_code}\n' \
-s \
https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/tree/$CIRCLE_BRANCH)
cat curl.output
echo ""
echo "http_code: $http_code"
if [[ ! "$http_code" =~ ^20[0-9]$ ]]; then
echo "Bad status code: $http_code" >&2
return 1
fi
}
trigger_job node-v4
trigger_job node-v6
trigger_job node-v7
Expand All @@ -25,7 +37,7 @@ jobs:
- image: node
environment:
TEST_REPORTS: /tmp/test-reports
working_directory: ~/wd
working_directory: ~/working_directory
steps:
- run:
name: Versions
Expand All @@ -35,23 +47,32 @@ jobs:
- checkout
- restore_cache:
keys:
- v1-yarn-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}
- v1-yarn-master-{{ .Environment.CIRCLE_JOB }}
- v{{ .Environment.CIRCLE_CACHE_VERSION }}-yarn-lock-{{ checksum "yarn.lock" }}-{{ .Environment.CIRCLE_JOB }}
- v{{ .Environment.CIRCLE_CACHE_VERSION }}-yarn-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}
- v{{ .Environment.CIRCLE_CACHE_VERSION }}-yarn-cache-master-{{ .Environment.CIRCLE_JOB }}
- run:
name: Install dependencies
command: yarn install
- run:
name: Test
command: |
mkdir -p $TEST_REPORTS
# Will be fixed in yarn v0.23
# https://github.com/yarnpkg/yarn/pull/2843
# yarn test
npm test
- save_cache:
key: v1-yarn-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-#{{ .BuildNum }}
key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-yarn-lock-{{ checksum "yarn.lock" }}-{{ .Environment.CIRCLE_JOB }}
paths:
- node_modules
- save_cache:
key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-yarn-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-#{{ .BuildNum }}
paths:
- ~/.cache/yarn
- store_test_results:
# Variables are not available in `path`
# https://discuss.circleci.com/t/can-i-use-variables-in-cache-paths/11393
# path: {{ .Environment.TEST_REPORTS }}
path: /tmp/test-reports

node-v4:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -6,6 +6,7 @@ Validate `manifest.json` of kintone plugin. Used in [kintone-plugin-packer](http
[![npm version][npm-image]][npm-url]
![Node.js Version Support][node-version]
[![build status][circleci-image]][circleci-url]
[![appveyor status][appveyor-image]][appveyor-url]
[![dependency status][deps-image]][deps-url]
![License][license]

Expand Down Expand Up @@ -51,7 +52,7 @@ MIT License: Teppei Sato <teppeis@gmail.com>
[travis-url]: https://travis-ci.org/teppeis/kintone-plugin-manifest-validator
[circleci-image]: https://circleci.com/gh/teppeis/kintone-plugin-manifest-validator.svg?style=svg
[circleci-url]: https://circleci.com/gh/teppeis/kintone-plugin-manifest-validator
[appveyor-image]: https://ci.appveyor.com/api/projects/status/KEY?svg=true
[appveyor-image]: https://ci.appveyor.com/api/projects/status/pcsvpsj4ff8u4jop/branch/master?svg=true
[appveyor-url]: https://ci.appveyor.com/project/teppeis/kintone-plugin-manifest-validator/branch/master
[deps-image]: https://img.shields.io/david/teppeis/kintone-plugin-manifest-validator.svg
[deps-url]: https://david-dm.org/teppeis/kintone-plugin-manifest-validator
Expand Down
29 changes: 29 additions & 0 deletions appveyor.yml
@@ -0,0 +1,29 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "6"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- yarn install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- yarn versions
- npm version
# run tests
- npm test

# Don't actually build.
build: off

# Cache
cache:
- node_modules -> yarn.lock
# - "%LOCALAPPDATA%\\Yarn"

# Just incremental build number
version: "{build}"
10 changes: 9 additions & 1 deletion index.js
@@ -1,6 +1,7 @@
'use strict';

const Ajv = require('ajv');
const v4metaSchema = require('ajv/lib/refs/json-schema-draft-04.json');
const bytes = require('bytes');
const jsonSchema = require('./manifest-schema.json');
const validateUrl = require('./src/validate-https-url');
Expand All @@ -25,12 +26,19 @@ module.exports = function(json, options) {
unknownFormats: true,
errorDataPath: 'property',
formats: {
url: str => validateUrl(str, true),
'https-url': str => validateUrl(str),
'relative-path': relativePath,
},
});

// Using draft-04 schemas
// https://github.com/epoberezkin/ajv/releases/tag/5.0.0
ajv.addMetaSchema(v4metaSchema);
ajv._opts.defaultMeta = v4metaSchema.id;
ajv.removeKeyword('propertyNames');
ajv.removeKeyword('contains');
ajv.removeKeyword('const');

ajv.addKeyword('maxFileSize', {
validate: function validateMaxFileSize(schema, data) {
// schema: max file size like "512KB" or 123 (in bytes)
Expand Down
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -14,9 +14,8 @@
"test": "run-s lint mocha"
},
"dependencies": {
"ajv": "^4.11.5",
"bytes": "^2.5.0",
"isomorphic-url": "1.0.0-alpha12"
"ajv": "^5.0.0",
"bytes": "^2.5.0"
},
"devDependencies": {
"eslint": "^3.19.0",
Expand Down
15 changes: 8 additions & 7 deletions src/validate-https-url.js
@@ -1,20 +1,21 @@
'use strict';

const URL = require('isomorphic-url').URL;
const formats = require('ajv/lib/compile/formats');

/**
* @param {string} str
* @param {boolean=} opt_allowHttp
* @return {boolean}
*/
function validateHttpsUrl(str, opt_allowHttp) {
const allowHttp = !!opt_allowHttp;
try {
const url = new URL(str);
return url.protocol === 'https:' || (allowHttp && url.protocol === 'http:');
} catch (e) {
return false;
if (formats.full.url.test(str)) {
if (opt_allowHttp) {
return /^https?:/.test(str);
} else {
return /^https:/.test(str);
}
}
return false;
}

module.exports = validateHttpsUrl;
2 changes: 1 addition & 1 deletion test/index.js
Expand Up @@ -53,7 +53,7 @@ describe('validator', () => {
message: 'should be >= 1',
params: {
comparison: '>=',
exclusive: false,
exclusive: undefined,
limit: 1,
},
schemaPath: '#/properties/version/minimum',
Expand Down

0 comments on commit bb45c71

Please sign in to comment.