|
| 1 | +import React from 'react'; |
| 2 | +import groupBy from 'lodash/groupBy'; |
| 3 | + |
| 4 | +import {tct} from 'app/locale'; |
| 5 | +import AddIntegration from 'app/views/organizationIntegrations/addIntegration'; |
| 6 | +import AlertLink from 'app/components/alertLink'; |
| 7 | +import AsyncComponent from 'app/components/asyncComponent'; |
| 8 | +import {IntegrationProvider, Integration, Repository} from 'app/types'; |
| 9 | + |
| 10 | +type Props = { |
| 11 | + orgId: string; |
| 12 | + providers: IntegrationProvider[]; |
| 13 | + onInstall: (integration: Integration) => void; |
| 14 | +} & AsyncComponent['props']; |
| 15 | + |
| 16 | +type State = { |
| 17 | + unmigratableRepos: Repository[]; |
| 18 | +} & AsyncComponent['state']; |
| 19 | + |
| 20 | +export default class MigrationWarnings extends AsyncComponent<Props, State> { |
| 21 | + getEndpoints(): ([string, string] | [string, string])[] { |
| 22 | + const {orgId} = this.props; |
| 23 | + |
| 24 | + return [['unmigratableRepos', `/organizations/${orgId}/repos/?status=unmigratable`]]; |
| 25 | + } |
| 26 | + |
| 27 | + get unmigratableReposByOrg() { |
| 28 | + // Group by [GitHub|BitBucket|VSTS] Org name |
| 29 | + return groupBy(this.state.unmigratableRepos, repo => repo.name.split('/')[0]); |
| 30 | + } |
| 31 | + |
| 32 | + render() { |
| 33 | + return Object.entries(this.unmigratableReposByOrg).map( |
| 34 | + ([orgName, repos]: [string, Repository[]]) => { |
| 35 | + // Repos use 'visualstudio', Integrations use 'vsts'. Normalize to 'vsts'. |
| 36 | + const key = |
| 37 | + repos[0].provider.id === 'visualstudio' ? 'vsts' : repos[0].provider.id; |
| 38 | + const provider = this.props.providers.find(p => p.key === key); |
| 39 | + |
| 40 | + // The Org might not have access to this Integration yet. |
| 41 | + if (!provider) { |
| 42 | + return ''; |
| 43 | + } |
| 44 | + |
| 45 | + return ( |
| 46 | + <AddIntegration |
| 47 | + key={provider.key} |
| 48 | + provider={provider} |
| 49 | + onInstall={this.props.onInstall} |
| 50 | + > |
| 51 | + {onClick => ( |
| 52 | + <AlertLink onClick={() => onClick()} href="#"> |
| 53 | + {tct( |
| 54 | + "Your [orgName] repositories can't send commit data to Sentry. Add a [orgName] [providerName] instance here.", |
| 55 | + { |
| 56 | + orgName, |
| 57 | + providerName: provider.name, |
| 58 | + } |
| 59 | + )} |
| 60 | + </AlertLink> |
| 61 | + )} |
| 62 | + </AddIntegration> |
| 63 | + ); |
| 64 | + } |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments