Skip to content

Commit

Permalink
Migrate comment functionality in server (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianruesch authored Nov 21, 2023
1 parent 3fbd87d commit e06f3c3
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions electron/providers/jira-server-provider/JiraServerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,19 +678,69 @@ export class JiraServerProvider implements IProvider {
}

addCommentToIssue(issueIdOrKey: string, commentText: string): Promise<void> {
throw new Error("Method not implemented for Jira Server")
return new Promise((resolve, reject) => {
this.getRestApiClient(2)
.post(
`/issue/${issueIdOrKey}/comment`,
{ body: commentText.replace(/\n/g, " ") }
)
.then(() => resolve())
.catch((error) => {
reject(new Error(`Error adding a comment to the issue ${issueIdOrKey}: ${error}`))
})
})
}

editIssueComment(
issueIdOrKey: string,
commentId: string,
commentText: string
): Promise<void> {
throw new Error("Method not implemented for Jira Server")
return new Promise((resolve, reject) =>{
// main part
this.getRestApiClient(2)
.put(
`/issue/${issueIdOrKey}/comment/${commentId}`,
{ body: commentText.replace(/\n/g, " ") }
)
.then(() => { resolve() })
.catch((error) => {
if (error.response) {
if (error.response.status === 400) {
return Promise.reject(new Error("The user does not have permission to edit the comment or the request is invalid"))
} if (error.response.status === 404) {
return Promise.reject(new Error("The issue was not found or the user does not have the necessary permissions"))
}
}

return Promise.reject(error)
})
.catch((error) => {
reject(Error(`Error editing the comment in issue ${issueIdOrKey}: ${error}`))
})
})
}

deleteIssueComment(issueIdOrKey: string, commentId: string): Promise<void> {
throw new Error("Method not implemented for Jira Server")
return new Promise((resolve, reject) => {
this.getRestApiClient(2)
.delete(`/issue/${issueIdOrKey}/comment/${commentId}`)
.then(() => { resolve() })
.catch((error) => {
if (error.response) {
if (error.response.status === 404) {
return Promise.reject(new Error("The issue was not found or the user does not have the necessary permissions"))
} if (error.response.status === 405) {
return Promise.reject(new Error("An anonymous call has been made to the operation"))
}
}

return Promise.reject(new Error(`Error deleting the comment in issue ${issueIdOrKey}: ${error}`))
})
.catch((error) => {
reject(Error(`Error deleting the comment in issue ${issueIdOrKey}: ${error}`))
})
})
}

refreshAccessToken(): Promise<void> {
Expand Down

0 comments on commit e06f3c3

Please sign in to comment.