Comparing version 7.0.1 to 7.1.0
# CHANGELOG | ||
## 7.1.0 | ||
Bug fixes: | ||
* Provide correct values for moveProjectsCard "position" parameter. | ||
Features: | ||
* Add a TypeScript generator. | ||
* Update protected branches api changes. | ||
## 7.0.1 | ||
@@ -4,0 +13,0 @@ |
@@ -207,4 +207,5 @@ #!/usr/bin/env node | ||
require('./generateFlowTypes.js'); | ||
require('./generateTypeScriptTypes.js'); | ||
}; | ||
main(); |
#!/usr/bin/env node | ||
/** section: github, internal | ||
* class ApiGenerator | ||
* | ||
* Copyright 2012 Cloud9 IDE, Inc. | ||
* | ||
* This product includes software developed by | ||
* Cloud9 IDE, Inc (http://c9.io). | ||
* | ||
* Author: Mike de Boer <mike@c9.io> | ||
**/ | ||
"use strict"; | ||
var fs = require("fs"); | ||
var Path = require("path"); | ||
var Util = require("./util"); | ||
var Mustache = require("mustache"); | ||
var templatePath = Path.join(__dirname, "..", "templates", "index.js.flow.tpl"); | ||
var template = fs.readFileSync(templatePath, "utf8"); | ||
var typeMap = { | ||
Json: "string", | ||
String: "string", | ||
Number: "number", | ||
Boolean: "boolean", | ||
}; | ||
// XXX: maybe a better idea to update routes.json to include array value types. | ||
function replaceArrayTypes(type, name) { | ||
switch (name) { | ||
case "scopes": | ||
case "add_scopes": | ||
case "remove_scopes": | ||
case "parents": | ||
case "assignees": | ||
case "body": | ||
case "repositories": | ||
case "repo_names": | ||
case "events": | ||
case "add_events": | ||
case "remove_events": | ||
case "contexts": | ||
case "required_contexts": | ||
return "string[]"; | ||
default: | ||
return type; | ||
} | ||
} | ||
function paramData(key, definition) { | ||
if (definition === null) { | ||
return {}; | ||
} | ||
var typeName = typeMap[definition.type] || definition.type; | ||
var type = replaceArrayTypes(typeName, key); | ||
var enums = definition.enum ? | ||
definition.enum.map(JSON.stringify).join("|") | ||
: null; | ||
return { | ||
name: pascalcase(key), | ||
key: key, | ||
required: definition.required, | ||
type: enums ? enums : type, | ||
}; | ||
} | ||
function capitalize(string) { | ||
return string.charAt(0).toUpperCase().concat(string.slice(1)); | ||
} | ||
function camelcase(string) { | ||
return string.replace(/(?:-|_)([a-z])/g, function (_, character) { | ||
return capitalize(character); | ||
}); | ||
} | ||
function pascalcase(string) { | ||
return capitalize(camelcase(string)); | ||
} | ||
function isGlobalParam(name) { | ||
return name.charAt(0) === "$"; | ||
} | ||
function isLocalParam(name) { | ||
return !isGlobalParam(name); | ||
} | ||
function entries(object) { | ||
return Object.keys(object).map(function (key) { | ||
return [key, object[key]]; | ||
}); | ||
} | ||
function combineParamData(params, entry) { | ||
return params.concat(paramData.apply(null, entry)); | ||
} | ||
var main = module.exports = function() { | ||
// check routes path | ||
var routesPath = Path.join(__dirname, "routes.json"); | ||
var routes = JSON.parse(fs.readFileSync(routesPath, "utf8")); | ||
if (!routes.defines) { | ||
Util.log("No routes defined.", "fatal"); | ||
process.exit(1); | ||
} | ||
var defines = routes.defines; | ||
var requestHeaders = defines["request-headers"]; | ||
delete routes.defines; | ||
Util.log("Generating flow types..."); | ||
var params = entries(defines.params).reduce(combineParamData, []); | ||
var namespaces = Object.keys(routes).reduce(function (namespaces, namespace) { | ||
var methods = entries(routes[namespace]).reduce(function (methods, entry) { | ||
var unionTypeNames = Object.keys(entry[1].params) | ||
.filter(isGlobalParam) | ||
.reduce(function (params, name) { | ||
return params.concat(pascalcase(name.slice(1))); | ||
}, []); | ||
var ownParams = entries(entry[1].params) | ||
.filter(function (entry) { return isLocalParam(entry[0]); }) | ||
.reduce(combineParamData, []); | ||
var hasParams = unionTypeNames.length > 0 || ownParams.length > 0; | ||
var paramTypeName = pascalcase(namespace + "-" + entry[0] + "Params"); | ||
return methods.concat({ | ||
method: camelcase(entry[0]), | ||
paramTypeName: hasParams && paramTypeName, | ||
unionTypeNames: unionTypeNames.length > 0 && unionTypeNames, | ||
ownParams: ownParams.length > 0 && { params: ownParams }, | ||
}); | ||
}, []); | ||
return namespaces.concat({ | ||
namespace: camelcase(namespace), | ||
methods: methods, | ||
}); | ||
}, []); | ||
var body = Mustache.render(template, { | ||
requestHeaders: requestHeaders.map(JSON.stringify), | ||
params: params, | ||
namespaces: namespaces, | ||
}); | ||
Util.log("Writing flow definitions file"); | ||
fs.writeFileSync(Path.join(__dirname, "index.js.flow"), body, "utf8"); | ||
}; | ||
main(); | ||
module.exports = require("./generateTypes")("Flow", "index.js.flow.tpl", "index.js.flow"); |
{ | ||
"name": "github", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"description": "NodeJS wrapper for the GitHub API", | ||
@@ -39,2 +39,3 @@ "author": "Mike de Boer <info@mikedeboer.nl>", | ||
"main": "lib", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
@@ -53,3 +54,3 @@ "test": "mocha" | ||
"name": "node-github", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"template": { | ||
@@ -56,0 +57,0 @@ "withCompare": true |
@@ -1177,2 +1177,19 @@ /* | ||
it("should successfully execute GET /repos/:owner/:repo/branches/:branch/protection/required_pull_request_reviews (getProtectedBranchPullRequestReviewEnforcement)", function(next) { | ||
client.repos.getProtectedBranchPullRequestReviewEnforcement( | ||
{ | ||
owner: "String", | ||
repo: "String", | ||
branch: "String", | ||
page: "Number", | ||
per_page: "Number" | ||
}, | ||
function(err, res) { | ||
Assert.equal(err, null); | ||
// other assertions go here | ||
next(); | ||
} | ||
); | ||
}); | ||
it("should successfully execute GET /repos/:owner/:repo/branches/:branch/protection/required_status_checks (getProtectedBranchRequiredStatusChecks)", function(next) { | ||
@@ -1567,2 +1584,17 @@ client.repos.getProtectedBranchRequiredStatusChecks( | ||
it("should successfully execute DELETE /repos/:owner/:repo/branches/:branch/protection/required_pull_request_reviews (removeProtectedBranchPullRequestReviewEnforcement)", function(next) { | ||
client.repos.removeProtectedBranchPullRequestReviewEnforcement( | ||
{ | ||
owner: "String", | ||
repo: "String", | ||
branch: "String" | ||
}, | ||
function(err, res) { | ||
Assert.equal(err, null); | ||
// other assertions go here | ||
next(); | ||
} | ||
); | ||
}); | ||
it("should successfully execute DELETE /repos/:owner/:repo/branches/:branch/protection/required_status_checks (removeProtectedBranchRequiredStatusChecks)", function(next) { | ||
@@ -1747,2 +1779,3 @@ client.repos.removeProtectedBranchRequiredStatusChecks( | ||
required_status_checks: "Json", | ||
required_pull_request_reviews: "Json", | ||
restrictions: "Json", | ||
@@ -1811,2 +1844,18 @@ page: "Number", | ||
it("should successfully execute PATCH /repos/:owner/:repo/branches/:branch/protection/required_pull_request_reviews (updateProtectedBranchPullRequestReviewEnforcement)", function(next) { | ||
client.repos.updateProtectedBranchPullRequestReviewEnforcement( | ||
{ | ||
owner: "String", | ||
repo: "String", | ||
branch: "String", | ||
include_admins: "Boolean" | ||
}, | ||
function(err, res) { | ||
Assert.equal(err, null); | ||
// other assertions go here | ||
next(); | ||
} | ||
); | ||
}); | ||
it("should successfully execute PATCH /repos/:owner/:repo/branches/:branch/protection/required_status_checks (updateProtectedBranchRequiredStatusChecks)", function(next) { | ||
@@ -1813,0 +1862,0 @@ client.repos.updateProtectedBranchRequiredStatusChecks( |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77
1659905
44697