Skip to content

Commit cf6db00

Browse files
authored
Merge pull request #362 from devtron-labs/feat/webhook-ui
feat: webhook UI
2 parents 7ce8555 + 343d223 commit cf6db00

File tree

16 files changed

+303
-310
lines changed

16 files changed

+303
-310
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Assets/Icon/ic-hash.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Assets/Icon/ic-pull-request.svg

Lines changed: 2 additions & 2 deletions
Loading

src/Assets/Icon/ic-tag.svg

Lines changed: 2 additions & 3 deletions
Loading

src/Common/Common.service.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import moment from 'moment'
1818
import { RuntimeParamsAPIResponseType, RuntimeParamsListItemType } from '@Shared/types'
1919
import { getIsManualApprovalSpecific, sanitizeUserApprovalConfig, stringComparatorBySortOrder } from '@Shared/Helpers'
2020
import { get, post } from './Api'
21-
import { ROUTES } from './Constants'
21+
import { GitProviderType, ROUTES } from './Constants'
2222
import { getUrlWithSearchParams, sortCallback } from './Helper'
2323
import {
2424
TeamList,
@@ -250,7 +250,7 @@ const getImageApprovalPolicyDetailsFromMaterialResult = (cdMaterialsResult): Ima
250250
const validGroups = userApprovalConfig.userGroups.map((group) => group.identifier)
251251

252252
// Have moved from Object.keys(imageApprovalUsersInfo) to approvalUsers since backend is not filtering out the users without approval
253-
// TODO: This check should be on BE. Need to remove this once BE is updated
253+
// TODO: This check should be on BE. Need to remove this once BE is updated
254254
const usersList = approvalUsers.filter((user) => user !== DefaultUserKey.system)
255255
const groupIdentifierToUsersMap = usersList.reduce(
256256
(acc, user) => {
@@ -511,3 +511,19 @@ export function getWebhookEventsForEventId(eventId: string | number) {
511511
const URL = `${ROUTES.GIT_HOST_EVENT}/${eventId}`
512512
return get(URL)
513513
}
514+
515+
/**
516+
*
517+
* @param gitUrl Git URL of the repository
518+
* @param branchName Branch name
519+
* @returns URL to the branch in the Git repository
520+
*/
521+
export const getGitBranchUrl = (gitUrl: string, branchName: string): string | null => {
522+
if (!gitUrl) return null
523+
const trimmedGitUrl = gitUrl.trim().replace(/\.git$/, '').replace(/\/$/, '') // Remove any trailing slash
524+
if (trimmedGitUrl.includes(GitProviderType.GITLAB)) return `${trimmedGitUrl}/-/tree/${branchName}`
525+
else if (trimmedGitUrl.includes(GitProviderType.GITHUB)) return `${trimmedGitUrl}/tree/${branchName}`
526+
else if (trimmedGitUrl.includes(GitProviderType.BITBUCKET)) return `${trimmedGitUrl}/branch/${branchName}`
527+
else if (trimmedGitUrl.includes(GitProviderType.AZURE)) return `${trimmedGitUrl}/src/branch/${branchName}`
528+
return null
529+
}

src/Common/Constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,20 @@ export const VULNERABILITIES_SORT_PRIORITY = {
558558

559559
// TODO: might not work need to verify
560560
export const IS_PLATFORM_MAC_OS = window.navigator.userAgent.toUpperCase().includes('MAC')
561+
562+
/**
563+
* Git provider types
564+
*/
565+
566+
export enum GitProviderType {
567+
GITHUB = 'github',
568+
GITLAB = 'gitlab',
569+
BITBUCKET = 'bitbucket',
570+
AZURE = 'azure',
571+
GITEA = 'gitea',
572+
}
573+
574+
/**
575+
* Formats the schema removing any irregularity in the existing schema
576+
*/
577+
export const getFormattedSchema = (schema?: string) => JSON.stringify(JSON.parse(schema ?? '{}'), null, 2)

src/Common/Helper.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ import {
4040
ToastManager,
4141
ToastVariantType,
4242
versionComparatorBySortOrder,
43+
WebhookEventNameType,
4344
} from '../Shared'
44-
import { ReactComponent as ArrowDown } from '../Assets/Icon/ic-chevron-down.svg'
45+
import { ReactComponent as ArrowDown } from '@Icons/ic-chevron-down.svg'
46+
import webhookIcon from '@Icons/ic-webhook.svg'
47+
import branchIcon from '@Icons/ic-branch.svg'
48+
import regexIcon from '@Icons/ic-regex.svg'
49+
import pullRequest from '@Icons/ic-pull-request.svg'
50+
import tagIcon from '@Icons/ic-tag.svg'
51+
import { SourceTypeMap } from '@Common/Common.service'
4552

4653
export function showError(serverError, showToastOnUnknownError = true, hideAccessError = false) {
4754
if (serverError instanceof ServerErrors && Array.isArray(serverError.errors)) {
@@ -956,6 +963,29 @@ export const throttle = <T extends (...args: unknown[]) => unknown>(
956963
}
957964
}
958965

966+
/**
967+
*
968+
* @param sourceType - SourceTypeMap
969+
* @param _isRegex - boolean
970+
* @param webhookEventName - WebhookEventNameType
971+
* @returns - Icon
972+
*/
973+
export const getBranchIcon = (sourceType, _isRegex?: boolean, webhookEventName?: string) => {
974+
if (sourceType === SourceTypeMap.WEBHOOK) {
975+
if (webhookEventName === WebhookEventNameType.PULL_REQUEST) {
976+
return pullRequest
977+
}
978+
if (webhookEventName === WebhookEventNameType.TAG_CREATION) {
979+
return tagIcon
980+
}
981+
return webhookIcon
982+
}
983+
if (sourceType === SourceTypeMap.BranchRegex || _isRegex) {
984+
return regexIcon
985+
}
986+
return branchIcon
987+
}
988+
959989
// TODO: Might need to expose sandbox and referrer policy
960990
export const getSanitizedIframe = (iframeString: string) =>
961991
DOMPurify.sanitize(iframeString, {

src/Shared/Components/CICDHistory/CiPipelineSourceConfig.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,11 @@
1616

1717
import { useState, useEffect, ReactNode } from 'react'
1818
import Tippy from '@tippyjs/react'
19-
import { getWebhookEventsForEventId, SourceTypeMap } from '../../../Common'
19+
import { ReactComponent as Info } from '@Icons/ic-info-outlined.svg'
20+
import { getBranchIcon, getWebhookEventsForEventId, SourceTypeMap } from '../../../Common'
2021
import { GIT_BRANCH_NOT_CONFIGURED, DEFAULT_GIT_BRANCH_VALUE } from './constants'
21-
import webhookIcon from '../../../Assets/Icon/ic-webhook.svg'
22-
import branchIcon from '../../../Assets/Icon/ic-branch.svg'
23-
import { ReactComponent as Info } from '../../../Assets/Icon/ic-info-outlined.svg'
24-
import regexIcon from '../../../Assets/Icon/ic-regex.svg'
2522
import { buildHoverHtmlForWebhook } from './utils'
26-
27-
export interface CIPipelineSourceConfigInterface {
28-
sourceType
29-
sourceValue
30-
showTooltip?: boolean
31-
showIcons?: boolean
32-
baseText?: string
33-
regex?: any
34-
isRegex?: boolean
35-
primaryBranchAfterRegex?: string
36-
}
23+
import { CIPipelineSourceConfigInterface } from './types'
3724

3825
export const CiPipelineSourceConfig = ({
3926
sourceType,
@@ -44,11 +31,12 @@ export const CiPipelineSourceConfig = ({
4431
regex,
4532
isRegex,
4633
primaryBranchAfterRegex,
34+
rootClassName = '',
4735
}: CIPipelineSourceConfigInterface) => {
4836
const _isWebhook = sourceType === SourceTypeMap.WEBHOOK
4937
const _isRegex = sourceType === SourceTypeMap.BranchRegex || !!regex || isRegex
5038

51-
const [sourceValueBase, setSourceValueBase] = useState<ReactNode>('')
39+
const [sourceValueBase, setSourceValueBase] = useState('')
5240
const [sourceValueAdv, setSourceValueAdv] = useState<ReactNode>('')
5341
const [loading, setLoading] = useState(!!_isWebhook)
5442

@@ -97,7 +85,7 @@ export const CiPipelineSourceConfig = ({
9785
)}
9886
</>
9987
)
100-
// for non webhook case, data is already set in use state initialisation
88+
// for non webhook case, data is already set in use state initialization
10189
function _init() {
10290
if (!_isWebhook) {
10391
return
@@ -130,16 +118,14 @@ export const CiPipelineSourceConfig = ({
130118
regexTippyContent()
131119
}, [])
132120

133-
const isRegexOrBranchIcon = _isRegex ? regexIcon : branchIcon
134-
135121
return (
136-
<div className={`flex left ${showTooltip ? 'branch-name' : ''}`}>
122+
<div className={`flex left ${showTooltip ? 'fw-5' : ''} ${rootClassName}`}>
137123
{loading && showIcons && <span className="dc__loading-dots">loading</span>}
138124
{!loading && (
139125
<div className="flex dc__gap-4">
140126
{showIcons && (
141127
<img
142-
src={_isWebhook ? webhookIcon : isRegexOrBranchIcon}
128+
src={getBranchIcon(sourceType, _isRegex, sourceValueBase)}
143129
alt="branch"
144130
className="icon-dim-12"
145131
/>
@@ -170,7 +156,7 @@ export const CiPipelineSourceConfig = ({
170156
</>
171157
)}
172158
{baseText && (
173-
<span className="cursor" style={{ borderBottom: '1px solid #3b444c' }}>
159+
<span className="dc__border-dashed--n3-bottom fw-6 fs-13 lh-19-imp">
174160
{baseText}
175161
</span>
176162
)}

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,3 +791,15 @@ export type CreateMarkupPropsType =
791791
export type TriggerHistoryFilterCriteriaType = `${string}|${string}|${string}`[]
792792
export const terminalStatus = new Set(['error', 'healthy', 'succeeded', 'cancelled', 'failed', 'aborted'])
793793
export const statusSet = new Set(['starting', 'running', 'pending'])
794+
795+
export interface CIPipelineSourceConfigInterface {
796+
sourceType: string
797+
sourceValue: any // TODO: need to make source value consistent
798+
showTooltip?: boolean
799+
showIcons?: boolean
800+
baseText?: string
801+
regex?: any
802+
isRegex?: boolean
803+
primaryBranchAfterRegex?: string
804+
rootClassName?: string
805+
}

0 commit comments

Comments
 (0)