Skip to content

Commit

Permalink
Introduce a type for GitHub issue comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cysp committed Dec 27, 2018
1 parent 0eb5b4c commit dbc9615
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
17 changes: 17 additions & 0 deletions source/dsl/GitHubDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ export interface GitHubIssueLabel {
color: string
}

export interface GitHubIssueComment {
/**
* UUID for the comment
*/
id: string

/**
* The User who made the comment
*/
user: GitHubUser

/**
* Textual representation of comment
*/
body: string
}

// This is `danger.github.pr`

/**
Expand Down
17 changes: 8 additions & 9 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import * as node_fetch from "node-fetch"
import parse from "parse-link-header"
import pLimit from "p-limit"

import { GitHubPRDSL, GitHubUser } from "../../dsl/GitHubDSL"
import { GitHubPRDSL, GitHubIssueComment, GitHubUser } from "../../dsl/GitHubDSL"

import { dangerIDToString } from "../../runner/templates/githubIssueTemplate"
import { api as fetch } from "../../api/fetch"
import { Comment } from "../platform"
import { RepoMetaData } from "../../dsl/BitBucketServerDSL"
import { CheckOptions } from "./comms/checks/resultsToCheck"

Expand Down Expand Up @@ -85,7 +84,7 @@ export class GitHubAPI {

getDangerCommentIDs = async (dangerID: string): Promise<string[]> => {
const userID = await this.getUserID()
const allComments: any[] = await this.getPullRequestComments()
const allComments = await this.getPullRequestComments()
const dangerIDMessage = dangerIDToString(dangerID)
this.d(`User ID: ${userID}`)
this.d(`Looking at ${allComments.length} comments for ${dangerIDMessage}`)
Expand Down Expand Up @@ -274,23 +273,23 @@ export class GitHubAPI {
return response.json()
}

getPullRequestComments = async (): Promise<any[]> => {
getPullRequestComments = async (): Promise<GitHubIssueComment[]> => {
const repo = this.repoMetadata.repoSlug
const prID = this.repoMetadata.pullRequestID
return await this.getAllOfResource(`repos/${repo}/issues/${prID}/comments`)
}

getPullRequestInlineComments = async (dangerID: string): Promise<Comment[]> => {
getPullRequestInlineComments = async (dangerID: string): Promise<(GitHubIssueComment & { ownedByDanger: boolean })[]> => {
const userID = await this.getUserID()
const repo = this.repoMetadata.repoSlug
const prID = this.repoMetadata.pullRequestID
return await this.getAllOfResource(`repos/${repo}/pulls/${prID}/comments`).then(v => {
return await this.getAllOfResource(`repos/${repo}/pulls/${prID}/comments`).then((v: GitHubIssueComment[]) => {
return v
.filter(Boolean)
.map((i: any) => {
return { id: i.id, ownedByDanger: i.user.id == userID && i.body.includes(dangerID), body: i.body }
.map(i => {
return { ...i, ownedByDanger: i.user.id == userID && i.body.includes(dangerID) }
})
.filter((i: any) => i.ownedByDanger)
.filter(i => i.ownedByDanger)
})
}

Expand Down

0 comments on commit dbc9615

Please sign in to comment.