@@ -10,6 +10,7 @@ import { CodacyCloud, CodacyCloudState } from './CodacyCloud'
1010import { Api } from '../api'
1111import { QualityStatusResponse , getQualityStatus } from '../common/commitStatusHelper'
1212import { Reason } from '../common/types'
13+ import Logger from '../common/logger'
1314
1415const MAX_IN_MEMORY_ITEMS = 300
1516
@@ -119,16 +120,20 @@ export class PullRequest extends PullRequestInfo {
119120 private async fetchCoverage ( ) {
120121 const repo = this . ensureRepository ( )
121122
122- const coverageResponse = await Api . Coverage . getRepositoryPullRequestFilesCoverage (
123- repo . provider ,
124- repo . owner ,
125- repo . name ,
126- this . _prWithAnalysis . pullRequest . number
127- )
123+ try {
124+ const coverageResponse = await Api . Coverage . getRepositoryPullRequestFilesCoverage (
125+ repo . provider ,
126+ repo . owner ,
127+ repo . name ,
128+ this . _prWithAnalysis . pullRequest . number
129+ )
128130
129- const coverageData = coverageResponse . data
130- for ( let i = 0 ; i < coverageData . length ; i ++ ) {
131- this . _diffCoverageLineHits . set ( coverageData [ i ] . fileName , coverageData [ i ] . diffLineHits )
131+ const coverageData = coverageResponse . data
132+ for ( let i = 0 ; i < coverageData . length ; i ++ ) {
133+ this . _diffCoverageLineHits . set ( coverageData [ i ] . fileName , coverageData [ i ] . diffLineHits )
134+ }
135+ } catch ( error ) {
136+ Logger . debug ( `Failed to retrieve coverage` )
132137 }
133138 }
134139
@@ -147,29 +152,32 @@ export class PullRequest extends PullRequestInfo {
147152 // load PR delta issues
148153 this . _issues = [ ]
149154 let nextCursor : string | undefined
150-
151- do {
152- const { data : issues , pagination } = await Api . Analysis . listCommitDeltaIssues (
153- repo . provider ,
154- repo . owner ,
155- repo . name ,
156- this . _headCommit ,
157- this . _baseCommit ,
158- undefined ,
159- undefined ,
160- nextCursor
161- )
162-
163- this . _issues . push (
164- ...issues . map ( ( issue ) => ( {
165- ...issue ,
166- uri : vscode . Uri . parse (
167- `https://app.codacy.com/${ repo . provider } /${ repo . owner } /${ repo . name } /pull-requests/${ this . meta . number } /issues#issue-${ issue . commitIssue . issueId } `
168- ) ,
169- } ) )
170- )
171- nextCursor = pagination ?. cursor
172- } while ( nextCursor && this . _issues . length < MAX_IN_MEMORY_ITEMS )
155+ try {
156+ do {
157+ const { data : issues , pagination } = await Api . Analysis . listCommitDeltaIssues (
158+ repo . provider ,
159+ repo . owner ,
160+ repo . name ,
161+ this . _headCommit ,
162+ this . _baseCommit ,
163+ undefined ,
164+ undefined ,
165+ nextCursor
166+ )
167+
168+ this . _issues . push (
169+ ...issues . map ( ( issue ) => ( {
170+ ...issue ,
171+ uri : vscode . Uri . parse (
172+ `https://app.codacy.com/${ repo . provider } /${ repo . owner } /${ repo . name } /pull-requests/${ this . meta . number } /issues#issue-${ issue . commitIssue . issueId } `
173+ ) ,
174+ } ) )
175+ )
176+ nextCursor = pagination ?. cursor
177+ } while ( nextCursor && this . _issues . length < MAX_IN_MEMORY_ITEMS )
178+ } catch ( error ) {
179+ Logger . debug ( `Failed to retrieve issues: ${ error } ` )
180+ }
173181 }
174182
175183 private async fetchFiles ( ) {
@@ -233,31 +241,35 @@ export class PullRequest extends PullRequestInfo {
233241
234242 public async refresh ( avoidMetadataFetch = false ) {
235243 const fetch = async ( ) => {
236- const wasAnalysing = this . analysis . isAnalysing
237-
238- if ( ! avoidMetadataFetch ) await this . fetchMetadata ( )
239-
240- await this . fetchQualityGates ( )
241- await this . fetchIssues ( )
242- await this . fetchFiles ( )
243- vscode . commands . executeCommand ( 'codacy.pr.refreshCoverageDecoration' )
244-
245- // all done, trigger the pull request update
246- this . _onDidUpdatePullRequest . fire ( this )
247-
248- // if the PR is still analysing, or...
249- // if commit heads don't match, and everything was pushed, try again
250- if (
251- this . analysis . isAnalysing ||
252- ( this . _headCommit !== this . _codacyCloud . head ?. commit && this . _codacyCloud . head ?. ahead === 0 )
253- ) {
254- this . _refreshTimeout && clearTimeout ( this . _refreshTimeout )
255- this . _refreshTimeout = setTimeout ( ( ) => {
256- this . refresh ( )
257- } , PR_REFRESH_TIME )
258- } else if ( wasAnalysing ) {
259- // PR has new results, show a notification depending on them
260- this . showAnalysisNotification ( )
244+ try {
245+ const wasAnalysing = this . analysis . isAnalysing
246+
247+ if ( ! avoidMetadataFetch ) await this . fetchMetadata ( )
248+
249+ await this . fetchQualityGates ( )
250+ await this . fetchIssues ( )
251+ await this . fetchFiles ( )
252+ vscode . commands . executeCommand ( 'codacy.pr.refreshCoverageDecoration' )
253+
254+ // all done, trigger the pull request update
255+ this . _onDidUpdatePullRequest . fire ( this )
256+
257+ // if the PR is still analysing, or...
258+ // if commit heads don't match, and everything was pushed, try again
259+ if (
260+ this . analysis . isAnalysing ||
261+ ( this . _headCommit !== this . _codacyCloud . head ?. commit && this . _codacyCloud . head ?. ahead === 0 )
262+ ) {
263+ this . _refreshTimeout && clearTimeout ( this . _refreshTimeout )
264+ this . _refreshTimeout = setTimeout ( ( ) => {
265+ this . refresh ( )
266+ } , PR_REFRESH_TIME )
267+ } else if ( wasAnalysing ) {
268+ // PR has new results, show a notification depending on them
269+ this . showAnalysisNotification ( )
270+ }
271+ } catch ( error ) {
272+ Logger . debug ( `Failed to refresh pull request: ${ error } ` )
261273 }
262274 }
263275
0 commit comments