1+ // Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
2+ // See LICENSE.txt for license information.
3+
14import { GitMergeIcon , GitPullRequestIcon , IssueClosedIcon , IssueOpenedIcon , SkipIcon , IconProps } from '@primer/octicons-react' ;
25import PropTypes from 'prop-types' ;
36import React , { useEffect , useState } from 'react' ;
@@ -50,37 +53,32 @@ export const LinkEmbedPreview = ({embed: {url}, connected}: LinkEmbedProps) => {
5053 if ( isUrlCanPreview ( url ) ) {
5154 const [ owner , repo , type , number ] = url . split ( 'github.com/' ) [ 1 ] . split ( '/' ) ;
5255
53- try {
54- let issueOrPR : any ;
55-
56- if ( type === 'issues' ) {
57- issueOrPR = await Client . getIssue ( owner , repo , Number ( number ) ) ;
58- } else if ( type === 'pull' ) {
59- issueOrPR = await Client . getPullRequest ( owner , repo , Number ( number ) ) ;
60- } else {
61- return ;
62- }
63-
64- if ( issueOrPR && ! ( 'error' in issueOrPR ) ) {
65- const githubData : GitHubData = {
66- owner,
67- repo,
68- type : type as 'issues' | 'pull' ,
69- state : issueOrPR . state || '' ,
70- created_at : issueOrPR . created_at || '' ,
71- title : issueOrPR . title || '' ,
72- number : issueOrPR . number || 0 ,
73- merged : type === 'pull' ? issueOrPR . merged : undefined ,
74- state_reason : issueOrPR . state_reason ,
75- body : issueOrPR . body ,
76- labels : Array . isArray ( issueOrPR . labels ) ? issueOrPR . labels : [ ] ,
77- base : type === 'pull' && issueOrPR . base ? issueOrPR . base : undefined ,
78- head : type === 'pull' && issueOrPR . head ? issueOrPR . head : undefined ,
79- } ;
80- setData ( githubData ) ;
81- }
82- } catch ( error ) {
83- console . error ( 'Error fetching GitHub data:' , error ) ;
56+ let issueOrPR : any ;
57+ if ( type === 'issues' ) {
58+ issueOrPR = await Client . getIssue ( owner , repo , Number ( number ) ) ;
59+ } else if ( type === 'pull' ) {
60+ issueOrPR = await Client . getPullRequest ( owner , repo , Number ( number ) ) ;
61+ } else {
62+ return ;
63+ }
64+
65+ if ( issueOrPR && ! ( 'error' in issueOrPR ) ) {
66+ const githubData : GitHubData = {
67+ owner,
68+ repo,
69+ type : type as 'issues' | 'pull' ,
70+ state : issueOrPR . state || '' ,
71+ created_at : issueOrPR . created_at || '' ,
72+ title : issueOrPR . title || '' ,
73+ number : issueOrPR . number || 0 ,
74+ merged : type === 'pull' && issueOrPR . merged ,
75+ state_reason : issueOrPR . state_reason ,
76+ body : issueOrPR . body ,
77+ labels : Array . isArray ( issueOrPR . labels ) ? issueOrPR . labels : [ ] ,
78+ base : type === 'pull' && issueOrPR . base && issueOrPR . base ,
79+ head : type === 'pull' && issueOrPR . head && issueOrPR . head ,
80+ } ;
81+ setData ( githubData ) ;
8482 }
8583 }
8684 } ;
@@ -93,8 +91,10 @@ export const LinkEmbedPreview = ({embed: {url}, connected}: LinkEmbedProps) => {
9391 } , [ connected , data , url ] ) ;
9492
9593 const getIconElement = ( ) => {
96- if ( ! data ) return null ;
97-
94+ if ( ! data ) {
95+ return null ;
96+ }
97+
9898 const iconProps = {
9999 size : 16 , // Use a number instead of 'small'
100100 verticalAlign : 'text-bottom' as const ,
0 commit comments