Skip to content

Commit

Permalink
Add createInlineComment to API & platform
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinejr committed Feb 25, 2018
1 parent 127fa2d commit 38ba779
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/platforms/FakePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class FakePlatform implements Platform {
return true
}

async createInlineComment(_comment: string, _commitId: string, _path: string, _position: number): Promise<any> {
return true
}

async deleteMainComment(): Promise<boolean> {
return true
}
Expand Down
12 changes: 12 additions & 0 deletions source/platforms/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ export class GitHub {
*/
createComment = (comment: string) => this.api.postPRComment(comment)

/**
* Returns the response for the new inline comment
*
* @param {string} comment you want to post
* @param {string} commitId to make a comment in
* @param {string} path to the file
* @param {number} position in the file
* @returns {Promise<any>} JSON response of new comment
*/
createInlineComment = (comment: string, commitId: string, path: string, position: number) =>
this.api.postInlinePRComment(comment, commitId, path, position)

// In Danger RB we support a danger_id property,
// this should be handled at some point

Expand Down
4 changes: 4 additions & 0 deletions source/platforms/LocalGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export class LocalGit implements Platform {
return true
}

async createInlineComment(_comment: string, _commitId: string, _path: string, _position: number): Promise<any> {
return true
}

async deleteMainComment(): Promise<boolean> {
return true
}
Expand Down
17 changes: 17 additions & 0 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ export class GitHubAPI {
return res.json()
}

postInlinePRComment = async (comment: string, commitId: string, path: string, position: number) => {
const repo = this.repoMetadata.repoSlug
const prID = this.repoMetadata.pullRequestID
const res = await this.post(
`repos/${repo}/issues/${prID}/comments`,
{},
{
body: comment,
commit_id: commitId,
path: path,
position: position,
}
)

return res.json()
}

getPullRequestInfo = async (): Promise<GitHubPRDSL> => {
if (this.pr) {
return this.pr
Expand Down
2 changes: 2 additions & 0 deletions source/platforms/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export interface Platform {
supportsCommenting: () => boolean
/** Creates a comment on the PR */
createComment: (dangerID: string, body: string) => Promise<any>
/** Creates an inline comment on the PR */
createInlineComment: (comment: string, commitId: string, path: string, position: number) => Promise<any>
/** Delete the main Danger comment */
deleteMainComment: (dangerID: string) => Promise<boolean>
/** Replace the main Danger comment */
Expand Down

0 comments on commit 38ba779

Please sign in to comment.