Zomis / Duga

Stack Exchange Chat bot
18 stars 6 forks source link

Support Bitbucket Commit Events #107

Closed EBrown8534 closed 8 years ago

EBrown8534 commented 9 years ago

Duga should be able to support commit events from Bitbucket (can't be too much worse than GitHub).

Bitbucket supports webhooks in a similar to GitHub, and will post events to the specified URL with JSON data representing the event.

In the following example JSON, DRS is the name of the repository, MK11B is the team name, EBrown8534 is a username, and Elliott Brown is a first/last name of the user.

Example JSON:

{"actor": {
    "type": "user",
    "display_name": "Elliott Brown", 
    "username": "EBrown8534", 
    "uuid": "{2d3b7773-2fd8-4193-bebf-50bcdbedc4de}", 
    "links": {
        "self": {
            "href": "https://api.bitbucket.org/2.0/users/EBrown8534"}, 
            "avatar": {
                "href": "https://bitbucket.org/account/EBrown8534/avatar/32/"
            }, 
            "html": {
                "href": "https://bitbucket.org/EBrown8534/"
            }
        }
    },
    "push": {
        "changes": [
            {
                "forced": false, 
                "truncated": false, 
                "new": {
                    "type": "branch", 
                    "links": {
                        "commits": {
                            "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commits/master"
                        }, 
                        "self": {
                            "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/refs/branches/master"
                        }, 
                        "html": {
                            "href": "https://bitbucket.org/MK11B/drs/branch/master"
                        }
                    }, 
                    "name": "master", 
                    "target": {
                        "date": "2015-09-18T18:56:20+00:00", 
                        "hash": "b21217059cd0918d8f3dc72f1656befcb2aad57c", 
                        "links": {
                            "self": {
                                "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commit/b21217059cd0918d8f3dc72f1656befcb2aad57c"
                            }, 
                            "html": {
                                "href": "https://bitbucket.org/MK11B/drs/commits/b21217059cd0918d8f3dc72f1656befcb2aad57c"
                            }
                        },
                        "message": "Minor changes to `ReportsController`.\n",
                        "type": "commit", 
                        "parents": [
                            {
                                "type": "commit",
                                "hash": "243b48deda01b44892bf374cf0cbdeee5065d7ef",
                                "links": {
                                    "self": {
                                        "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commit/243b48deda01b44892bf374cf0cbdeee5065d7ef"
                                    },
                                    "html": {
                                        "href": "https://bitbucket.org/MK11B/drs/commits/243b48deda01b44892bf374cf0cbdeee5065d7ef"
                                    }
                                }
                            }
                        ],
                        "author": {
                            "raw": "EBrown8534 <ebrown8534@gmail.com>"
                        }
                    }
                },
                "links": {
                    "diff": {
                        "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/diff/b21217059cd0918d8f3dc72f1656befcb2aad57c..243b48deda01b44892bf374cf0cbdeee5065d7ef"
                    }, 
                    "commits": {
                        "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commits?include=b21217059cd0918d8f3dc72f1656befcb2aad57c&exclude=243b48deda01b44892bf374cf0cbdeee5065d7ef"
                    }, 
                    "html": {
                        "href": "https://bitbucket.org/MK11B/drs/branches/compare/b21217059cd0918d8f3dc72f1656befcb2aad57c..243b48deda01b44892bf374cf0cbdeee5065d7ef"
                    }
                },
                "old": {
                    "type": "branch", 
                    "links": {
                        "commits": {
                            "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commits/master"
                        },
                        "self": {
                            "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/refs/branches/master"
                        },
                        "html": {
                            "href": "https://bitbucket.org/MK11B/drs/branch/master"
                        }
                    },
                    "name": "master", 
                    "target": {
                        "date": "2015-09-18T18:03:28+00:00", 
                        "hash": "243b48deda01b44892bf374cf0cbdeee5065d7ef", 
                        "links": {
                            "self": {
                                "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commit/243b48deda01b44892bf374cf0cbdeee5065d7ef"
                            }, 
                            "html": {
                                "href": "https://bitbucket.org/MK11B/drs/commits/243b48deda01b44892bf374cf0cbdeee5065d7ef"
                            }
                        },
                        "message": "Test commit.\n",
                        "type": "commit",
                        "parents": [
                            {
                                "type": "commit", "hash": "dcaa62d79bed4828afabd878009646852efe482a",
                                "links": {
                                    "self": {
                                        "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commit/dcaa62d79bed4828afabd878009646852efe482a"
                                    }, 
                                    "html": {
                                        "href": "https://bitbucket.org/MK11B/drs/commits/dcaa62d79bed4828afabd878009646852efe482a"
                                    }
                                }
                            }
                        ],
                        "author": {
                            "raw": "EBrown8534 <ebrown8534@gmail.com>"
                        }
                    }
                }, 
                "commits": [
                    {
                        "type": "commit", 
                        "author": {
                            "raw": "EBrown8534 <ebrown8534@gmail.com>"
                        }, 
                        "hash": "b21217059cd0918d8f3dc72f1656befcb2aad57c", 
                        "links": {
                            "self": {
                                "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs/commit/b21217059cd0918d8f3dc72f1656befcb2aad57c"
                            }, 
                            "html": {
                                "href": "https://bitbucket.org/MK11B/drs/commits/b21217059cd0918d8f3dc72f1656befcb2aad57c"
                            }
                        }, 
                        "message": "Minor changes to `ReportsController`.\n"
                    }
                ], 
                "created": false, 
                "closed": false
            }
        ]
    }, 
    "repository": {
        "scm": "git", 
        "full_name": "MK11B/drs", 
        "uuid": "{cb743a28-1f79-4abe-baaa-7cbe11ced0d4}", 
        "links": {
            "self": {
                "href": "https://api.bitbucket.org/2.0/repositories/MK11B/drs"
            }, 
            "avatar": {
                "href": "https://bitbucket.org/MK11B/drs/avatar/16/"
            }, 
            "html": {
                "href": "https://bitbucket.org/MK11B/drs"
            }
        }, 
        "type": "repository", 
        "owner": {
            "type": "team", 
            "display_name": "Mark 11 Bravo", 
            "username": "MK11B", 
            "uuid": "{78e8ab51-33ab-4f5e-bee1-093247607506}", 
            "links": {
                "self": {
                    "href": "https://api.bitbucket.org/2.0/teams/MK11B"
                }, 
                "avatar": {
                    "href": "https://bitbucket.org/account/MK11B/avatar/32/"
                }, 
                "html": {
                    "href": "https://bitbucket.org/MK11B/"
                }
            }
        }, 
        "is_private": true, 
        "name": "DRS"
    }
}
Zomis commented 9 years ago

It is unlikely that I will implement this myself in the near future, so if anyone wants to make a PR, feel free to do so.

Zomis commented 8 years ago

As I now also use several bitbucket repos, this is really something I should give priority.

Zomis commented 8 years ago

This has now been implemented. URL to use is: http://stats.zomis.net/GithubHookSEChatService/hooks/bitbucket?roomId=xxxxx where xxxxx is the Stack Exchange Chat room id.