@actions/github
Advanced tools
Comparing version 2.2.0 to 3.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Context = void 0; | ||
const fs_1 = require("fs"); | ||
@@ -4,0 +5,0 @@ const os_1 = require("os"); |
@@ -1,27 +0,11 @@ | ||
import { graphql as GraphQL } from '@octokit/graphql/dist-types/types'; | ||
import { Octokit } from '@octokit/rest'; | ||
import * as Context from './context'; | ||
import { GitHub } from './utils'; | ||
import { OctokitOptions } from '@octokit/core/dist-types/types'; | ||
export declare const context: Context.Context; | ||
export declare class GitHub extends Octokit { | ||
graphql: GraphQL; | ||
/** | ||
* Sets up the REST client and GraphQL client with auth and proxy support. | ||
* The parameter `token` or `opts.auth` must be supplied. The GraphQL client | ||
* authorization is not setup when `opts.auth` is a function or object. | ||
* | ||
* @param token Auth token | ||
* @param opts Octokit options | ||
*/ | ||
constructor(token: string, opts?: Omit<Octokit.Options, 'auth'>); | ||
constructor(opts: Octokit.Options); | ||
/** | ||
* Disambiguates the constructor overload parameters | ||
*/ | ||
private static disambiguate; | ||
private static getOctokitOptions; | ||
private static getGraphQL; | ||
private static getAuthString; | ||
private static getProxyAgent; | ||
private static getApiBaseUrl; | ||
private static getGraphQLBaseUrl; | ||
} | ||
/** | ||
* Returns a hydrated octokit ready to use for GitHub Actions | ||
* | ||
* @param token the repo PAT or GITHUB_TOKEN | ||
* @param options other options to set | ||
*/ | ||
export declare function getOctokit(token: string, options?: OctokitOptions): InstanceType<typeof GitHub>; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/github.ts | ||
const graphql_1 = require("@octokit/graphql"); | ||
const rest_1 = require("@octokit/rest"); | ||
exports.getOctokit = exports.context = void 0; | ||
const Context = __importStar(require("./context")); | ||
const httpClient = __importStar(require("@actions/http-client")); | ||
// We need this in order to extend Octokit | ||
rest_1.Octokit.prototype = new rest_1.Octokit(); | ||
const utils_1 = require("./utils"); | ||
exports.context = new Context.Context(); | ||
class GitHub extends rest_1.Octokit { | ||
constructor(token, opts) { | ||
super(GitHub.getOctokitOptions(GitHub.disambiguate(token, opts))); | ||
this.graphql = GitHub.getGraphQL(GitHub.disambiguate(token, opts)); | ||
} | ||
/** | ||
* Disambiguates the constructor overload parameters | ||
*/ | ||
static disambiguate(token, opts) { | ||
return [ | ||
typeof token === 'string' ? token : '', | ||
typeof token === 'object' ? token : opts || {} | ||
]; | ||
} | ||
static getOctokitOptions(args) { | ||
const token = args[0]; | ||
const options = Object.assign({}, args[1]); // Shallow clone - don't mutate the object provided by the caller | ||
// Base URL - GHES or Dotcom | ||
options.baseUrl = options.baseUrl || this.getApiBaseUrl(); | ||
// Auth | ||
const auth = GitHub.getAuthString(token, options); | ||
if (auth) { | ||
options.auth = auth; | ||
} | ||
// Proxy | ||
const agent = GitHub.getProxyAgent(options.baseUrl, options); | ||
if (agent) { | ||
// Shallow clone - don't mutate the object provided by the caller | ||
options.request = options.request ? Object.assign({}, options.request) : {}; | ||
// Set the agent | ||
options.request.agent = agent; | ||
} | ||
return options; | ||
} | ||
static getGraphQL(args) { | ||
const defaults = {}; | ||
defaults.baseUrl = this.getGraphQLBaseUrl(); | ||
const token = args[0]; | ||
const options = args[1]; | ||
// Authorization | ||
const auth = this.getAuthString(token, options); | ||
if (auth) { | ||
defaults.headers = { | ||
authorization: auth | ||
}; | ||
} | ||
// Proxy | ||
const agent = GitHub.getProxyAgent(defaults.baseUrl, options); | ||
if (agent) { | ||
defaults.request = { agent }; | ||
} | ||
return graphql_1.graphql.defaults(defaults); | ||
} | ||
static getAuthString(token, options) { | ||
// Validate args | ||
if (!token && !options.auth) { | ||
throw new Error('Parameter token or opts.auth is required'); | ||
} | ||
else if (token && options.auth) { | ||
throw new Error('Parameters token and opts.auth may not both be specified'); | ||
} | ||
return typeof options.auth === 'string' ? options.auth : `token ${token}`; | ||
} | ||
static getProxyAgent(destinationUrl, options) { | ||
var _a; | ||
if (!((_a = options.request) === null || _a === void 0 ? void 0 : _a.agent)) { | ||
if (httpClient.getProxyUrl(destinationUrl)) { | ||
const hc = new httpClient.HttpClient(); | ||
return hc.getAgent(destinationUrl); | ||
} | ||
} | ||
return undefined; | ||
} | ||
static getApiBaseUrl() { | ||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'; | ||
} | ||
static getGraphQLBaseUrl() { | ||
let url = process.env['GITHUB_GRAPHQL_URL'] || 'https://api.github.com/graphql'; | ||
// Shouldn't be a trailing slash, but remove if so | ||
if (url.endsWith('/')) { | ||
url = url.substr(0, url.length - 1); | ||
} | ||
// Remove trailing "/graphql" | ||
if (url.toUpperCase().endsWith('/GRAPHQL')) { | ||
url = url.substr(0, url.length - '/graphql'.length); | ||
} | ||
return url; | ||
} | ||
/** | ||
* Returns a hydrated octokit ready to use for GitHub Actions | ||
* | ||
* @param token the repo PAT or GITHUB_TOKEN | ||
* @param options other options to set | ||
*/ | ||
function getOctokit(token, options) { | ||
return new utils_1.GitHub(utils_1.getOctokitOptions(token, options)); | ||
} | ||
exports.GitHub = GitHub; | ||
exports.getOctokit = getOctokit; | ||
//# sourceMappingURL=github.js.map |
@@ -36,2 +36,6 @@ export interface PayloadRepository { | ||
}; | ||
comment?: { | ||
id: number; | ||
[key: string]: any; | ||
}; | ||
} |
{ | ||
"name": "@actions/github", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Actions github lib", | ||
@@ -41,4 +41,5 @@ "keywords": [ | ||
"@actions/http-client": "^1.0.3", | ||
"@octokit/graphql": "^4.3.1", | ||
"@octokit/rest": "^16.43.1" | ||
"@octokit/core": "^2.5.1", | ||
"@octokit/plugin-paginate-rest": "^2.2.0", | ||
"@octokit/plugin-rest-endpoint-methods": "^3.10.0" | ||
}, | ||
@@ -45,0 +46,0 @@ "devDependencies": { |
@@ -7,3 +7,3 @@ # `@actions/github` | ||
Returns an authenticated Octokit client that follows the machine [proxy settings](https://help.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners). See https://octokit.github.io/rest.js for the API. | ||
Returns an authenticated Octokit client that follows the machine [proxy settings](https://help.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners) and correctly sets GHES base urls. See https://octokit.github.io/rest.js for the API. | ||
@@ -21,4 +21,7 @@ ```js | ||
const octokit = new github.GitHub(myToken); | ||
const octokit = github.getOctokit(myToken) | ||
// You can also pass in additional options as a second parameter to getOctokit | ||
// const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"}); | ||
const { data: pullRequest } = await octokit.pulls.get({ | ||
@@ -39,4 +42,2 @@ owner: 'octokit', | ||
You can pass client options, as specified by [Octokit](https://octokit.github.io/rest.js/), as a second argument to the `GitHub` constructor. | ||
You can also make GraphQL requests. See https://github.com/octokit/graphql.js for the API. | ||
@@ -78,1 +79,23 @@ | ||
``` | ||
## Extending the Octokit instance | ||
`@octokit/core` now supports the [plugin architecture](https://github.com/octokit/core.js#plugins). You can extend the GitHub instance using plugins. | ||
For example, using the `@octokit/plugin-enterprise-server` you can now access enterprise admin apis on GHES instances. | ||
```ts | ||
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils' | ||
import { enterpriseServer220Admin } from '@octokit/plugin-enterprise-server' | ||
const octokit = GitHub.plugin(enterpriseServer220Admin) | ||
// or override some of the default values as well | ||
// const octokit = GitHub.plugin(enterpriseServer220Admin).defaults({userAgent: "MyNewUserAgent"}) | ||
const myToken = core.getInput('myToken'); | ||
const myOctokit = new octokit(getOctokitOptions(token)) | ||
// Create a new user | ||
myOctokit.enterpriseAdmin.createUser({ | ||
login: "testuser", | ||
email: "testuser@test.com", | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
24605
18
283
98
14
4
2
+ Added@octokit/core@^2.5.1
+ Added@octokit/core@2.5.4(transitive)
+ Added@octokit/plugin-paginate-rest@2.21.3(transitive)
+ Added@octokit/plugin-rest-endpoint-methods@3.17.0(transitive)
+ Added@octokit/types@4.1.105.5.0(transitive)
+ Addeduniversal-user-agent@5.0.0(transitive)
- Removed@octokit/graphql@^4.3.1
- Removed@octokit/rest@^16.43.1
- Removed@octokit/auth-token@5.1.1(transitive)
- Removed@octokit/core@6.1.2(transitive)
- Removed@octokit/endpoint@10.1.1(transitive)
- Removed@octokit/graphql@8.1.1(transitive)
- Removed@octokit/openapi-types@22.2.0(transitive)
- Removed@octokit/plugin-paginate-rest@1.1.2(transitive)
- Removed@octokit/plugin-request-log@1.0.4(transitive)
- Removed@octokit/plugin-rest-endpoint-methods@2.4.0(transitive)
- Removed@octokit/request@9.1.3(transitive)
- Removed@octokit/request-error@1.2.16.1.5(transitive)
- Removed@octokit/rest@16.43.2(transitive)
- Removed@octokit/types@13.6.12.16.2(transitive)
- Removedatob-lite@2.0.0(transitive)
- Removedbefore-after-hook@3.0.2(transitive)
- Removedbtoa-lite@1.0.0(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedlodash.set@4.3.2(transitive)
- Removedlodash.uniq@4.5.0(transitive)
- Removedoctokit-pagination-methods@1.1.0(transitive)
- Removeduniversal-user-agent@4.0.17.0.2(transitive)