Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 49a8cc3

Browse files
committed
Removing broken Travis webhook integration
- Fixed incorrect instructions in the readme. - Added more explanations and example config for Travis & Appveyor, which most users will likely need. Fixes #60.
1 parent 39c40e0 commit 49a8cc3

File tree

3 files changed

+114
-149
lines changed

3 files changed

+114
-149
lines changed

README.md

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
[![Hommando]][Akemi Homura]
44

55
Homu is a bot that integrates with GitHub and your favorite continuous
6-
integration service, such as [Buildbot] or [Travis CI].
6+
integration service such as [Travis CI], [Appveyor] or [Buildbot].
77

88
[Hommando]: https://i.imgur.com/j0jNvHF.png
99
[Akemi Homura]: https://wiki.puella-magi.net/Homura_Akemi
1010
[Buildbot]: http://buildbot.net/
1111
[Travis CI]: https://travis-ci.org/
12+
[Appveyor]: https://www.appveyor.com/
1213

1314
## Why is it needed?
1415

@@ -31,8 +32,9 @@ approval comment from one of the configured reviewers. When the pull request is
3132
approved, Homu tests it using your favorite continuous integration service, and
3233
only when it passes all the tests, it is merged into `master`.
3334

34-
Note that Homu is **not** a replacement of Travis CI or Buildbot. It works on
35-
top of them. Homu itself doesn't have the ability to test pull requests.
35+
Note that Homu is **not** a replacement of Travis CI, Buildbot or Appveyor. It
36+
works on top of them. Homu itself doesn't have the ability to test pull
37+
requests.
3638

3739
## Influences of bors
3840

@@ -50,8 +52,8 @@ before the merge" came from bors. However, there are also some differences:
5052
feature. This approach improves the overall performance and the response
5153
time, because the bot is informed about the status changes immediately.
5254

53-
And also, Homu has more features, such as `rollup`, `try`, and the Travis CI
54-
support.
55+
And also, Homu has more features, such as `rollup`, `try`, and the Travis CI &
56+
Appveyor support.
5557

5658
[bors]: https://github.com/graydon/bors
5759
[Webhooks]: https://developer.github.com/webhooks/
@@ -62,74 +64,71 @@ support.
6264
### How to install
6365

6466
```sh
65-
sudo apt-get install python3-venv
66-
67-
pyvenv .venv
68-
. .venv/bin/activate
69-
70-
# Stable version
71-
72-
pip install homu
73-
74-
# Development version
75-
76-
git clone https://github.com/barosl/homu.git
77-
pip install -e homu
67+
$ sudo apt-get install python3-venv
68+
$ pyvenv .venv
69+
$ . .venv/bin/activate
70+
$ git clone https://github.com/servo/homu.git
71+
$ pip install -e homu
7872
```
7973

8074
### How to configure
8175

82-
1. Copy `cfg.sample.toml` to `cfg.toml`, and edit it accordingly.
83-
84-
2. Create a GitHub account that will be used by Homu. You can also use an
85-
existing account. In the [account settings][settings], register a new
86-
application and generate a new access token (with the `repo` permission).
87-
The OAuth Callback URL should be `http://HOST:PORT/callback`, the homepage URL
88-
isn't needed and can be anything, for example `http://HOST:PORT/`.
89-
90-
3. Add a Webhook to your repository:
91-
92-
- Payload URL: `http://HOST:PORT/github`
93-
- Content type: `application/json`
94-
- Secret: The same as `repo.NAME.github.secret` in cfg.toml
95-
- Events: `Issue Comment`, `Pull Request`, `Push`, `Status`
76+
In the following instructions, `HOST` refers to the hostname (or IP address)
77+
where you are running your custom homu instance. `PORT` is the port the service
78+
is listening to and is configured in `web.port` in `cfg.toml`. `NAME` refers to
79+
the name of the repository you are configuring homu for.
9680

