Skip to content

Commit

Permalink
feat: add sonarqube cloud connection config
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet committed Oct 8, 2024
1 parent 3a2421c commit 7587fdb
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
22 changes: 21 additions & 1 deletion config-ui/src/plugins/register/sonarqube/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,39 @@ import { IPluginConfig } from '@/types';

import Icon from './assets/icon.svg?react';

import { Organization } from './connection-fields/organization';

export const SonarQubeConfig: IPluginConfig = {
plugin: 'sonarqube',
name: 'SonarQube',
icon: ({ color }) => <Icon fill={color} />,
sort: 11,
connection: {
docLink: DOC_URL.PLUGIN.SONARQUBE.BASIS,
initialValues: {
endpoint: 'https://sonarcloud.io/api/',
},
fields: [
'name',
{
key: 'endpoint',
subLabel: 'Provide the SonarQube instance API endpoint. E.g. http://<host>:<port>/api/',
multipleVersions: {
cloud: 'https://sonarcloud.io/api/',
server: ' ',
},
subLabel: 'If you are using SonarCloud, the endpoint URL will be set to `https://sonarcloud.io/api/`.',
},
({ type, initialValues, values, errors, setValues, setErrors }: any) => (
<Organization
key="organization"
type={type}
initialValues={initialValues}
values={values}
errors={errors}
setValues={setValues}
setErrors={setErrors}
/>
),
'token',
'proxy',
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { Input } from 'antd';

import { Block } from '@/components';
import { useEffect } from 'react';

interface Props {
type: 'create' | 'update';
initialValues: any;
values: any;
errors: any;
setValues: (value: any) => void;
setErrors: (value: any) => void;
}

export const Organization = ({ initialValues, values, setValues, setErrors }: Props) => {
const { endpoint } = values;

useEffect(() => {
setValues({ org: initialValues.org });
}, [initialValues.org]);

useEffect(() => {
setErrors({
org: values.org ? '' : 'organization is required',
});
}, [values.org]);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setValues({
org: e.target.value,
});
};

if (endpoint !== 'https://sonarcloud.io/api/') {
return null;
}

return (
<Block
title="Organization"
description="Add the SonarCloud organization. If you have more than one, please create another connection."
required
>
<Input style={{ width: 386 }} placeholder="e.g. org-1" value={values.org} onChange={handleChange} />
</Block>
);
};

0 comments on commit 7587fdb

Please sign in to comment.