Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
Intial
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Nov 25, 2014
0 parents commit 346c0bf
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: python
python:
- '2.7'
- '3.4'
install:
- pip install -r requirements.txt
script:
- flake8 . | ./comment-on-pr.py
env:
global:
- TRAVIS_BOT_GITHUB_TOKEN=cf451704f2f1d2b1701a7aca7849ce2f8debb09c
deploy:
provider: pypi
user: koddsson
password:
secure: CZR30T94L5wR7TkaEHassLfNX0wspfl3use7yVeIxU3m2dWCyMa0zmh/ZRT7g/RD2ZoNEsO4KcnwS5gE0CdUbDU/7b/FleBzL5BfZWpJyP+QbQ+30xQIPJpBXM7XfSte+LfplQhz9ygbG2GmlB0fOL3YL85RxS9lqdW/GEKNL3s=
on:
tags: true
repo: koddsson/travis-github-pr-bot
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![Build Status](https://travis-ci.org/koddsson/travis-github-pr-bot.svg?branch=master)](https://travis-ci.org/koddsson/travis-github-pr-bot)
48 changes: 48 additions & 0 deletions comment-on-pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
"""
Comments stdin to the GitHub PR that triggered the travis build.
Usage:
flake8 | python comment-on-pr.py
Notes:
The following enviromental variables need to be set:
- TRAVIS_PULL_REQUEST
- TRAVIS_REPO_SLUG
- TRAVIS_BOT_GITHUB_TOKEN
"""

from __future__ import print_function

import os
import sys
import json
import requests


def comment_on_pull_request(pr_number, slug, token, comment):
""" Comment message on a given GitHub pull request. """
url = 'https://api.github.com/repos/{slug}/issues/{number}/comments'.format(
slug=slug, number=pr_number)
response = requests.post(url, data=json.dumps({'body': comment}),
headers={'Authorization': 'token ' + token})
return response.json()


if __name__ == '__main__':
PR_NUMBER = os.environ.get('TRAVIS_PULL_REQUEST')
REPO_SLUG = os.environ.get('TRAVIS_REPO_SLUG')
TOKEN = os.environ.get('TRAVIS_BOT_GITHUB_TOKEN')

results = sys.stdin.read()
comment = (
"""
```
{flake_results}
```
""").format(flake_results=results)

if all([PR_NUMBER, REPO_SLUG, TOKEN, results.strip()]):
comment_on_pull_request(PR_NUMBER, REPO_SLUG, TOKEN, comment)
else:
print('Not all neccesery variables are present')
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
flake8==2.2.5
mccabe==0.2.1
pep8==1.5.7
pyflakes==0.8.1
requests==2.4.3
wsgiref==0.1.2

0 comments on commit 346c0bf

Please sign in to comment.