Skip to content

Instantly share code, notes, and snippets.

@PiotrZakrzewski
Created March 6, 2018 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiotrZakrzewski/a279d1764ab0fd0993a6af433791cecb to your computer and use it in GitHub Desktop.
Save PiotrZakrzewski/a279d1764ab0fd0993a6af433791cecb to your computer and use it in GitHub Desktop.
from github import Github
from time import time
from calendar import timegm
from statistics import median
import requests
import json
GITHUB_API_TOKEN = "REPLACE_ME"
WEBHOOK_URL = "REPLACE_ME"
TARGET_ORG = "REPLACE_ME"
g = Github(GITHUB_API_TOKEN)
hue_webhook = WEBHOOK_URL
current_time = time()
ages = []
for repo in g.get_organization(TARGET_ORG).get_repos():
for pr in repo.get_pulls():
pr_created = timegm(pr.created_at.timetuple())
age = (current_time - pr_created) / 60 / 60 / 24 # to days
age = round(age, 1)
ages.append(age)
print("Open PRs:", len(ages))
print("median", median(ages), "h")
msg_text = "Hello! You have {0} Open PRs\nTheir median age is {1} days".format(len(ages), median(ages))
payload = {
'text' : msg_text
}
res = requests.post(hue_webhook, data=json.dumps(payload))
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment