@@ -13,6 +13,7 @@ import {
1313 RequestClientError ,
1414 RequestNotFoundError ,
1515} from '../../../../errors' ;
16+ import type { Issue } from '../../../../git/models/issue' ;
1617import type { IssueOrPullRequest , IssueOrPullRequestType } from '../../../../git/models/issueOrPullRequest' ;
1718import type { PullRequest } from '../../../../git/models/pullRequest' ;
1819import type { Provider } from '../../../../git/models/remoteProvider' ;
@@ -25,7 +26,7 @@ import type { LogScope } from '../../../../system/logger.scope';
2526import { getLogScope } from '../../../../system/logger.scope' ;
2627import { maybeStopWatch } from '../../../../system/stopwatch' ;
2728import type { BitbucketIssue , BitbucketPullRequest , BitbucketRepository } from './models' ;
28- import { bitbucketIssueStateToState , fromBitbucketPullRequest } from './models' ;
29+ import { bitbucketIssueStateToState , fromBitbucketIssue , fromBitbucketPullRequest } from './models' ;
2930
3031export class BitbucketApi implements Disposable {
3132 private readonly _disposable : Disposable ;
@@ -92,6 +93,73 @@ export class BitbucketApi implements Disposable {
9293 return fromBitbucketPullRequest ( response . values [ 0 ] , provider ) ;
9394 }
9495
96+ @debug < BitbucketApi [ 'getUsersIssuesForRepo' ] > ( { args : { 0 : p => p . name , 1 : '<token>' } } )
97+ async getUsersIssuesForRepo (
98+ provider : Provider ,
99+ token : string ,
100+ userUuid : string ,
101+ owner : string ,
102+ repo : string ,
103+ baseUrl : string ,
104+ ) : Promise < Issue [ ] | undefined > {
105+ const scope = getLogScope ( ) ;
106+ const query = encodeURIComponent ( `assignee.uuid="${ userUuid } " OR reporter.uuid="${ userUuid } "` ) ;
107+
108+ const response = await this . request < {
109+ values : BitbucketIssue [ ] ;
110+ pagelen : number ;
111+ size : number ;
112+ page : number ;
113+ } > (
114+ provider ,
115+ token ,
116+ baseUrl ,
117+ `repositories/${ owner } /${ repo } /issues?q=${ query } ` ,
118+ {
119+ method : 'GET' ,
120+ } ,
121+ scope ,
122+ ) ;
123+
124+ if ( ! response ?. values ?. length ) {
125+ return undefined ;
126+ }
127+ return response . values . map ( issue => fromBitbucketIssue ( issue , provider ) ) ;
128+ }
129+
130+ @debug < BitbucketApi [ 'getIssue' ] > ( { args : { 0 : p => p . name , 1 : '<token>' } } )
131+ async getIssue (
132+ provider : Provider ,
133+ token : string ,
134+ owner : string ,
135+ repo : string ,
136+ id : string ,
137+ baseUrl : string ,
138+ ) : Promise < Issue | undefined > {
139+ const scope = getLogScope ( ) ;
140+
141+ try {
142+ const response = await this . request < BitbucketIssue > (
143+ provider ,
144+ token ,
145+ baseUrl ,
146+ `repositories/${ owner } /${ repo } /issues/${ id } ` ,
147+ {
148+ method : 'GET' ,
149+ } ,
150+ scope ,
151+ ) ;
152+
153+ if ( response ) {
154+ return fromBitbucketIssue ( response , provider ) ;
155+ }
156+ return undefined ;
157+ } catch ( ex ) {
158+ Logger . error ( ex , scope ) ;
159+ return undefined ;
160+ }
161+ }
162+
95163 @debug < BitbucketApi [ 'getIssueOrPullRequest' ] > ( { args : { 0 : p => p . name , 1 : '<token>' } } )
96164 public async getIssueOrPullRequest (
97165 provider : Provider ,
0 commit comments