@@ -113,6 +113,37 @@ function renderField( | |||
); | |||
} | |||
function renderMonoRepoField(props: { | |||
monorepoEnabled: boolean; | |||
value?: boolean; | |||
docLink: string; | |||
onFieldChange: (id: keyof ProjectAlmBindingResponse, value: string | boolean) => void; | |||
}) { | |||
if (!props.monorepoEnabled) { | |||
return null; | |||
} | |||
return renderBooleanField({ | |||
help: true, | |||
helpParams: { | |||
doc_link: ( | |||
<Link to={props.docLink} target="_blank"> | |||
{translate('learn_more')} | |||
</Link> | |||
) | |||
}, | |||
id: 'monorepo', | |||
onFieldChange: props.onFieldChange, | |||
propKey: 'monorepo', | |||
value: props.value ?? false, | |||
inputExtra: props.value && ( | |||
<Alert className="no-margin-bottom spacer-left" variant="warning" display="inline"> | |||
{translate('settings.pr_decoration.binding.form.monorepo.warning')} | |||
</Alert> | |||
) | |||
}); | |||
} | |||
export default function AlmSpecificForm(props: AlmSpecificFormProps) { | |||
const { | |||
alm, | |||
@@ -138,26 +169,12 @@ export default function AlmSpecificForm(props: AlmSpecificFormProps) { | |||
propKey: 'repository', | |||
value: repository || '' | |||
})} | |||
{monorepoEnabled && | |||
renderBooleanField({ | |||
help: true, | |||
helpParams: { | |||
doc_link: ( | |||
<Link to="/documentation/analysis/azuredevops-integration/" target="_blank"> | |||
{translate('learn_more')} | |||
</Link> | |||
) | |||
}, | |||
id: 'azure.monorepo', | |||
onFieldChange: props.onFieldChange, | |||
propKey: 'monorepo', | |||
value: monorepo ?? false, | |||
inputExtra: monorepo && ( | |||
<Alert className="no-margin-bottom spacer-left" variant="warning" display="inline"> | |||
{translate('settings.pr_decoration.binding.form.azure.monorepo.warning')} | |||
</Alert> | |||
) | |||
})} | |||
{renderMonoRepoField({ | |||
monorepoEnabled, | |||
value: monorepo, | |||
docLink: '/documentation/analysis/azuredevops-integration/', | |||
onFieldChange: props.onFieldChange | |||
})} | |||
</> | |||
); | |||
case AlmKeys.Bitbucket: | |||
@@ -195,6 +212,12 @@ export default function AlmSpecificForm(props: AlmSpecificFormProps) { | |||
propKey: 'slug', | |||
value: slug || '' | |||
})} | |||
{renderMonoRepoField({ | |||
monorepoEnabled, | |||
value: monorepo, | |||
docLink: '/documentation/analysis/bitbucket-integration/', | |||
onFieldChange: props.onFieldChange | |||
})} | |||
</> | |||
); | |||
case AlmKeys.GitHub: |
@@ -181,15 +181,18 @@ export class PRDecorationBinding extends React.PureComponent<Props & StateProps, | |||
}); | |||
} | |||
case AlmKeys.Bitbucket: { | |||
if (!almSpecificFields) { | |||
const repository = almSpecificFields?.repository; | |||
const slug = almSpecificFields?.slug; | |||
const monorepo = almSpecificFields?.monorepo ?? false; | |||
if (!repository || !slug) { | |||
return Promise.reject(); | |||
} | |||
const { repository = '', slug = '' } = almSpecificFields; | |||
return setProjectBitbucketBinding({ | |||
almSetting, | |||
project, | |||
repository, | |||
slug | |||
slug, | |||
monorepo | |||
}); | |||
} | |||
case AlmKeys.GitHub: { |
@@ -26,8 +26,11 @@ it.each([ | |||
[AlmKeys.Azure, false], | |||
[AlmKeys.Azure, true], | |||
[AlmKeys.Bitbucket, false], | |||
[AlmKeys.Bitbucket, true], | |||
[AlmKeys.GitHub, false], | |||
[AlmKeys.GitLab, false] | |||
[AlmKeys.GitHub, true], | |||
[AlmKeys.GitLab, false], | |||
[AlmKeys.GitLab, true] | |||
])('it should render correctly for %s and monorepo=%s', (alm, monorepoEnabled) => { | |||
expect(shallowRender(alm, { monorepoEnabled })).toMatchSnapshot(); | |||
}); |
@@ -146,7 +146,8 @@ describe('handleSubmit', () => { | |||
const bitbucketKey = 'bitbucket'; | |||
const repository = 'repoKey'; | |||
const slug = 'repoSlug'; | |||
wrapper.setState({ formData: { key: bitbucketKey, repository, slug }, instances }); | |||
const monorepo = true; | |||
wrapper.setState({ formData: { key: bitbucketKey, repository, slug, monorepo }, instances }); | |||
wrapper.instance().handleSubmit(); | |||
await waitAndUpdate(wrapper); | |||
@@ -154,7 +155,8 @@ describe('handleSubmit', () => { | |||
almSetting: bitbucketKey, | |||
project: PROJECT_KEY, | |||
repository, | |||
slug | |||
slug, | |||
monorepo | |||
}); | |||
expect(wrapper.state().success).toBe(true); | |||
}); | |||
@@ -258,6 +260,37 @@ it('should accept submit azure settings', async () => { | |||
}); | |||
}); | |||
it('should reject submitted bbs settings', async () => { | |||
const wrapper = shallowRender(); | |||
expect.assertions(2); | |||
await expect( | |||
wrapper | |||
.instance() | |||
.submitProjectAlmBinding(AlmKeys.Bitbucket, 'bbs-binding', { slug: 'project' }) | |||
).rejects.toBeUndefined(); | |||
await expect( | |||
wrapper | |||
.instance() | |||
.submitProjectAlmBinding(AlmKeys.Bitbucket, 'bbs-binding', { repository: 'repo' }) | |||
).rejects.toBeUndefined(); | |||
}); | |||
it('should accept submit bbs settings', async () => { | |||
const wrapper = shallowRender(); | |||
await wrapper.instance().submitProjectAlmBinding(AlmKeys.Bitbucket, 'bbs', { | |||
repository: 'bbs-repo', | |||
slug: 'bbs-project' | |||
}); | |||
expect(setProjectBitbucketBinding).toHaveBeenCalledWith({ | |||
almSetting: 'bbs', | |||
project: PROJECT_KEY, | |||
repository: 'bbs-repo', | |||
slug: 'bbs-project', | |||
monorepo: false | |||
}); | |||
}); | |||
it('should reject submit github settings', async () => { | |||
const wrapper = shallowRender(); | |||
@@ -152,15 +152,15 @@ exports[`it should render correctly for azure and monorepo=true 1`] = ` | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="azure.monorepo" | |||
htmlFor="monorepo" | |||
> | |||
settings.pr_decoration.binding.form.azure.monorepo | |||
settings.pr_decoration.binding.form.monorepo | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.azure.monorepo.help" | |||
id="settings.pr_decoration.binding.form.azure.monorepo.help" | |||
defaultMessage="settings.pr_decoration.binding.form.monorepo.help" | |||
id="settings.pr_decoration.binding.form.monorepo.help" | |||
values={ | |||
Object { | |||
"doc_link": <Link | |||
@@ -183,7 +183,7 @@ exports[`it should render correctly for azure and monorepo=true 1`] = ` | |||
> | |||
<InputForBoolean | |||
isDefault={true} | |||
name="azure.monorepo" | |||
name="monorepo" | |||
onChange={[Function]} | |||
value={false} | |||
/> | |||
@@ -287,6 +287,143 @@ exports[`it should render correctly for bitbucket and monorepo=false 1`] = ` | |||
</Fragment> | |||
`; | |||
exports[`it should render correctly for bitbucket and monorepo=true 1`] = ` | |||
<Fragment> | |||
<div | |||
className="form-field" | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="bitbucket.repository" | |||
> | |||
settings.pr_decoration.binding.form.bitbucket.repository | |||
<em | |||
className="mandatory" | |||
> | |||
* | |||
</em> | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.bitbucket.repository.help" | |||
id="settings.pr_decoration.binding.form.bitbucket.repository.help" | |||
values={ | |||
Object { | |||
"example": <React.Fragment> | |||
.../projects/ | |||
<strong> | |||
{KEY} | |||
</strong> | |||
/repos/{SLUG}/browse | |||
</React.Fragment>, | |||
} | |||
} | |||
/> | |||
} | |||
placement="right" | |||
/> | |||
</label> | |||
<input | |||
className="input-super-large" | |||
id="bitbucket.repository" | |||
maxLength={256} | |||
name="bitbucket.repository" | |||
onChange={[Function]} | |||
type="text" | |||
value="" | |||
/> | |||
</div> | |||
<div | |||
className="form-field" | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="bitbucket.slug" | |||
> | |||
settings.pr_decoration.binding.form.bitbucket.slug | |||
<em | |||
className="mandatory" | |||
> | |||
* | |||
</em> | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.bitbucket.slug.help" | |||
id="settings.pr_decoration.binding.form.bitbucket.slug.help" | |||
values={ | |||
Object { | |||
"example": <React.Fragment> | |||
.../projects/{KEY}/repos/ | |||
<strong> | |||
{SLUG} | |||
</strong> | |||
/browse | |||
</React.Fragment>, | |||
} | |||
} | |||
/> | |||
} | |||
placement="right" | |||
/> | |||
</label> | |||
<input | |||
className="input-super-large" | |||
id="bitbucket.slug" | |||
maxLength={256} | |||
name="bitbucket.slug" | |||
onChange={[Function]} | |||
type="text" | |||
value="" | |||
/> | |||
</div> | |||
<div | |||
className="form-field" | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="monorepo" | |||
> | |||
settings.pr_decoration.binding.form.monorepo | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.monorepo.help" | |||
id="settings.pr_decoration.binding.form.monorepo.help" | |||
values={ | |||
Object { | |||
"doc_link": <Link | |||
onlyActiveOnIndex={false} | |||
style={Object {}} | |||
target="_blank" | |||
to="/documentation/analysis/bitbucket-integration/" | |||
> | |||
learn_more | |||
</Link>, | |||
} | |||
} | |||
/> | |||
} | |||
placement="right" | |||
/> | |||
</label> | |||
<div | |||
className="display-flex-center" | |||
> | |||
<InputForBoolean | |||
isDefault={true} | |||
name="monorepo" | |||
onChange={[Function]} | |||
value={false} | |||
/> | |||
</div> | |||
</div> | |||
</Fragment> | |||
`; | |||
exports[`it should render correctly for github and monorepo=false 1`] = ` | |||
<Fragment> | |||
<div | |||
@@ -362,6 +499,81 @@ exports[`it should render correctly for github and monorepo=false 1`] = ` | |||
</Fragment> | |||
`; | |||
exports[`it should render correctly for github and monorepo=true 1`] = ` | |||
<Fragment> | |||
<div | |||
className="form-field" | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="github.repository" | |||
> | |||
settings.pr_decoration.binding.form.github.repository | |||
<em | |||
className="mandatory" | |||
> | |||
* | |||
</em> | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.github.repository.help" | |||
id="settings.pr_decoration.binding.form.github.repository.help" | |||
values={ | |||
Object { | |||
"example": "SonarSource/sonarqube", | |||
} | |||
} | |||
/> | |||
} | |||
placement="right" | |||
/> | |||
</label> | |||
<input | |||
className="input-super-large" | |||
id="github.repository" | |||
maxLength={256} | |||
name="github.repository" | |||
onChange={[Function]} | |||
type="text" | |||
value="" | |||
/> | |||
</div> | |||
<div | |||
className="form-field" | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="github.summary_comment_setting" | |||
> | |||
settings.pr_decoration.binding.form.github.summary_comment_setting | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.github.summary_comment_setting.help" | |||
id="settings.pr_decoration.binding.form.github.summary_comment_setting.help" | |||
values={Object {}} | |||
/> | |||
} | |||
placement="right" | |||
/> | |||
</label> | |||
<div | |||
className="display-flex-center" | |||
> | |||
<InputForBoolean | |||
isDefault={true} | |||
name="github.summary_comment_setting" | |||
onChange={[Function]} | |||
value={true} | |||
/> | |||
</div> | |||
</div> | |||
</Fragment> | |||
`; | |||
exports[`it should render correctly for gitlab and monorepo=false 1`] = ` | |||
<div | |||
className="form-field" | |||
@@ -389,6 +601,33 @@ exports[`it should render correctly for gitlab and monorepo=false 1`] = ` | |||
</div> | |||
`; | |||
exports[`it should render correctly for gitlab and monorepo=true 1`] = ` | |||
<div | |||
className="form-field" | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="gitlab.repository" | |||
> | |||
settings.pr_decoration.binding.form.gitlab.repository | |||
<em | |||
className="mandatory" | |||
> | |||
* | |||
</em> | |||
</label> | |||
<input | |||
className="input-super-large" | |||
id="gitlab.repository" | |||
maxLength={256} | |||
name="gitlab.repository" | |||
onChange={[Function]} | |||
type="text" | |||
value="" | |||
/> | |||
</div> | |||
`; | |||
exports[`should render an alert for azure when the monorepo option is activated 1`] = ` | |||
<Fragment> | |||
<div | |||
@@ -466,15 +705,15 @@ exports[`should render an alert for azure when the monorepo option is activated | |||
> | |||
<label | |||
className="display-flex-center" | |||
htmlFor="azure.monorepo" | |||
htmlFor="monorepo" | |||
> | |||
settings.pr_decoration.binding.form.azure.monorepo | |||
settings.pr_decoration.binding.form.monorepo | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay={ | |||
<FormattedMessage | |||
defaultMessage="settings.pr_decoration.binding.form.azure.monorepo.help" | |||
id="settings.pr_decoration.binding.form.azure.monorepo.help" | |||
defaultMessage="settings.pr_decoration.binding.form.monorepo.help" | |||
id="settings.pr_decoration.binding.form.monorepo.help" | |||
values={ | |||
Object { | |||
"doc_link": <Link | |||
@@ -497,7 +736,7 @@ exports[`should render an alert for azure when the monorepo option is activated | |||
> | |||
<InputForBoolean | |||
isDefault={true} | |||
name="azure.monorepo" | |||
name="monorepo" | |||
onChange={[Function]} | |||
value={true} | |||
/> | |||
@@ -506,7 +745,7 @@ exports[`should render an alert for azure when the monorepo option is activated | |||
display="inline" | |||
variant="warning" | |||
> | |||
settings.pr_decoration.binding.form.azure.monorepo.warning | |||
settings.pr_decoration.binding.form.monorepo.warning | |||
</Alert> | |||
</div> | |||
</div> |
@@ -130,6 +130,7 @@ exports[`should render correctly: jenkins tutorial 1`] = ` | |||
Object { | |||
"alm": "bitbucket", | |||
"key": "foo", | |||
"monorepo": true, | |||
"repository": "PROJECT_KEY", | |||
"slug": "repo-slug", | |||
} |
@@ -28,6 +28,7 @@ exports[`should render correctly: default 1`] = ` | |||
Object { | |||
"alm": "bitbucket", | |||
"key": "foo", | |||
"monorepo": true, | |||
"repository": "PROJECT_KEY", | |||
"slug": "repo-slug", | |||
} | |||
@@ -42,6 +43,7 @@ exports[`should render correctly: default 1`] = ` | |||
Object { | |||
"alm": "bitbucket", | |||
"key": "foo", | |||
"monorepo": true, | |||
"repository": "PROJECT_KEY", | |||
"slug": "repo-slug", | |||
} |
@@ -79,6 +79,7 @@ exports[`it should render correctly for bitbucket: content 1`] = ` | |||
Object { | |||
"alm": "bitbucket", | |||
"key": "foo", | |||
"monorepo": true, | |||
"repository": "PROJECT_KEY", | |||
"slug": "repo-slug", | |||
} |
@@ -106,6 +106,7 @@ export function mockProjectBitbucketBindingResponse( | |||
key: 'foo', | |||
repository: 'PROJECT_KEY', | |||
slug: 'repo-slug', | |||
monorepo: true, | |||
...overrides | |||
}; | |||
} |
@@ -73,6 +73,7 @@ export interface ProjectBitbucketBindingResponse extends ProjectAlmBindingRespon | |||
alm: AlmKeys.Bitbucket; | |||
repository: string; | |||
slug: string; | |||
monorepo: boolean; | |||
} | |||
export interface ProjectGitHubBindingResponse extends ProjectAlmBindingResponse { | |||
@@ -100,6 +101,7 @@ export interface AzureProjectAlmBindingParams extends ProjectAlmBindingParams { | |||
export interface BitbucketProjectAlmBindingParams extends ProjectAlmBindingParams { | |||
repository: string; | |||
slug: string; | |||
monorepo: boolean; | |||
} | |||
export interface GithubProjectAlmBindingParams extends ProjectAlmBindingParams { |
@@ -1138,13 +1138,13 @@ settings.pr_decoration.binding.title=Pull Request Decoration | |||
settings.pr_decoration.binding.description=Enable Pull Request Decoration for this project. | |||
settings.pr_decoration.binding.form.url=Project location | |||
settings.pr_decoration.binding.form.name=Configuration name | |||
settings.pr_decoration.binding.form.monorepo=Enable mono repository support | |||
settings.pr_decoration.binding.form.monorepo.help=Enable this setting if your project is part of a mono repository. {doc_link} | |||
settings.pr_decoration.binding.form.monorepo.warning=This setting must be enabled for all SonarQube projects that are part of a mono repository. | |||
settings.pr_decoration.binding.form.azure.project=Project Name | |||
settings.pr_decoration.binding.form.azure.project.help=The name of the Azure DevOps Server project containing your repository. | |||
settings.pr_decoration.binding.form.azure.repository=Repository Name | |||
settings.pr_decoration.binding.form.azure.repository.help=The name of your Azure DevOps Server repository. | |||
settings.pr_decoration.binding.form.azure.monorepo=Enable mono repository support | |||
settings.pr_decoration.binding.form.azure.monorepo.help=Enable this setting if your project is part of a mono repository. {doc_link} | |||
settings.pr_decoration.binding.form.azure.monorepo.warning=This setting must be enabled for all projects that are part of a mono repository. | |||
settings.pr_decoration.binding.form.github.repository=Repository identifier | |||
settings.pr_decoration.binding.form.github.repository.help=The path of your repository URL. Example: {example} | |||
settings.pr_decoration.binding.form.github.summary_comment_setting=Enable analysis summary under the GitHub Conversation tab |