diff --git a/README.md b/README.md index a1cb443..59d24e3 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,34 @@ # skyhook + Parses webhooks and forwards them in the proper format to Discord. [![Discord](https://discordapp.com/api/guilds/303595820345851905/widget.png)](https://discord.gg/js7wD7p) ## Setup + You can use the [site](https://skyhookapi.com/) to create the right webhook link. If you want to manually do it, here are the steps: + 1. Create a webhook in Discord (Server Settings -> Webhooks -> Create Webhook) 2. Copy the webhook url 3. Turn the Discord webhook url into a skyhook webhook url like so: + ``` Replace discordapp.com in url with skyhookapi.com https://discordapp.com/api/webhooks/firstPartOfWebhook/secondPartOfWebhook -> https://skyhookapi.com/api/webhooks/firstPartOfWebhook/secondPartOfWebhook ``` + 4. Add the provider you want to the end of the url: + ``` https://skyhookapi.com/api/webhooks/firstPartOfWebhook/secondPartOfWebhook/providerGoesHere ``` + ## Supported Providers + - [AppVeyor](https://www.appveyor.com/docs/notifications/#webhook-payload-default) - `/appveyor` +- [Azure DevOps](https://docs.microsoft.com/en-us/azure/devops/service-hooks/services/webhooks?view=azure-devops) - `/azure-devops` - [Basecamp 3](https://github.com/basecamp/bc3-api/blob/master/sections/webhooks.md) - `/basecamp` - [BitBucket](https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html) - `/bitbucket` - [BitBucket Server](https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html) - `/bitbucketserver` @@ -45,38 +54,50 @@ If you want support for a new provider, just create a pull request and add it! Alternatively, a new provider can also be requested by creating an [issue](https://github.com/Commit451/skyhook/issues). ## Contributing + If you wish to contribute, follow our [contributing guide](CONTRIBUTING.md). ### Creating a Provider + If you want to create a new provider please follow the examples shown at our small [documentation](docs/CreateNewProvider.md). ## Testing Locally + To build: + ``` npm run build ``` + To run server (after building): + ``` npm start ``` + To run tests: + ``` npm test ``` Through Docker: + ``` docker run -it --rm -p 8080:8080 commit451/skyhook ``` ## Deploying + - [Docker](docs/docker) - [Google Cloud](docs/gcloud) ## Thanks + Special thanks to all our amazing contributors. skyhookapi.com is hosted for free for you, so if you feel so inclined, [buy a coffee!](https://ko-fi.com/jawnnypoo) ## License + skyhook is available under the MIT license. See the LICENSE file for more info. -\ ゜o゜)ノ +\ ゜ o ゜)ノ diff --git a/src/index.ts b/src/index.ts index 087ac82..6a2479a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,7 @@ import { Unity } from './provider/Unity' import { UptimeRobot } from './provider/UptimeRobot' import { VSTS } from './provider/VSTS' import { Type } from './util/TSUtility' +import { AzureDevops } from './provider/AzureDevops' dotenv.config() @@ -44,6 +45,7 @@ const app = express() */ const providers: Type[] = [ AppVeyor, + AzureDevops, Basecamp, BitBucket, BitBucketServer, @@ -147,7 +149,7 @@ app.post('/api/webhooks/:webhookID/:webhookSecret/:from', async (req, res) => { if (discordPayload != null) { // We could implement a more robust validation on this at some point. - if(Object.keys(discordPayload).length === 0) { + if (Object.keys(discordPayload).length === 0) { logger.error('Bad implementation, outbound payload is empty.') res.status(500).send('Bad implementation.') return diff --git a/src/provider/AzureDevops.ts b/src/provider/AzureDevops.ts new file mode 100644 index 0000000..1e9e2d8 --- /dev/null +++ b/src/provider/AzureDevops.ts @@ -0,0 +1,42 @@ +import { Embed, EmbedField, EmbedAuthor } from '../model/DiscordApi' +import { TypeParseProvder } from './BaseProvider' + +export class AzureDevops extends TypeParseProvder { + + private embed: Embed + + constructor() { + super() + this.setEmbedColor(0x205081) + this.embed = {} + } + + public getName(): string { + return 'Azure-DevOps' + } + + public getType(): string | null { + return this.body.eventType + } + + public knownTypes(): string[] { + return ['gitPush'] + } + + public async gitPush(): Promise { + this.logger.debug('Parsing git push event') + this.embed.title = this.body.message.markdown + this.embed.description = this.body.detailedMessage.markdown + this.embed.url = this.body.resource.repository.url + + this.embed.author = this.extractAuthor() + + this.addEmbed(this.embed) + } + + public extractAuthor(): EmbedAuthor { + return { + name: this.body.resource.pushedBy.displayName, + } + } +} \ No newline at end of file diff --git a/test/azure-devops/azure-devops-spec.ts b/test/azure-devops/azure-devops-spec.ts new file mode 100644 index 0000000..70b096d --- /dev/null +++ b/test/azure-devops/azure-devops-spec.ts @@ -0,0 +1,11 @@ +import { expect } from 'chai' +import { AzureDevops } from '../../src/provider/AzureDevops' +import { Tester } from '../Tester' + +describe('/POST azure-devops', () => { + it('should build', async () => { + const res = await Tester.test(new AzureDevops(), 'azure-devops.json', null) + expect(res).to.not.be.null + expect(res!.embeds).to.be.an('array').that.has.length(1) + }) +}) \ No newline at end of file diff --git a/test/azure-devops/azure-devops.json b/test/azure-devops/azure-devops.json new file mode 100644 index 0000000..696a6c5 --- /dev/null +++ b/test/azure-devops/azure-devops.json @@ -0,0 +1,79 @@ +{ + "subscriptionId": "00000000-0000-0000-0000-000000000000", + "notificationId": 3, + "id": "03c164c2-8912-4d5e-8009-3707d5f83734", + "eventType": "git.push", + "publisherId": "tfs", + "message": { + "text": "Jamal Hartnett pushed updates to Fabrikam-Fiber-Git:master.", + "html": "Jamal Hartnett pushed updates to Fabrikam-Fiber-Git:master.", + "markdown": "Jamal Hartnett pushed updates to `Fabrikam-Fiber-Git`:`master`." + }, + "detailedMessage": { + "text": "Jamal Hartnett pushed a commit to Fabrikam-Fiber-Git:master.\n - Fixed bug in web.config file 33b55f7c", + "html": "Jamal Hartnett pushed a commit to Fabrikam-Fiber-Git:master.\n", + "markdown": "Jamal Hartnett pushed a commit to [Fabrikam-Fiber-Git](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/):[master](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster).\n* Fixed bug in web.config file [33b55f7c](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74)" + }, + "resource": { + "commits": [ + { + "commitId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74", + "author": { + "name": "Jamal Hartnett", + "email": "fabrikamfiber4@hotmail.com", + "date": "2015-02-25T19:01:00Z" + }, + "committer": { + "name": "Jamal Hartnett", + "email": "fabrikamfiber4@hotmail.com", + "date": "2015-02-25T19:01:00Z" + }, + "comment": "Fixed bug in web.config file", + "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74" + } + ], + "refUpdates": [ + { + "name": "refs/heads/master", + "oldObjectId": "aad331d8d3b131fa9ae03cf5e53965b51942618a", + "newObjectId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74" + } + ], + "repository": { + "id": "278d5cd2-584d-4b63-824a-2ba458937249", + "name": "Fabrikam-Fiber-Git", + "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249", + "project": { + "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "name": "Fabrikam-Fiber-Git", + "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "state": "wellFormed", + "visibility": "unchanged", + "lastUpdateTime": "0001-01-01T00:00:00" + }, + "defaultBranch": "refs/heads/master", + "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git" + }, + "pushedBy": { + "displayName": "Jamal Hartnett", + "id": "00067FFED5C7AF52@Live.com", + "uniqueName": "fabrikamfiber4@hotmail.com" + }, + "pushId": 14, + "date": "2014-05-02T19:17:13.3309587Z", + "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/pushes/14" + }, + "resourceVersion": "1.0", + "resourceContainers": { + "collection": { + "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2" + }, + "account": { + "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e" + }, + "project": { + "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f" + } + }, + "createdDate": "2021-10-17T02:10:46.3292927Z" +} \ No newline at end of file