@octokit/types#EndpointOptions TypeScript Examples
The following examples show how to use
@octokit/types#EndpointOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: merge.test.ts From file-changes-action with MIT License | 6 votes |
describe('Testing Octokit object...', () => {
beforeAll(() => {
jest.restoreAllMocks()
})
it('...endpoint.merge returns 500 error with pull_number "error"', () => {
expect(() => {
merge(({pull_number: 'error'} as unknown) as EndpointOptions)
}).toThrowError(
new Error(JSON.stringify({name: 'HttpError', status: '500'}))
)
})
it('...endpoint.merge returns 500 error with base "error"', () => {
expect(() => {
merge(({base: 'error'} as unknown) as EndpointOptions)
}).toThrowError(
new Error(JSON.stringify({name: 'HttpError', status: '500'}))
)
})
it('...endpoint.merge returns empty object', async () => {
const request = OctokitPullsListFilesEndpointMergeRequest
const data = merge({...request, pull_number: NaN})
expect(data).toStrictEqual({
...OctokitPullsListFilesEndpointMergeResponse,
...{pull_number: NaN, base: '', head: ''}
})
})
it('...endpoint.merge for pull request', () => {
const request = OctokitPullsListFilesEndpointMergeRequest
const response = OctokitPullsListFilesEndpointMergeResponse
const data = merge(request)
expect(data).toStrictEqual(response)
})
it('...endpoint.merge for push', () => {
const request = OctokitReposCompareCommitsEndpointMergeRequest
const response = OctokitReposCompareCommitsEndpointMergeResponse
const data = merge(request)
expect(data).toStrictEqual(response)
})
})
Example #2
Source File: merge.ts From file-changes-action with MIT License | 6 votes |
fn = jest.fn((data: EndpointOptions, response?: number) => {
if (data.base === 'error' || data.pull_number === 'error') {
throw new Error(JSON.stringify({name: 'HttpError', status: '500'}))
}
if (data.base === 'unknown' || data.pull_number === 'unknown') {
throw JSON.stringify({idk: 'error', message: 'test'})
}
if (
(!data.base && !data.head && Number.isNaN(data.pull_number)) ||
(!data.base && data.head) ||
(data.base && !data.head)
)
return {
...OctokitPullsListFilesEndpointMergeResponse,
...{pull_number: NaN, base: '', head: ''}
} as RequestOptions
if (data.pull_number) {
return {
...OctokitPullsListFilesEndpointMergeResponse,
...data
} as RequestOptions
}
return {
...OctokitReposCompareCommitsEndpointMergeResponse,
...data
} as RequestOptions
})
Example #3
Source File: index.ts From file-changes-action with MIT License | 6 votes |
octokitMock: OctokitMock = {
paginate: (
data: EndpointOptions,
cb?: (response: OctokitResponse<any>) => Promise<any[]>
) => paginate(data, cb),
pulls: {
listFiles: Object.assign((data: EndpointOptions) => listFiles(data), {
endpoint: {
merge: (data: EndpointOptions) => endpointMerge(data)
}
})
},
repos: {
compareCommits: Object.assign(
(data: EndpointOptions) => compareCommits(data),
{
endpoint: {
merge: (data: EndpointOptions) => endpointMerge(data)
}
}
)
}
}
Example #4
Source File: paginate.ts From file-changes-action with MIT License | 6 votes |
fn = jest.fn(
(
data: EndpointOptions,
cb?: (response: OctokitResponse<any>) => Promise<any[]>
) => {
if (
data.owner !== 'trilom' ||
data.repo !== 'file-changes-action' ||
(data.base && !data.head) ||
(!data.base && data.head) ||
// the github api doesn't seem to return an error
// eslint-disable-next-line prefer-promise-reject-errors
(!data.base && !data.head && !data.pull_number)
)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject({name: 'HttpError', status: '404'})
if (data.pull_number) {
if (cb)
return Promise.resolve(cb({data: prResponse} as OctokitResponse<any>))
return Promise.resolve(prResponse)
}
if (cb)
return Promise.resolve(cb({data: pushResponse} as OctokitResponse<any>))
return Promise.resolve([pushResponse])
}
)
Example #5
Source File: payloads.ts From file-changes-action with MIT License | 6 votes |
pushEndpointOptions: EndpointOptions = {
method: 'GET',
baseUrl: 'https://api.github.com',
url: '/repos/:owner/:repo/compare/:base...:head',
owner: 'trilom',
repo: 'file-changes-action',
base: '01a956ad7dbd39773299d421b402535cef6ab1f3',
head: '513ca39ff3756e5b510ad752edaba6a0aeb2efac'
}
Example #6
Source File: endpoint-with-defaults.d.ts From aws-ssm-send-command with MIT License | 5 votes |
export declare function endpointWithDefaults(defaults: typeof DEFAULTS, route: Route | EndpointOptions, options?: RequestParameters): import("@octokit/types").RequestOptions;
Example #7
Source File: payloads.ts From file-changes-action with MIT License | 5 votes |
prEndpointOptions: EndpointOptions = {
method: 'GET',
baseUrl: 'https://api.github.com',
url: '/repos/:owner/:repo/pulls/:pull_number/files',
owner: 'trilom',
repo: 'file-changes-action',
pull_number: 79
}
Example #8
Source File: listFiles.ts From file-changes-action with MIT License | 5 votes |
fn = jest.fn((data: EndpointOptions) => {
return Promise.resolve({
data: OctokitPullsListFilesResponse
} as OctokitResponse<any>)
})
Example #9
Source File: compareCommits.ts From file-changes-action with MIT License | 5 votes |
fn = jest.fn((data: EndpointOptions) => {
return Promise.resolve({
data: {
files: OctokitReposCompareCommitsResponse
}
} as OctokitResponse<any>)
})