Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20]
node: ['>=20.18.1 <21', 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand All @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: ">=20.18.1 <21"
- run: npm install
- run: npm test
env:
Expand All @@ -44,7 +44,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: ">=20.18.1 <21"
- run: npm install
- run: npm run lint
docs:
Expand All @@ -53,7 +53,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: ">=20.18.1 <21"
- run: npm install
- run: npm run docs
- uses: JustinBeckwith/linkinator-action@v1
Expand All @@ -68,6 +68,6 @@ jobs:
ref: main
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: ">=20.18.1 <21"
- run: npm install --save googleapis/release-please#${{ github.ref }}
- run: npm run build
40 changes: 34 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./build/src/index.js",
"bin": "./build/src/bin/release-please.js",
"scripts": {
"test": "cross-env ENVIRONMENT=test LC_ALL=en c8 mocha --node-option no-experimental-fetch --recursive --timeout=5000 build/test",
"test": "cross-env ENVIRONMENT=test LC_ALL=en c8 mocha --recursive --timeout=5000 build/test",
"docs": "echo add docs tests",
"test:snap": "cross-env SNAPSHOT_UPDATE=1 LC_ALL=en npm test",
"clean": "gts clean",
Expand Down Expand Up @@ -46,7 +46,7 @@
"@types/js-yaml": "^4.0.0",
"@types/jsonpath": "^0.2.0",
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/node": "^18.13.0",
"@types/npmlog": "^7.0.0",
"@types/semver": "^7.0.0",
"@types/sinon": "^17.0.0",
Expand Down Expand Up @@ -92,14 +92,15 @@
"semver": "^7.5.3",
"type-fest": "^3.0.0",
"typescript": "^4.6.4",
"undici": "^7.18.2",
"unist-util-visit": "^2.0.3",
"unist-util-visit-parents": "^3.1.1",
"xpath": "^0.0.34",
"yaml": "^2.2.2",
"yargs": "^17.0.0"
},
"engines": {
"node": ">=18.0.0"
"node": ">=20.18.1"
},
"overrides": {
"tmp": "0.2.5"
Expand Down
37 changes: 14 additions & 23 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@
FileNotFoundError as MissingFileError,
} from '@google-automations/git-file-utils';
import {Logger} from 'code-suggester/build/src/types';
import {HttpsProxyAgent} from 'https-proxy-agent';
import {HttpProxyAgent} from 'http-proxy-agent';
import {
fetch as undiciFetch,
EnvHttpProxyAgent,
RequestInit,
RequestInfo,
Response,
} from 'undici';
import {PullRequestOverflowHandler} from './util/pull-request-overflow-handler';
import {mergeUpdates} from './updaters/composite';

Expand All @@ -68,11 +73,6 @@
logger?: Logger;
}

interface ProxyOption {
host: string;
port: number;
}

interface GitHubCreateOptions {
owner: string;
repo: string;
Expand All @@ -82,8 +82,7 @@
octokitAPIs?: OctokitAPIs;
token?: string;
logger?: Logger;
proxy?: ProxyOption;
fetch?: any;

Check warning on line 85 in src/github.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}

type CommitFilter = (commit: Commit) => boolean;
Expand Down Expand Up @@ -220,17 +219,11 @@
this.logger = options.logger ?? defaultLogger;
}

static createDefaultAgent(baseUrl: string, defaultProxy?: ProxyOption) {
if (!defaultProxy) {
return undefined;
}

const {host, port} = defaultProxy;
if (new URL(baseUrl).protocol.replace(':', '') === 'http') {
return new HttpProxyAgent(`http://${host}:${port}`);
} else {
return new HttpsProxyAgent(`https://${host}:${port}`);
}
static fetch(url: RequestInfo, opts: RequestInit): Promise<Response> {
return undiciFetch(url, {
...opts,
dispatcher: new EnvHttpProxyAgent(),
});
}

/**
Expand All @@ -256,8 +249,7 @@
baseUrl: apiUrl,
auth: options.token,
request: {
agent: this.createDefaultAgent(apiUrl, options.proxy),
fetch: options.fetch,
fetch: options.fetch ?? this.fetch,
},
}),
request: request.defaults({
Expand All @@ -271,8 +263,7 @@
graphql: graphql.defaults({
baseUrl: graphqlUrl,
request: {
agent: this.createDefaultAgent(graphqlUrl, options.proxy),
fetch: options.fetch,
fetch: options.fetch ?? this.fetch,
},
headers: {
'user-agent': `release-please/${releasePleaseVersion}`,
Expand Down Expand Up @@ -572,7 +563,7 @@
}
)) {
// Paginate plugin doesn't have types for listing files on a commit
const data = resp.data as any as {files: {filename: string}[]};

Check warning on line 566 in src/github.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const f of data.files || []) {
if (f.filename) {
files.push(f.filename);
Expand Down
36 changes: 1 addition & 35 deletions test/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {resolve} from 'path';
import * as snapshot from 'snap-shot-it';
import * as sinon from 'sinon';

import {GH_API_URL, GitHub, GitHubRelease} from '../src/github';
import {GitHub, GitHubRelease} from '../src/github';
import {PullRequest} from '../src/pull-request';
import {TagName} from '../src/util/tag-name';
import {Version} from '../src/version';
Expand All @@ -38,11 +38,8 @@ import {PullRequestTitle} from '../src/util/pull-request-title';
import * as codeSuggester from 'code-suggester';
import {RawContent} from '../src/updaters/raw-content';
import {ReleasePleaseManifest} from '../src/updaters/release-please-manifest';
import {HttpsProxyAgent} from 'https-proxy-agent';
import {HttpProxyAgent} from 'http-proxy-agent';
import {Commit} from '../src/commit';
import {mockReleaseData, MockPullRequestOverflowHandler} from './helpers';
const fetch = require('node-fetch');

const fixturesPath = './test/fixtures';
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -100,37 +97,6 @@ describe('GitHub', () => {

expect(github.repository.defaultBranch).to.eql('some-branch-from-api');
});

it('default agent is undefined when no proxy option passed ', () => {
expect(GitHub.createDefaultAgent('test_url')).eq(undefined);
});

it('should return a https agent', () => {
expect(
GitHub.createDefaultAgent(GH_API_URL, {
host: 'http://proxy.com',
port: 3000,
})
).instanceof(HttpsProxyAgent);
});

it('should throw error when baseUrl is an invalid url', () => {
expect(() => {
GitHub.createDefaultAgent('invalid_url', {
host: 'http://proxy.com',
port: 3000,
});
}).to.throw('Invalid URL');
});

it('should return a http agent', () => {
expect(
GitHub.createDefaultAgent('http://www.github.com', {
host: 'http://proxy.com',
port: 3000,
})
).instanceof(HttpProxyAgent);
});
});

describe('findFilesByFilename', () => {
Expand Down
Loading