@@ -13,6 +13,7 @@ import {
13
13
RequestClientError ,
14
14
RequestNotFoundError ,
15
15
} from '../../../../errors' ;
16
+ import type { Issue } from '../../../../git/models/issue' ;
16
17
import type { IssueOrPullRequest , IssueOrPullRequestType } from '../../../../git/models/issueOrPullRequest' ;
17
18
import type { PullRequest } from '../../../../git/models/pullRequest' ;
18
19
import type { Provider } from '../../../../git/models/remoteProvider' ;
@@ -25,7 +26,7 @@ import type { LogScope } from '../../../../system/logger.scope';
25
26
import { getLogScope } from '../../../../system/logger.scope' ;
26
27
import { maybeStopWatch } from '../../../../system/stopwatch' ;
27
28
import type { BitbucketIssue , BitbucketPullRequest , BitbucketRepository } from './models' ;
28
- import { bitbucketIssueStateToState , fromBitbucketPullRequest } from './models' ;
29
+ import { bitbucketIssueStateToState , fromBitbucketIssue , fromBitbucketPullRequest } from './models' ;
29
30
30
31
export class BitbucketApi implements Disposable {
31
32
private readonly _disposable : Disposable ;
@@ -92,6 +93,73 @@ export class BitbucketApi implements Disposable {
92
93
return fromBitbucketPullRequest ( response . values [ 0 ] , provider ) ;
93
94
}
94
95
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
+
95
163
@debug < BitbucketApi [ 'getIssueOrPullRequest' ] > ( { args : { 0 : p => p . name , 1 : '<token>' } } )
96
164
public async getIssueOrPullRequest (
97
165
provider : Provider ,
0 commit comments