Skip to content

Commit

Permalink
feat(api-github-v3): delete reaction if already token
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Jan 2, 2020
1 parent 9e28bb8 commit 33ecf23
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/@vssue/api-github-v3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,38 @@ export default class GithubV3 implements VssueAPI.Instance {
'Accept': 'application/vnd.github.squirrel-girl-preview',
},
})

// 200 OK if the reaction is already token
if (response.status === 200) {
return this.deleteCommentReaction({
accessToken,
reactionId: response.data.id,
})
}

// 201 CREATED
return response.status === 201
}

/**
* Delete a reaction of a comment
*
* @see https://developer.github.com/v3/reactions/#delete-a-reaction
*/
async deleteCommentReaction ({
accessToken,
reactionId,
}: {
accessToken: VssueAPI.AccessToken
reactionId: string | number
}): Promise<boolean> {
const response = await this.$http.delete(
`reactions/${reactionId}`, {
headers: {
'Authorization': `token ${accessToken}`,
'Accept': 'application/vnd.github.squirrel-girl-preview',
},
})
return response.status === 204
}
}

0 comments on commit 33ecf23

Please sign in to comment.