2017-04-24 14:53:45 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2019-05-07 00:15:25 -05:00
|
|
|
url_fmt = "https://api.github.com/repos/Equinor/libecl/pulls/%d"
|
2017-04-24 14:53:45 -05:00
|
|
|
|
2017-10-26 10:16:36 -05:00
|
|
|
def getPRList( api_token, pr1, pr2):
|
|
|
|
pr = pr1
|
2017-04-24 14:53:45 -05:00
|
|
|
pr_list = []
|
|
|
|
prev_len = 0
|
|
|
|
sys.stderr.write("Downloading PR: ")
|
|
|
|
while True:
|
2017-10-26 10:16:36 -05:00
|
|
|
url = url_fmt % pr
|
2018-10-30 07:21:11 -05:00
|
|
|
response = requests.get( url , params = {"access_token" : api_token})
|
2017-10-26 10:16:36 -05:00
|
|
|
for i in range(prev_len):
|
|
|
|
sys.stdout.write("\b")
|
|
|
|
|
|
|
|
sys.stdout.write("%d" % pr )
|
|
|
|
sys.stdout.flush()
|
|
|
|
prev_len = len("%s" % pr)
|
|
|
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
pr_list.append( json.loads( response.content ) )
|
|
|
|
pr += 1
|
|
|
|
|
|
|
|
if pr > pr2:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-24 14:53:45 -05:00
|
|
|
return pr_list
|
|
|
|
|
|
|
|
|
|
|
|
def printPRList( pr_list , fileH):
|
|
|
|
for pr in pr_list:
|
|
|
|
title = pr["title"]
|
|
|
|
body = pr["body"]
|
|
|
|
nr = pr["number"]
|
2019-05-07 00:15:25 -05:00
|
|
|
url = "https://github.com/Equinor/libecl/pull/{}/".format(nr)
|
2017-10-26 10:16:36 -05:00
|
|
|
|
2017-04-24 14:53:45 -05:00
|
|
|
try:
|
2018-10-30 07:21:11 -05:00
|
|
|
title = str(title)
|
2017-04-24 14:53:45 -05:00
|
|
|
except UnicodeEncodeError:
|
2018-10-30 07:21:11 -05:00
|
|
|
title = "UnicodeError"
|
|
|
|
|
|
|
|
fileH.write( "[`{nr} <{url}>`] : {title}".format(nr = nr, url=url, title = title))
|
2017-04-24 14:53:45 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
fileH.write( "%s\n\n\n" % body )
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
fileH.write("UnicodeError")
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if "GITHUB_API_TOKEN" in os.environ:
|
|
|
|
github_api_token = os.getenv("GITHUB_API_TOKEN")
|
|
|
|
else:
|
|
|
|
sys.exit("You must create a github access token and set the environment variable 'GITHUB_API_TOKEN' to proceed")
|
|
|
|
|
|
|
|
pr1 = int(sys.argv[1])
|
2017-10-26 10:16:36 -05:00
|
|
|
pr2 = int(sys.argv[2])
|
|
|
|
pr_list = getPRList( github_api_token, pr1, pr2)
|
2017-04-24 14:53:45 -05:00
|
|
|
|
|
|
|
filename = "/tmp/relnotes-%d-%d" % (pr1 , pr2)
|
|
|
|
printPRList( pr_list , open(filename , "w"))
|
|
|
|
|
2018-10-30 07:21:11 -05:00
|
|
|
print "\nHave created file: %s which can be a starting point for release notes" % filename
|
2017-04-24 14:53:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-26 10:16:36 -05:00
|
|
|
|
2017-04-24 14:53:45 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main( )
|
|
|
|
|
|
|
|
|