Skip to content

Commit 59f3022

Browse files
authored
Merge pull request #189 from codacy/force-type-provider
clean: Change provider type
2 parents b69b5ed + 7e194f3 commit 59f3022

4 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/common/parseGitRemote.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
const validProviders: Record<string, 'gh' | 'gl' | 'bb'> = {
1+
import { Provider } from '../api/client'
2+
3+
const validProviders: Record<string, Provider> = {
24
github: 'gh',
35
gitlab: 'gl',
46
bitbucket: 'bb',
57
}
68

79
interface GitRemoteInfo {
8-
provider: 'gh' | 'gl' | 'bb'
10+
provider: Provider
911
organization: string
1012
repository: string
1113
originalRepository?: string
@@ -15,7 +17,7 @@ interface GitRemoteInfo {
1517
* Normalize repository name based on provider
1618
* For GitLab, extracts the last part of group/subgroup/project path
1719
*/
18-
const normalizeRepositoryName = (provider: 'gh' | 'gl' | 'bb', repository: string): string => {
20+
const normalizeRepositoryName = (provider: Provider, repository: string): string => {
1921
if (provider === 'gl') {
2022
// For GitLab, take the last part of the path
2123
const parts = repository.split('/')

src/onboarding.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Api } from './api'
22
import * as vscode from 'vscode'
3-
import { OrganizationService } from './api/client'
3+
import { OrganizationService, Provider } from './api/client'
44
import { CodacyCloud, CodacyCloudState } from './git/CodacyCloud'
55

66
const ORGANIZATIONS_ITERATION_LIMIT = 5
77

8-
const findOrganization = async (provider: 'bb' | 'gh' | 'gl', organization: string, cursor?: string) => {
8+
const findOrganization = async (provider: Provider, organization: string, cursor?: string) => {
99
try {
1010
let currentCursor = cursor
1111
let hasMore = true
@@ -45,7 +45,7 @@ const pendingJoinOrganizationStatus = async () => {
4545
return CodacyCloudState.HasPendingJoinOrganization
4646
}
4747

48-
export const getRepositoryCodacyCloudStatus = async (provider: 'bb' | 'gh' | 'gl', organization: string) => {
48+
export const getRepositoryCodacyCloudStatus = async (provider: Provider, organization: string) => {
4949
const findOrgResult = await findOrganization(provider, organization)
5050
if (!findOrgResult.success) {
5151
// Organization not found on Codacy; User needs to add the organization
@@ -191,11 +191,7 @@ export const addRepository = async (codacyCloud: CodacyCloud) => {
191191
}
192192
}
193193

194-
export const checkFirstAnalysisStatus = async (
195-
provider: 'bb' | 'gh' | 'gl',
196-
organization: string,
197-
repository: string
198-
) => {
194+
export const checkFirstAnalysisStatus = async (provider: Provider, organization: string, repository: string) => {
199195
try {
200196
const { data } = await Api.Analysis.getFirstAnalysisOverview(provider, organization, repository)
201197
return data

src/views/ProblemsDiagnosticCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CodacyCloud } from '../git/CodacyCloud'
55
import { PullRequestIssue } from '../git/PullRequest'
66
import { GitProvider } from '../git/GitProvider'
77
import { BranchIssue } from '../git/IssuesManager'
8-
import { CommitIssue, SeverityLevel } from '../api/client'
8+
import { CommitIssue, Provider, SeverityLevel } from '../api/client'
99
import { ProcessedSarifResult } from '../cli'
1010
import * as path from 'path'
1111
import Logger from '../common/logger'
@@ -371,7 +371,7 @@ export class ProblemsDiagnosticCollection implements vscode.Disposable {
371371
*/
372372
export class IssueActionProvider implements vscode.CodeActionProvider {
373373
constructor(
374-
private getParams?: () => { provider: string; organization: string; repository: string } | undefined,
374+
private getParams?: () => { provider: Provider; organization: string; repository: string } | undefined,
375375
private cli?: CodacyCli
376376
) {}
377377

src/views/hasPermissions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Permission } from '../api/client'
1+
import { Permission, Provider } from '../api/client'
22
import { Api } from '../api'
33

44
export const hasPermission = async (
5-
provider: string,
5+
provider: Provider,
66
organization: string,
77
allowedByDefault: Permission,
88
repositoryPermission?: Permission

0 commit comments

Comments
 (0)