-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@actions/github v3 using Octokit/core #453
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d7c1f88
Rebuild to use Octokit Core
thboop 618498d
Example Enterprise Solution
thboop dbbbdff
implement defaults, cleanup
thboop a8c1b03
Update @octokit/core, remove inheritance
thboop 21a8c07
simplify getProxyAgent
thboop 3ec2a3d
Cleanup code
thboop 1d63494
Minor cleanup
thboop c0f321e
Make mainline path getOctokit function
thboop 309c5a6
move non mainline scenarios to helper functions
thboop ebb9e52
Cleanup docs
thboop eb77465
minor doc update
thboop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import * as http from 'http' | ||
import * as https from 'https' | ||
import proxy from 'proxy' | ||
|
||
// Default values are set when the module is imported, so we need to set proxy first. | ||
const proxyUrl = 'http://127.0.0.1:8081' | ||
const originalProxyUrl = process.env['https_proxy'] | ||
process.env['https_proxy'] = proxyUrl | ||
// eslint-disable-next-line import/first | ||
import {getOctokit} from '../src/github' | ||
|
||
describe('@actions/github', () => { | ||
let proxyConnects: string[] | ||
let proxyServer: http.Server | ||
let first = true | ||
|
||
beforeAll(async () => { | ||
// Start proxy server | ||
proxyServer = proxy() | ||
await new Promise(resolve => { | ||
const port = Number(proxyUrl.split(':')[2]) | ||
proxyServer.listen(port, () => resolve()) | ||
}) | ||
proxyServer.on('connect', req => { | ||
proxyConnects.push(req.url) | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
proxyConnects = [] | ||
}) | ||
|
||
afterAll(async () => { | ||
// Stop proxy server | ||
await new Promise(resolve => { | ||
proxyServer.once('close', () => resolve()) | ||
proxyServer.close() | ||
}) | ||
|
||
if (originalProxyUrl) { | ||
process.env['https_proxy'] = originalProxyUrl | ||
} | ||
}) | ||
|
||
it('basic REST client with proxy', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
const octokit = getOctokit(token) | ||
const branch = await octokit.repos.getBranch({ | ||
owner: 'actions', | ||
repo: 'toolkit', | ||
branch: 'master' | ||
}) | ||
expect(branch.data.name).toBe('master') | ||
expect(proxyConnects).toEqual(['api.github.com:443']) | ||
}) | ||
|
||
it('basic GraphQL client with proxy', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
process.env['https_proxy'] = proxyUrl | ||
const octokit = getOctokit(token) | ||
|
||
const repository = await octokit.graphql( | ||
'{repository(owner:"actions", name:"toolkit"){name}}' | ||
) | ||
expect(repository).toEqual({repository: {name: 'toolkit'}}) | ||
expect(proxyConnects).toEqual(['api.github.com:443']) | ||
}) | ||
|
||
it('should only use default agent if one is not provided', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
// Valid token | ||
const octokit = getOctokit(token, { | ||
request: { | ||
agent: new https.Agent() | ||
} | ||
}) | ||
const branch = await octokit.repos.getBranch({ | ||
owner: 'actions', | ||
repo: 'toolkit', | ||
branch: 'master' | ||
}) | ||
expect(branch.data.name).toBe('master') | ||
expect(proxyConnects).toHaveLength(0) | ||
}) | ||
|
||
function getToken(): string { | ||
const token = process.env['GITHUB_TOKEN'] || '' | ||
if (!token && first) { | ||
/* eslint-disable-next-line no-console */ | ||
console.warn( | ||
'Skipping GitHub tests. Set $GITHUB_TOKEN to run REST client and GraphQL client tests' | ||
) | ||
first = false | ||
} | ||
|
||
return token | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now load proxy settings when the module is imported because of the way
defaults
works. This required a new test suite for proxy tests.