Skip to content
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

Pass correct baseUrl to octokit #1288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZauberNerd
Copy link

The PR #1246 replaced the getOctokit method from the octokit-provider.ts file with the getOctokit method from the @actions/github package.
The octokit-provider was previously responsible for creating an Octokit instance and setting the baseUrl via the getServerApiUrl helper function. This function calls getServerUrl which reads the server url from the GITHUB_SERVER_URL environment variable, which on GHES is set to the enterprise instance.
This commit restores the previous behaviour by calling getServerApiUrl in all places where an octokit instance is created.

The PR actions#1246 replaced the `getOctokit` method from the
`octokit-provider.ts` file with the `getOctokit` method from the
`@actions/github` package.
The octokit-provider was previously responsible for creating an Octokit
instance and setting the `baseUrl` via the `getServerApiUrl` helper
function. This function calls `getServerUrl` which reads the server url
from the `GITHUB_SERVER_URL` environment variable, which on GHES is set
to the enterprise instance.
This commit restores the previous behaviour by calling `getServerApiUrl`
in all places where an octokit instance is created.

Co-authored-by: Markus Wolf <mail@markus-wolf.de>
})

it('getDefaultBranch should use GITHUB_SERVER_URL to set the baseUrl', async () => {
;(github.getOctokit as jest.Mock).mockImplementation(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ; necessary for this typecast?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically no, but the prettier configuration in this repository seems to require it. At least the format-check fails without it and format adds it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, my mistake, it is correct. The ; is to prevent the parentheses of (github.getOctokit as jest.Mock) to be interpreted as function invocation in case later statement is added above.

console.log('foo')
(github.getOctokit as jest.Mock)

would be read as console.log('foo')(github.getOctokit as jest.Mock), the ; prevents it.

@fhammerl
Copy link
Contributor

We're already rolling out the hotfix (with the exact same changes :) )

I'll merge this PR regardless, thanks for the unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants