Skip to content

Commit 0946e56

Browse files
committed
feat: add proxy support
1 parent 1c556b1 commit 0946e56

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ Options:
8383
-b, --body text of release body
8484
-o, --owner repo owner
8585
-r, --repo repo name
86-
-d, --draft publish as draft [default: false]
87-
-p, --prerelease publish as prerelease [default: false]
88-
-w, --workpath path to working directory [default: current directory]
89-
-e, --endpoint GitHub API endpoint URL [default: "https://api.github.com"]
90-
-a, --assets comma-delimited list of assets to upload [default: false]
91-
--dry-run dry run (stops before release step) [default: false]
92-
-y, --yes bypass confirmation prompt for release [default: false]
86+
-d, --draft publish as draft [default: false]
87+
-p, --prerelease publish as prerelease [default: false]
88+
-w, --workpath path to working directory [default: current directory]
89+
-e, --endpoint GitHub API endpoint URL [default: "https://api.github.com"]
90+
--proxy Use a proxy with your environment variables [default: false]
91+
-a, --assets comma-delimited list of assets to upload [default: false]
92+
--dry-run dry run (stops before release step) [default: false]
93+
-y, --yes bypass confirmation prompt for release [default: false]
9394
-h, --help Show help
9495
-v, --version Show version number
9596
```
@@ -109,7 +110,8 @@ var options = {
109110
prerelease: false,
110111
repo: 'gh-release',
111112
owner: 'ungoldman',
112-
endpoint: 'https://api.github.com' // for GitHub enterprise, use http(s)://hostname/api/v3
113+
endpoint: 'https://api.github.com', // for GitHub enterprise, use http(s)://hostname/api/v3
114+
proxy: true // true will use environment variables, or string to specify a specific address
113115
}
114116

115117
// options can also be just an empty object

bin/lib/get-defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function getDefaults (workPath, isEnterprise, callback) {
7171
dryRun: false,
7272
yes: false,
7373
endpoint: 'https://api.github.com',
74+
proxy: false,
7475
workpath: process.cwd(),
7576
prerelease: false,
7677
draft: false,

bin/lib/yargs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ module.exports = require('yargs')
6060
default: 'https://api.github.com',
6161
describe: 'GitHub API endpoint URL'
6262
},
63+
proxy: {
64+
type: 'boolean',
65+
default: false,
66+
description: 'Use a proxy, uses your environment variables'
67+
},
6368
a: {
6469
alias: 'assets',
6570
type: 'string',

index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const ghReleaseAssets = require('gh-release-assets')
55
const getDefaults = require('./bin/lib/get-defaults')
66
const Emitter = require('events').EventEmitter
77
const { Octokit } = require('@octokit/rest')
8+
const { fetch: undiciFetch, EnvHttpProxyAgent } = require('undici')
89

910
const clientId = '04dac3c40b7e49b11f38'
1011

@@ -24,6 +25,7 @@ const OPTIONS = {
2425
yes: false,
2526
draft: false,
2627
endpoint: 'https://api.github.com',
28+
proxy: false,
2729
prerelease: false,
2830
workpath: process.cwd()
2931
},
@@ -39,6 +41,7 @@ const OPTIONS = {
3941
'yes',
4042
'draft',
4143
'endpoint',
44+
'proxy',
4245
'prerelease',
4346
'workpath',
4447
'assets'
@@ -83,10 +86,27 @@ function _Release (options, emitter, callback) {
8386
// err if auth info not provided (token or user/pass)
8487
if (!getToken(options)) return callback(new Error('missing auth info'))
8588

86-
const octokit = new Octokit({
89+
const octokitOptions = {
8790
auth: getToken(options),
8891
baseUrl: options.endpoint
89-
})
92+
}
93+
94+
if (options.proxy) {
95+
const proxyFetch = (url, requestInit) => {
96+
return undiciFetch(url, {
97+
...requestInit,
98+
dispatcher: new EnvHttpProxyAgent({
99+
keepAliveTimeout: 10,
100+
keepAliveMaxTimeout: 10
101+
})
102+
})
103+
}
104+
octokitOptions.request = {
105+
fetch: proxyFetch
106+
}
107+
}
108+
109+
const octokit = new Octokit(octokitOptions)
90110

91111
octokit.repos.getCommit({
92112
owner: options.owner,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"Ted Janeczko <[email protected]>"
2222
],
2323
"dependencies": {
24-
"@octokit/rest": "^20.1.2",
24+
"@octokit/rest": "^22.0.0",
2525
"changelog-parser": "^3.0.1",
2626
"deep-extend": "^0.6.0",
2727
"gauge": "^5.0.2",
@@ -30,6 +30,7 @@
3030
"github-url-to-object": "^4.0.6",
3131
"inquirer": "^8.2.6",
3232
"shelljs": "^0.10.0",
33+
"undici": "^7.15.0",
3334
"update-notifier": "^5.1.0",
3435
"yargs": "^17.7.2"
3536
},

0 commit comments

Comments
 (0)