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

[chore] Add rule to make provider casing more consistent #3640

Merged
merged 15 commits into from
Jan 8, 2025
Merged
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to include Bitbucket with these rules, we may mis-case it in the opposite direction BitBucket 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I definitely did that before

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome thank you!

Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,13 @@ module.exports = {
// https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',

'no-restricted-syntax': [
'warn',
{
selector: "JSXText[value=/\\bGithub\\b|\\bGitlab\\b/]",
message: "Use correct casing (GitHub, GitLab)"
}
]
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function GithubIntegrationSection() {

return (
<div className="flex flex-col gap-2">
<h2 className="text-lg font-semibold">Github Integration</h2>
<h2 className="text-lg font-semibold">GitHub Integration</h2>
<GithubIntegrationCopy integrationId={accountDetails?.integrationId} />
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('GithubIntegrationSection', () => {
render(<GithubIntegrationSection />, { wrapper: wrapper() })

const link = await screen.findByRole('link', {
name: /Github/i,
name: /GitHub/i,
})
expect(link).toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import BannerHeading from 'ui/Banner/BannerHeading'
export const ProvidersEnum = Object.freeze({
Github: 'GitHub',
Gitlab: 'GitLab',
BitBucket: 'BitBucket',
Bitbucket: 'Bitbucket',
})

function useProviderSetting() {
Expand All @@ -28,7 +28,7 @@ function useProviderSetting() {
const ghWithNoApp =
!accountDetails?.integrationId && provider === ProvidersEnum.Github

const bbProvider = provider === ProvidersEnum.BitBucket
const bbProvider = provider === ProvidersEnum.Bitbucket
const glProvider = provider === ProvidersEnum.Gitlab

return { ghWithNoApp, bbProvider, glProvider, ghWithApp }
Expand Down Expand Up @@ -83,7 +83,7 @@ const BotErrorHeading = () => {

if (ghWithApp) {
return (
<p className="font-semibold">There was an issue with the Github app</p>
<p className="font-semibold">There was an issue with the GitHub app</p>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('BotErrorBanner', () => {
})

const title = await screen.findByText(
'There was an issue with the Github app'
'There was an issue with the GitHub app'
)
expect(title).toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('EnterpriseLandingPage', () => {
it('displays bitbucket card', async () => {
render(<EnterpriseLandingPage />, { wrapper })

const element = await screen.findByRole('heading', { name: 'BitBucket' })
const element = await screen.findByRole('heading', { name: 'Bitbucket' })
expect(element).toBeInTheDocument()
})

Expand Down Expand Up @@ -138,7 +138,7 @@ describe('EnterpriseLandingPage', () => {
it('displays bitbucket button', () => {
render(<EnterpriseLandingPage />, { wrapper })

expect(screen.queryByText('BitBucket')).toBeNull()
expect(screen.queryByText('Bitbucket')).toBeNull()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('ProviderCard', () => {
)

const element = screen.getByRole('link', {
name: 'Login via BitBucket',
name: 'Login via Bitbucket',
})
expect(element).toBeInTheDocument()
expect(element).toHaveAttribute('href', '/login/bb')
Expand All @@ -43,7 +43,7 @@ describe('ProviderCard', () => {
)

const element = screen.getByRole('link', {
name: 'Login via BitBucket Server',
name: 'Login via Bitbucket Server',
})
expect(element).toBeInTheDocument()
expect(element).toHaveAttribute('href', '/login/bbs')
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SyncProviderPage/SyncButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('SyncButton', () => {
it('renders sync button', () => {
render(<SyncButton provider="bb" />, { wrapper })

const link = screen.getByRole('link', { name: /Sync with BitBucket/ })
const link = screen.getByRole('link', { name: /Sync with Bitbucket/ })

const expectedRedirect = encodeURIComponent('http://localhost:3000/bb')
expect(link).toBeInTheDocument()
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('SyncButton', () => {
render(<SyncButton provider="bbs" />, { wrapper })

const link = screen.getByRole('link', {
name: /Sync with BitBucket Server/,
name: /Sync with Bitbucket Server/,
})

const expectedRedirect = encodeURIComponent('http://localhost:3000/bbs')
Expand Down
20 changes: 10 additions & 10 deletions src/shared/utils/loginProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import sentryLogo from 'assets/providers/sentry-icon.svg'
export const LoginProvidersEnum = {
BITBUCKET: {
provider: 'bb',
name: 'BitBucket',
name: 'Bitbucket',
external: 'BITBUCKET',
externalKey: 'bb',
selfHosted: 'BITBUCKET_SERVER',
selfHostedKey: 'bbs',
selfHostedName: 'BitBucket Server',
selfHostedName: 'Bitbucket Server',
variant: 'bitbucket',
},
GITHUB: {
Expand Down Expand Up @@ -71,17 +71,17 @@ export function loginProviderToShortName(loginProvider?: string) {

export const LOGIN_PROVIDER_NAMES = {
gh: 'GitHub',
bb: 'BitBucket',
bb: 'Bitbucket',
gl: 'GitLab',
ghe: 'GitHub Enterprise',
gle: 'GitLab Enterprise',
bbs: 'BitBucket Server',
bbs: 'Bitbucket Server',
github: 'GitHub',
bitbucket: 'BitBucket',
bitbucket: 'Bitbucket',
gitlab: 'GitLab',
github_enterprise: 'GitHub Enterprise',
gitlab_enterprise: 'GitLab Enterprise',
bitbucket_server: 'BitBucket Server',
bitbucket_server: 'Bitbucket Server',
sentry: 'Sentry',
okta: 'Okta',
} as const
Expand All @@ -99,21 +99,21 @@ export function loginProviderToName(loginProvider?: string) {
export const LOGIN_PROVIDER_IMAGES = {
GitHub: githubLogo,
GitLab: gitlabLogo,
BitBucket: bitbucketLogo,
Bitbucket: bitbucketLogo,
'GitHub Enterprise': githubLogo,
'GitLab Enterprise': gitlabLogo,
'BitBucket Server': bitbucketLogo,
'Bitbucket Server': bitbucketLogo,
Sentry: sentryLogo,
Okta: oktaLogo,
} as const

export const LOGIN_PROVIDER_DARK_MODE_IMAGES = {
GitHub: githubLogoWhite,
GitLab: gitlabLogo,
BitBucket: bitbucketLogo,
Bitbucket: bitbucketLogo,
'GitHub Enterprise': githubLogoWhite,
'GitLab Enterprise': gitlabLogo,
'BitBucket Server': bitbucketLogo,
'Bitbucket Server': bitbucketLogo,
Sentry: sentryLogoWhite,
Okta: oktaLogo,
} as const
Expand Down
44 changes: 22 additions & 22 deletions src/shared/utils/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,74 @@ vi.mock('config')

describe('providerToName', () => {
describe('when called with gh', () => {
it('returns Github', () => {
it('returns GitHub', () => {
expect(providerToName('gh')).toBe('GitHub')
})
})

describe('when called with gl', () => {
it('returns Gitlab', () => {
it('returns GitLab', () => {
expect(providerToName('gl')).toBe('GitLab')
})
})

describe('when called with bb', () => {
it('returns BitBucket', () => {
expect(providerToName('bb')).toBe('BitBucket')
it('returns Bitbucket', () => {
expect(providerToName('bb')).toBe('Bitbucket')
})
})

describe('when called with ghe', () => {
it('returns Github Enterprise', () => {
it('returns GitHub Enterprise', () => {
expect(providerToName('ghe')).toBe('GitHub Enterprise')
})
})

describe('when called with gle', () => {
it('returns Gitlab Enterprise', () => {
it('returns GitLab Enterprise', () => {
expect(providerToName('gle')).toBe('GitLab Enterprise')
})
})

describe('when called with bbs', () => {
it('returns BitBucket Server', () => {
expect(providerToName('bbs')).toBe('BitBucket Server')
it('returns Bitbucket Server', () => {
expect(providerToName('bbs')).toBe('Bitbucket Server')
})
})

describe('when called with Github', () => {
it('returns Github', () => {
describe('when called with GitHub', () => {
it('returns GitHub', () => {
expect(providerToName('github')).toBe('GitHub')
})
})

describe('when called with Gitlab', () => {
it('returns Gitlab', () => {
describe('when called with GitLab', () => {
it('returns GitLab', () => {
expect(providerToName('gitlab')).toBe('GitLab')
})
})

describe('when called with BitBucket', () => {
it('returns BitBucket', () => {
expect(providerToName('bitbucket')).toBe('BitBucket')
describe('when called with Bitbucket', () => {
it('returns Bitbucket', () => {
expect(providerToName('bitbucket')).toBe('Bitbucket')
})
})

describe('when called with github_enterprise', () => {
it('returns Github Enterprise', () => {
it('returns GitHub Enterprise', () => {
expect(providerToName('github_enterprise')).toBe('GitHub Enterprise')
})
})

describe('when called with gitlab-enterprise', () => {
it('returns Gitlab Enterprise', () => {
it('returns GitLab Enterprise', () => {
expect(providerToName('gitlab_enterprise')).toBe('GitLab Enterprise')
})
})

describe('when called with bitbucket_server', () => {
it('returns BitBucket Server', () => {
expect(providerToName('bitbucket_server')).toBe('BitBucket Server')
it('returns Bitbucket Server', () => {
expect(providerToName('bitbucket_server')).toBe('Bitbucket Server')
})
})
})
Expand Down Expand Up @@ -203,19 +203,19 @@ describe('providerToInternalProvider', () => {
})
})

describe('when called with Github', () => {
describe('when called with GitHub', () => {
it('returns github', () => {
expect(providerToInternalProvider('github')).toBe('github')
})
})

describe('when called with Gitlab', () => {
describe('when called with GitLab', () => {
it('returns gitlab', () => {
expect(providerToInternalProvider('gitlab')).toBe('gitlab')
})
})

describe('when called with BitBucket', () => {
describe('when called with Bitbucket', () => {
it('returns bitbucket', () => {
expect(providerToInternalProvider('bitbucket')).toBe('bitbucket')
})
Expand Down
16 changes: 8 additions & 8 deletions src/shared/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { Provider } from 'shared/api/helpers'
export function providerToName(provider: Provider) {
return {
gh: 'GitHub',
bb: 'BitBucket',
bb: 'Bitbucket',
gl: 'GitLab',
ghe: 'GitHub Enterprise',
gle: 'GitLab Enterprise',
bbs: 'BitBucket Server',
bbs: 'Bitbucket Server',
github: 'GitHub',
bitbucket: 'BitBucket',
bitbucket: 'Bitbucket',
gitlab: 'GitLab',
github_enterprise: 'GitHub Enterprise',
gitlab_enterprise: 'GitLab Enterprise',
bitbucket_server: 'BitBucket Server',
bitbucket_server: 'Bitbucket Server',
}[provider.toLowerCase()]
}

Expand Down Expand Up @@ -50,11 +50,11 @@ export function getProviderCommitURL({
}) {
return {
GitHub: `https://github.com/${owner}/${repo}/commit/${commit}`,
BitBucket: `https://bitbucket.org/${owner}/${repo}/commits/${commit}`,
Bitbucket: `https://bitbucket.org/${owner}/${repo}/commits/${commit}`,
GitLab: `https://gitlab.com/${owner}/${repo}/-/commit/${commit}`,
'GitHub Enterprise': `${config.GHE_URL}/${owner}/${repo}/commit/${commit}`,
'GitLab Enterprise': `${config.GLE_URL}/${owner}/${repo}/-/commit/${commit}`,
'BitBucket Server': `${config.BBS_URL}/${owner}/${repo}/commits/${commit}`,
'Bitbucket Server': `${config.BBS_URL}/${owner}/${repo}/commits/${commit}`,
// @ts-expect-error - provider could be undefined but it should be fine
}[providerToName(provider)]
}
Expand All @@ -72,11 +72,11 @@ export function getProviderPullURL({
}) {
return {
GitHub: `https://github.com/${owner}/${repo}/pull/${pullId}`,
BitBucket: `https://bitbucket.org/${owner}/${repo}/pull-requests/${pullId}`,
Bitbucket: `https://bitbucket.org/${owner}/${repo}/pull-requests/${pullId}`,
GitLab: `https://gitlab.com/${owner}/${repo}/-/merge_requests/${pullId}`,
'GitHub Enterprise': `${config.GHE_URL}/${owner}/${repo}/pull/${pullId}`,
'GitLab Enterprise': `${config.GLE_URL}/${owner}/${repo}/-/merge_requests/${pullId}`,
'BitBucket Server': `${config.BBS_URL}/${owner}/${repo}/pull-requests/${pullId}`,
'Bitbucket Server': `${config.BBS_URL}/${owner}/${repo}/pull-requests/${pullId}`,
// @ts-expect-error - provider could be undefined but it should be fine
}[providerToName(provider)]
}
Loading