Skip to content

Commit

Permalink
add reviews + requested reviews to the PR dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
deecewan committed Mar 3, 2017
1 parent 96a02e8 commit 2ca1a92
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
57 changes: 57 additions & 0 deletions source/dsl/GitHubDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ export interface GitHubPRDSL {
*/
assignees: Array<GitHubUser>

/**
* The people requested to review this PR
* @type {GitHubReview}
*/
requestedReviewers: Array<GitHubUser>

/**
* The reviews left on this pull request
* @type {Array<GitHubReview>}
* @memberOf GitHubPRDSL
*/
reviews: Array<GitHubReview>

/**
* Has the PR been merged yet
* @type {boolean}
Expand Down Expand Up @@ -315,3 +328,47 @@ export interface GitHubMergeRef {
*/
user: GitHubUser
}

/**
* GitHubReview
* While a review is pending, it will only have a user. Once a review is complete, the rest of
* the review attributes will be present
* @export
* @interface GitHubReview
*/
export interface GitHubReview {
/**
* The user requested to review, or the user who has completed the review
* @type {GitHubUser}
* @memberOf GitHubReview
*/
user: GitHubUser
/**
* @type {number}
* @memberOf GitHubReview
*/
id?: number

/**
* The body of the review
* @type {string}
* @memberOf GitHubReview
*/
body?: string

/**
* The commit ID this review was made on
* @type {string}
* @memberOf GitHubReview
*/
commit_id?: string

/**
* The state of the review
* APPROVED, REQUEST_CHANGES, COMMENT or PENDING
* @type {string}
* @memberOf GitHubReview
*/
state?: string

}
11 changes: 8 additions & 3 deletions source/platforms/GitHub.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GitDSL } from "../dsl/GitDSL"
import { GitCommit } from "../dsl/Commit"
import { GitHubCommit, GitHubDSL, GitHubIssue, GitHubIssueLabel } from "../dsl/GitHubDSL"
import { GitHubPRDSL, GitHubCommit, GitHubDSL, GitHubIssue, GitHubIssueLabel } from "../dsl/GitHubDSL"
import { GitHubAPI } from "./github/GitHubAPI"

import * as parseDiff from "parse-diff"
Expand All @@ -23,9 +23,14 @@ export class GitHub {
*
* @returns {Promise<any>} JSON representation
*/
async getReviewInfo(): Promise<any> {
async getReviewInfo(): Promise<GitHubPRDSL> {
const deets = await this.api.getPullRequestInfo()
return await deets.json()

return {
...await deets.json(),
reviews: await this.api.getReviews(),
requestedReviewers: await this.api.getReviewerRequests(),
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ export class GitHubAPI {
return []
}

async getReviewerRequests(): Promise<any> {
const repo = this.ciSource.repoSlug
const prID = this.ciSource.pullRequestID
const res = await this.get(`repos/${repo}/pulls/${prID}/requested_reviewers`, {
accept: "application/vnd.github.black-cat-preview+json"
})
if (res.ok) {
return res.json()
}
return []
}

async getReviews(): Promise<any> {
const repo = this.ciSource.repoSlug
const prID = this.ciSource.pullRequestID
const res = await this.get(`repos/${repo}/pulls/${prID}/reviews`, {
accept: "application/vnd.github.black-cat-preview+json"
})
if (res.ok) {
return res.json()
}
return []
}

async getIssue(): Promise<any> {
const repo = this.ciSource.repoSlug
const prID = this.ciSource.pullRequestID
Expand Down

0 comments on commit 2ca1a92

Please sign in to comment.