You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitlabForm.tsx 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { Link } from 'design-system';
  21. import * as React from 'react';
  22. import { FormattedMessage } from 'react-intl';
  23. import { ALM_DOCUMENTATION_PATHS } from '../../../../helpers/constants';
  24. import { useDocUrl } from '../../../../helpers/docs';
  25. import { translate } from '../../../../helpers/l10n';
  26. import { AlmKeys, GitlabBindingDefinition } from '../../../../types/alm-settings';
  27. import { AlmBindingDefinitionFormField } from './AlmBindingDefinitionFormField';
  28. export interface GitlabFormProps {
  29. formData: GitlabBindingDefinition;
  30. onFieldChange: (fieldId: keyof GitlabBindingDefinition, value: string) => void;
  31. }
  32. export default function GitlabForm(props: GitlabFormProps) {
  33. const { formData, onFieldChange } = props;
  34. const toStatic = useDocUrl(ALM_DOCUMENTATION_PATHS[AlmKeys.GitLab]);
  35. return (
  36. <>
  37. <AlmBindingDefinitionFormField
  38. autoFocus
  39. help={translate('settings.almintegration.form.name.gitlab.help')}
  40. id="name.gitlab"
  41. onFieldChange={onFieldChange}
  42. propKey="key"
  43. value={formData.key}
  44. maxLength={200}
  45. />
  46. <AlmBindingDefinitionFormField
  47. help={
  48. <>
  49. {translate('settings.almintegration.form.url.gitlab.help')}
  50. <br />
  51. <em>https://gitlab.com/api/v4</em>
  52. <br />
  53. <br />
  54. {translate('settings.almintegration.form.url.pat_warning')}
  55. </>
  56. }
  57. id="url.gitlab"
  58. maxLength={2000}
  59. onFieldChange={onFieldChange}
  60. propKey="url"
  61. value={formData.url || ''}
  62. />
  63. <AlmBindingDefinitionFormField
  64. help={
  65. <FormattedMessage
  66. defaultMessage={translate(
  67. `settings.almintegration.form.personal_access_token.gitlab.help`,
  68. )}
  69. id="settings.almintegration.form.personal_access_token.gitlab.help"
  70. values={{
  71. pat: (
  72. <Link
  73. to="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html"
  74. target="_blank"
  75. >
  76. {translate('settings.almintegration.form.personal_access_token.gitlab.help.url')}
  77. </Link>
  78. ),
  79. permission: <strong>Reporter</strong>,
  80. scope: <strong>api</strong>,
  81. doc_link: <Link to={toStatic}>{translate('learn_more')}</Link>,
  82. }}
  83. />
  84. }
  85. id="personal_access_token"
  86. isTextArea
  87. onFieldChange={onFieldChange}
  88. overwriteOnly={Boolean(formData.key)}
  89. propKey="personalAccessToken"
  90. value={formData.personalAccessToken}
  91. maxLength={2000}
  92. isSecret
  93. />
  94. </>
  95. );
  96. }