Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basecamp 3 provider #180

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ https://skyhookapi.com/api/webhooks/firstPartOfWebhook/secondPartOfWebhook/provi
```
## Supported Providers
- [AppVeyor](https://www.appveyor.com/docs/notifications/#webhook-payload-default) - `/appveyor`
- [Basecamp 3](https://github.com/basecamp/bc3-api/blob/master/sections/webhooks.md) - `/basecamp`
- [Bintray](https://bintray.com/docs/api/#_webhooks) - `/bintray`
- [BitBucket](https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html) - `/bitbucket`
- [BitBucket Server](https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html) - `/bitbucketserver`
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"express": "^4.17.1",
"gravatar": "^1.8.1",
"luxon": "^1.25.0",
"turndown": "^7.1.1",
"winston": "^3.3.3"
},
"engines": {
Expand All @@ -58,4 +59,4 @@
"skyhook",
"discord"
]
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ErrorUtil } from './util/ErrorUtil'
import { LoggerUtil } from './util/LoggerUtil'

import { AppVeyor } from './provider/Appveyor'
import { Basecamp } from './provider/Basecamp'
import { Bintray } from './provider/Bintray'
import { BitBucket } from './provider/Bitbucket'
import { BitBucketServer } from './provider/BitBucketServer'
Expand Down Expand Up @@ -43,6 +44,7 @@ const app = express()
*/
const providers = [
AppVeyor,
Basecamp,
Bintray,
BitBucket,
BitBucketServer,
Expand Down
215 changes: 215 additions & 0 deletions src/provider/Basecamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import {Embed} from '../model/Embed'
import {BaseProvider} from '../provider/BaseProvider'
import * as fs from 'fs'
import {EmbedAuthor} from '../model/EmbedAuthor'

import TurndownService from 'turndown'

class Basecamp extends BaseProvider {
private turndown: TurndownService
private colorCreated = 0x00ff00
private colorDeleted = 0xff0000
private colorArchived = 0x8b0000
private colorUnarchived = 0x66cdaa
private colorEdited = 0x40e0d0

constructor() {
super()
this.turndown = new TurndownService()
}

public getName(): string {
return 'Basecamp'
}

public getPath(): string {
return 'basecamp'
}

public async parseData(): Promise<void> {
// console.log(this.body)
// fs.appendFile('bc.json', JSON.stringify(this.body) + '\n\n', function (err) {
// if (err) {
// return console.log(err)
// }
// })
//let embed: Embed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these commented out bits please?

switch (this.body.kind) {
case 'comment_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted comment', ['title'], true)
break
case 'comment_created':
this.prepareEmbed(this.colorCreated, 'added comment', ['title'], true)
break
case 'todo_created':
this.prepareEmbed(this.colorCreated, 'created todo', ['title'])
break
case 'todo_completed':
this.prepareEmbed(0x4ca3dd, 'completed todo', ['title'])
break
case 'todo_archived':
this.prepareEmbed(this.colorArchived, 'archived todo', ['title'])
break
case 'todo_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived todo', ['title'])
break
case 'todo_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted todo', ['title'])
break
case 'comment_content_changed':
this.prepareEmbed(this.colorEdited, 'changed comment', ['title'], true)
break
case 'todolist_description_changed':
this.prepareEmbed(this.colorEdited, 'changed todolist\'s description', ['title'], true)
break
case 'todolist_created':
this.prepareEmbed(this.colorCreated, 'created todolist', ['title'], true)
break
case 'todolist_archived':
this.prepareEmbed(this.colorArchived, 'archived todolist', ['title'])
break
case 'todolist_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived todolist', ['title'])
break
case 'todolist_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted todolist', ['title'])
break
case 'message_created':
case 'message_active':
this.prepareEmbed(this.colorCreated, 'published message', ['title'], true)
break
case 'message_archived':
this.prepareEmbed(this.colorArchived, 'archived message', ['title'], true)
break
case 'message_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived message', ['title'], true)
break
case 'message_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted message', ['title'], true)
break
case 'comment_archived':
this.prepareEmbed(this.colorArchived, 'archived comment', ['title'], true)
break
case 'comment_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived comment', ['title'], true)
break
case 'vault_created':
this.prepareEmbed(this.colorCreated, 'created doc\'s folder', ['title'],)
break
case 'vault_copied':
this.prepareEmbed(this.colorCreated, 'copied doc\'s folder', ['title'],)
break
case 'vault_inserted':
this.prepareEmbed(this.colorCreated, 'added doc\'s folder', ['title'],)
break
case 'vault_title_changed':
this.prepareEmbed(this.colorEdited, 'changed folder\'s title', ['title'],)
break
case 'vault_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted folder', ['title'], true)
break
case 'vault_archived':
this.prepareEmbed(this.colorArchived, 'archived folder', ['title'], true)
break
case 'vault_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived folder', ['title'], true)
break
case 'upload_created':
case 'upload_active':
this.prepareEmbed(this.colorCreated, 'uploaded file', ['title'], true)
break
case 'upload_copied':
this.prepareEmbed(this.colorCreated, 'copied file', ['title'], true)
break
case 'upload_inserted':
this.prepareEmbed(this.colorCreated, 'added file', ['title'], true)
break
case 'upload_archived':
this.prepareEmbed(this.colorArchived, 'archived file', ['title'], true)
break
case 'upload_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived file', ['title'], true)
break
case 'upload_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted file', ['title'], true)
break
case 'document_created':
case 'document_active':
this.prepareEmbed(this.colorCreated, 'created document', ['title'], true)
break
case 'document_copied':
this.prepareEmbed(this.colorCreated, 'copied document', ['title'], true)
break
case 'document_inserted':
this.prepareEmbed(this.colorCreated, 'added document', ['title'], true)
break
case 'document_archived':
this.prepareEmbed(this.colorArchived, 'archived document', ['title'], true)
break
case 'document_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived document', ['title'], true)
break
case 'document_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted document', ['title'], true)
break
case 'google_document_created':
case 'google_document_active':
this.prepareEmbed(this.colorCreated, 'created Google Document', ['title'], true)
break
case 'google_document_copied':
this.prepareEmbed(this.colorCreated, 'copied Google Document', ['title'], true)
break
case 'google_document_inserted':
this.prepareEmbed(this.colorCreated, 'added Google Document', ['title'], true)
break
case 'google_document_archived':
this.prepareEmbed(this.colorArchived, 'archived Google Document', ['title'], true)
break
case 'google_document_unarchived':
this.prepareEmbed(this.colorUnarchived, 'unarchived Google Document', ['title'], true)
break
case 'google_document_trashed':
this.prepareEmbed(this.colorDeleted, 'deleted Google Document', ['title'], true)
break
default:
console.log('unknown event ' + this.body.kind)
this.prepareEmbed(0xf0ff00, this.body.kind, ['title', 'type'], true)
break
}
}

private escapeString(str: string): string {
if (!str) {
return ''
}
return this.turndown.turndown(str)
}

private prepareEmbed(color: number, title: string, fields: Array<string> = [], content = false): Embed {
const embed = new Embed()
embed.url = this.body.recording.app_url
embed.color = color
embed.title = `${title} on ${this.body.recording.bucket.name} / ${this.body.recording.parent.type} : ${this.body.recording.parent.title}`
embed.author = new EmbedAuthor()
embed.author.name = this.body.recording.creator.name
embed.author.icon_url = this.body.recording.creator.avatar_url
if (content) {
embed.description = this.escapeString(this.body.recording.content).substring(0, 4096)
}
embed.fields = []
const body = this.body
fields.forEach(function (field) {
switch (field) {
case 'title':
embed.fields.push({name: 'Title', value: body.recording.title, inline: true})
break
case 'type':
embed.fields.push({name: 'Type', value: body.recording.type, inline: true})
}
})
this.addEmbed(embed)
return embed
}
}

export {Basecamp}