@@ -508,6 +508,15 @@ export interface IAPIPullRequestReview {
508
508
| 'CHANGES_REQUESTED'
509
509
}
510
510
511
+ /** Represents both issue comments and PR review comments */
512
+ export interface IAPIComment {
513
+ readonly id : number
514
+ readonly body : string
515
+ readonly html_url : string
516
+ readonly user : IAPIIdentity
517
+ readonly created_at : string
518
+ }
519
+
511
520
/** The metadata about a GitHub server. */
512
521
export interface IServerMetadata {
513
522
/**
@@ -733,6 +742,79 @@ export class API {
733
742
}
734
743
}
735
744
745
+ /**
746
+ * Fetch an issue comment (i.e. a comment on an issue or pull request).
747
+ *
748
+ * @param owner The owner of the repository
749
+ * @param name The name of the repository
750
+ * @param commentId The ID of the comment
751
+ *
752
+ * @returns The comment if it was found, null if it wasn't, or an error
753
+ * occurred.
754
+ */
755
+ public async fetchIssueComment (
756
+ owner : string ,
757
+ name : string ,
758
+ commentId : string
759
+ ) : Promise < IAPIComment | null > {
760
+ try {
761
+ const response = await this . request (
762
+ 'GET' ,
763
+ `repos/${ owner } /${ name } /issues/comments/${ commentId } `
764
+ )
765
+ if ( response . status === HttpStatusCode . NotFound ) {
766
+ log . warn (
767
+ `fetchIssueComment: '${ owner } /${ name } /issues/comments/${ commentId } ' returned a 404`
768
+ )
769
+ return null
770
+ }
771
+ return await parsedResponse < IAPIComment > ( response )
772
+ } catch ( e ) {
773
+ log . warn (
774
+ `fetchIssueComment: an error occurred for '${ owner } /${ name } /issues/comments/${ commentId } '` ,
775
+ e
776
+ )
777
+ return null
778
+ }
779
+ }
780
+
781
+ /**
782
+ * Fetch a pull request review comment (i.e. a comment that was posted as part
783
+ * of a review of a pull request).
784
+ *
785
+ * @param owner The owner of the repository
786
+ * @param name The name of the repository
787
+ * @param commentId The ID of the comment
788
+ *
789
+ * @returns The comment if it was found, null if it wasn't, or an error
790
+ * occurred.
791
+ */
792
+ public async fetchPullRequestReviewComment (
793
+ owner : string ,
794
+ name : string ,
795
+ commentId : string
796
+ ) : Promise < IAPIComment | null > {
797
+ try {
798
+ const response = await this . request (
799
+ 'GET' ,
800
+ `repos/${ owner } /${ name } /pulls/comments/${ commentId } `
801
+ )
802
+ if ( response . status === HttpStatusCode . NotFound ) {
803
+ log . warn (
804
+ `fetchPullRequestReviewComment: '${ owner } /${ name } /pulls/comments/${ commentId } ' returned a 404`
805
+ )
806
+ return null
807
+ }
808
+ return await parsedResponse < IAPIComment > ( response )
809
+ } catch ( e ) {
810
+ log . warn (
811
+ `fetchPullRequestReviewComment: an error occurred for '${ owner } /${ name } /pulls/comments/${ commentId } '` ,
812
+ e
813
+ )
814
+ return null
815
+ }
816
+ }
817
+
736
818
/** Fetch a repo by its owner and name. */
737
819
public async fetchRepository (
738
820
owner : string ,
@@ -1047,6 +1129,83 @@ export class API {
1047
1129
}
1048
1130
}
1049
1131
1132
+ /** Fetches all reviews from a given pull request. */
1133
+ public async fetchPullRequestReviews (
1134
+ owner : string ,
1135
+ name : string ,
1136
+ prNumber : string
1137
+ ) {
1138
+ try {
1139
+ const path = `/repos/${ owner } /${ name } /pulls/${ prNumber } /reviews`
1140
+ const response = await this . request ( 'GET' , path )
1141
+ return await parsedResponse < IAPIPullRequestReview [ ] > ( response )
1142
+ } catch ( e ) {
1143
+ log . debug (
1144
+ `failed fetching PR reviews for ${ owner } /${ name } /pulls/${ prNumber } ` ,
1145
+ e
1146
+ )
1147
+ return [ ]
1148
+ }
1149
+ }
1150
+
1151
+ /** Fetches all review comments from a given pull request. */
1152
+ public async fetchPullRequestReviewComments (
1153
+ owner : string ,
1154
+ name : string ,
1155
+ prNumber : string ,
1156
+ reviewId : string
1157
+ ) {
1158
+ try {
1159
+ const path = `/repos/${ owner } /${ name } /pulls/${ prNumber } /reviews/${ reviewId } /comments`
1160
+ const response = await this . request ( 'GET' , path )
1161
+ return await parsedResponse < IAPIComment [ ] > ( response )
1162
+ } catch ( e ) {
1163
+ log . debug (
1164
+ `failed fetching PR review comments for ${ owner } /${ name } /pulls/${ prNumber } ` ,
1165
+ e
1166
+ )
1167
+ return [ ]
1168
+ }
1169
+ }
1170
+
1171
+ /** Fetches all review comments from a given pull request. */
1172
+ public async fetchPullRequestComments (
1173
+ owner : string ,
1174
+ name : string ,
1175
+ prNumber : string
1176
+ ) {
1177
+ try {
1178
+ const path = `/repos/${ owner } /${ name } /pulls/${ prNumber } /comments`
1179
+ const response = await this . request ( 'GET' , path )
1180
+ return await parsedResponse < IAPIComment [ ] > ( response )
1181
+ } catch ( e ) {
1182
+ log . debug (
1183
+ `failed fetching PR comments for ${ owner } /${ name } /pulls/${ prNumber } ` ,
1184
+ e
1185
+ )
1186
+ return [ ]
1187
+ }
1188
+ }
1189
+
1190
+ /** Fetches all comments from a given issue. */
1191
+ public async fetchIssueComments (
1192
+ owner : string ,
1193
+ name : string ,
1194
+ issueNumber : string
1195
+ ) {
1196
+ try {
1197
+ const path = `/repos/${ owner } /${ name } /issues/${ issueNumber } /comments`
1198
+ const response = await this . request ( 'GET' , path )
1199
+ return await parsedResponse < IAPIComment [ ] > ( response )
1200
+ } catch ( e ) {
1201
+ log . debug (
1202
+ `failed fetching issue comments for ${ owner } /${ name } /issues/${ issueNumber } ` ,
1203
+ e
1204
+ )
1205
+ return [ ]
1206
+ }
1207
+ }
1208
+
1050
1209
/**
1051
1210
* Get the combined status for the given ref.
1052
1211
*/
0 commit comments