This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 346c0bf
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[](https://travis-ci.org/koddsson/travis-github-pr-bot) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |