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

New Provider: Azure DevOps #187

Closed
wants to merge 4 commits into from
Closed
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
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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 ゜)ノ
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -44,6 +45,7 @@ const app = express()
*/
const providers: Type<BaseProvider>[] = [
AppVeyor,
AzureDevops,
Basecamp,
BitBucket,
BitBucketServer,
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions src/provider/AzureDevops.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
this.logger.debug('Parsing git push event')
this.embed.title = this.body.message.markdown
Copy link

Choose a reason for hiding this comment

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

You can't use markdown in the title of an embed. You should use this.body.message.text instead.

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,
}
}
}
11 changes: 11 additions & 0 deletions test/azure-devops/azure-devops-spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
79 changes: 79 additions & 0 deletions test/azure-devops/azure-devops.json
Original file line number Diff line number Diff line change
@@ -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 <a href=\"https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/\">Fabrikam-Fiber-Git</a>:<a href=\"https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster\">master</a>.\n<ul>\n<li>Fixed bug in web.config file <a href=\"https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74\">33b55f7c</a>\n</ul>",
"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": "[email protected]",
"date": "2015-02-25T19:01:00Z"
},
"committer": {
"name": "Jamal Hartnett",
"email": "[email protected]",
"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": "[email protected]",
"uniqueName": "[email protected]"
},
"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"
}