97-
4. Add a Webhook to your continuous integration service:
81+
1. Copy `cfg.sample.toml` to `cfg.toml`. You'll need to edit this file to set up
82+
your configuration. The following steps explain where you can find important
83+
config values.
9884

99-
- Buildbot
100-
101-
Insert the following code to the `master.cfg` file:
102-
103-
```python
104-
from buildbot.status.status_push import HttpStatusPush
105-
106-
c['status'].append(HttpStatusPush(
85+
2. Create a GitHub account that will be used by Homu. You can also use an
86+
existing account. In the [account settings][settings], go to "OAuth
87+
applications" and create a new application:
88+
- Make note of the "Client ID" and "Client Secret"; you will need to put them in
89+
your `cgf.toml`.
90+
- The OAuth Callback URL should be `http://HOST:PORT/callback`.
91+
- The homepage URL isn't necessary; you could set `http://HOST:PORT/`.
92+
93+
3. Go to the user settings of the GitHub account you created/used in the
94+
previous step. Go to "Personal access tokens". Click "Generate new token" and
95+
choose the "repo" and "user" scopes. Put the token value in your `cfg.toml`.
96+
97+
4. Add your new GitHub account as a Collaborator to the GitHub repo you are
98+
setting up homu for. This can be done in repo (NOT user) "Settings", then
99+
"Collaborators".
100+
101+
5. Add a Webhook to your repository. This is done under repo (NOT user)
102+
"Settings", then "Webhooks". Click "Add webhook", the set:
103+
- Payload URL: `http://HOST:PORT/github`
104+
- Content type: `application/json`
105+
- Secret: The same as `repo.NAME.github.secret` in `cfg.toml`
106+
- Events: `Issue Comment`, `Pull Request`, `Push`, `Status`
107+
108+
6. Add a Webhook to your continuous integration service, if necessary. You don't
109+
need this if using Travis/Appveyor.
110+
- Buildbot
111+
112+
Insert the following code to the `master.cfg` file:
113+
114+
```python
115+
from buildbot.status.status_push import HttpStatusPush
116+
117+
c['status'].append(HttpStatusPush(
107118
serverUrl='http://HOST:PORT/buildbot',
108119
extra_post_params={'secret': 'repo.NAME.buildbot.secret in cfg.toml'},
109-
))
110-
```
120+
))
121+
```
111122

112-
- Travis CI
113-
114-
Add [your Travis token][travis] as `repo.NAME.travis.token` in cfg.toml.
115-
Insert the following code to the `.travis.yml` file:
116-
117-
```yaml
118-
notifications:
119-
webhooks: http://HOST:PORT/travis
120-
121-
branches:
122-
only:
123-
- auto
124-
```
123+
7. Go through the rest of your `cfg.toml` and uncomment (and change, if needed)
124+
parts of the config you'll need.
125125

126126
[settings]: https://github.com/settings/applications
127127
[travis]: https://travis-ci.org/profile/info
128128

129129
### How to run
130130

131131
```sh
132-
. .venv/bin/activate
133-
134-
homu
132+
$ . .venv/bin/activate
133+
$ homu
135134
```

cfg.sample.toml

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Information for securely interacting with GitHub. These are found/generated
44
# under <https://github.com/settings/applications>.
55

6-
# A GitHub personal access token
6+
# A GitHub personal access token.
77
access_token = ""
88

99
# A GitHub oauth application for this instance of homu:
@@ -16,28 +16,29 @@ max_priority = 9001
1616
[git]
1717

1818
# Use the local Git command. Required to use some advanced features. It also
19-
# speeds up Travis by reducing temporary commits
19+
# speeds up Travis by reducing temporary commits.
2020
#local_git = false
2121

22-
# SSH private key. Needed only when the local Git command is used
22+
# SSH private key. Needed only when the local Git command is used.
2323
#ssh_key = """
2424
#"""
2525

26-
# By default, Homu extracts the name+email from the Github account. However,
27-
# you may want to use a private email for the account, and associate the commits
28-
# with a public email address.
26+
# By default, Homu extracts the name+email from the Github account it will be
27+
# using. However, you may want to use a private email for the account, and
28+
# associate the commits with a public email address.
2929
#user = "Some Cool Project Bot"
3030
#email = "coolprojectbot-devel@example.com"
3131

3232
[web]
3333

34-
# The port homu listens on
34+
# The port homu listens on.
3535
port = 54856
3636

37-
# Synchronize all open PRs on startup
38-
#sync_on_start = false
37+
# Synchronize all open PRs on startup. "Synchronize" means fetch the state of
38+
# all open PRs.
39+
sync_on_start = true
3940

40-
# Custom hooks can be added as well
41+
# Custom hooks can be added as well.
4142
# Homu will ping the given endpoint with POSTdata of the form:
4243
# {'body': 'comment body', 'extra_data': 'extra data', 'pull': pull req number}
4344
# The extra data is the text specified in `@homu hookname=text`
@@ -49,46 +50,74 @@ port = 54856
4950
# has_response = true # Should the response be posted back to github? Only allowed if realtime=true
5051
# realtime = true # Should it only run in realtime mode? If false, this will be replayed each time homu is started (probably not what you want)
5152

52-
# An example configuration for repository (there can be many of these)
53+
# An example configuration for repository (there can be many of these). NAME
54+
# refers to your repo name.
5355
[repo.NAME]
5456

55-
# github.com/<owner>/<name>
57+
# Which repo are we talking about? You can get these fields from your repo URL:
58+
# github.com/<owner>/<name>
5659
owner = ""
5760
name = ""
5861

59-
# who has r+ rights?
60-
reviewers = ["barosl", "graydon"]
61-
# Alternatively, set this to allow any github collaborator;
62+
# Who can approve PRs (r+ rights)? You can put GitHub usernames here.
63+
reviewers = []
64+
# Alternatively, set this allow any github collaborator;
6265
# note that you can *also* specify reviewers above.
6366
# auth_collaborators = true
6467

65-
# who has 'try' rights? (try, retry, force, clean, prioritization)
68+
# Who has 'try' rights? (try, retry, force, clean, prioritization). It's fine to
69+
# keep this empty.
6670
try_users = []
6771

68-
# Keep the commit history linear. Requires the local Git command
72+
# Keep the commit history linear. Requires the local Git command.
6973
#linear = false
7074

71-
# Auto-squash commits. Requires the local Git command
75+
# Auto-squash commits. Requires the local Git command.
7276
#autosquash = true
7377

74-
# If the PR already has the same success statuses that we expect on the auto
78+
# If the PR already has the same success statuses that we expect on the `auto`
7579
# branch, then push directly to branch if safe to do so. Requires the local Git
7680
# command.
7781
#status_based_exemption = false
7882

79-
## branch names (these settings here are the defaults)
83+
# Branch names. These settings are the defaults; it makes sense to leave these
84+
# as-is.
8085
#[repo.NAME.branch]
8186
#
8287
#auto = "auto"
8388
#try = "try"
8489
#rollup = "rollup"
8590

8691
[repo.NAME.github]
87-
88-
# arbitrary secret (e.g. openssl rand -hex 20)
92+
# Arbitrary secret. You can generate one with: openssl rand -hex 20
8993
secret = ""
9094

91-
## Use buildbot for running tests
95+
# Travis integration. Don't forget to allow Travis to test the `auto` branch!
96+
[repo.NAME.status.travis]
97+
# String label set by status updates. Don't touch this unless you really know
98+
# what you're doing.
99+
context = 'continuous-integration/travis-ci/push'
100+
101+
# Appveyor integration. Don't forget to allow Appveyor to test the `auto` branch!
102+
#[repo.NAME.status.appveyor]
103+
#
104+
# String label set by status updates. Don't touch this unless you really know
105+
# what you're doing.
106+
#context = 'continuous-integration/appveyor/branch'
107+
108+
# Generic GitHub Status API support. You don't need this if you're using the
109+
# above examples for Travis/Appveyor.
110+
#[repo.NAME.status.LABEL]
111+
#
112+
# String label set by status updates.
113+
#context = ""
114+
#
115+
# Equivalent context to look for on the PR itself if checking whether the
116+
# build should be exempted. If omitted, looks for the same context. This is
117+
# only used if status_based_exemption is true.
118+
#pr_context = ""
119+
120+
# Use buildbot for running tests
92121
#[repo.NAME.buildbot]
93122
#
94123
#url = ""
@@ -100,28 +129,11 @@ secret = ""
100129
#username = ""
101130
#password = ""
102131

103-
## Use travis for running tests
104-
#[repo.NAME.travis]
105-
#
106-
## found under <https://travis-ci.org/profile/info>.
107-
#token = ""
108-
109-
## Use the Status API
110-
#[repo.NAME.status.LABEL]
111-
#
112-
## String label set by status updates
113-
#context = ""
114132
#
115133
## Boolean which indicates whether the builder is included in try builds (defaults to true)
116134
#try = false
117-
#
118-
## Equivalent context to look for on the PR itself if checking whether the
119-
## build should be exempted. If omitted, looks for the same context. This is
120-
## only used if status_based_exemption is true.
121-
#pr_context = ""
122135

123-
## The database homu uses
124-
#[db]
125-
#
126-
## SQLite file
127-
#file = "main.db"
136+
# The database homu uses
137+
[db]
138+
# SQLite file
139+
file = "main.db"

homu/server.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
abort,
2424
response,
2525
)
26-
import hashlib
2726
from threading import Thread
2827
import sys
2928
import os
@@ -677,51 +676,6 @@ def buildbot():
677676
return 'OK'
678677

679678

680-
@post('/travis')
681-
def travis():
682-
logger = g.logger.getChild('travis')
683-
684-
info = json.loads(request.forms.payload)
685-
686-
lazy_debug(logger, lambda: 'info: {}'.format(utils.remove_url_keys_from_json(info))) # noqa
687-
688-
try:
689-
state, repo_label = find_state(info['commit'])
690-
except ValueError:
691-
lazy_debug(logger, lambda: 'Invalid commit ID from Travis: {}'.format(info['commit'])) # noqa
692-
return 'OK'
693-
694-
lazy_debug(logger, lambda: 'state: {}, {}'.format(state, state.build_res_summary())) # noqa
695-
696-
if 'travis' not in state.build_res:
697-
lazy_debug(logger, lambda: 'travis is not a monitored target for {}'.format(state)) # noqa
698-
return 'OK'
699-
700-
repo_cfg = g.repo_cfgs[repo_label]
701-
token = repo_cfg['travis']['token']
702-
auth_header = request.headers['Authorization']
703-
704-
slug = '{}/{}{}'.format(state.owner, state.name, token)
705-
code = hashlib.sha256((slug).encode('utf-8')).hexdigest()
706-
707-
if auth_header != code:
708-
# this isn't necessarily an error, e.g. maybe someone is
709-
# fabricating travis notifications to try to trick Homu, but,
710-
# I imagine that this will most often occur because a repo is
711-
# misconfigured.
712-
logger.warn('authorization failed for {}, maybe the repo has the '
713-
'wrong travis token? header = {}, computed = {}'
714-
.format(state, auth_header, code))
715-
abort(400, 'Authorization failed')
716-
717-
succ = info['result'] == 0
718-
719-
report_build_res(succ, info['build_url'], 'travis', state, logger,
720-
repo_cfg)
721-
722-
return 'OK'
723-
724-
725679
def synch(user_gh, state, repo_label, repo_cfg, repo):
726680
if not repo.is_collaborator(user_gh.user().login):
727681
abort(400, 'You are not a collaborator')

0 commit comments

Comments
 (0)