-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.py
83 lines (73 loc) · 2.02 KB
/
tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from pandas import read_csv
from credentials import *
from github import Github
import base64
import sys
import pandas
g=Github("AbhishekM2001",passwd)
def get_version(x):
r=g.get_repo(x)
# print(r.name)
contents=r.get_contents("package.json")
# print(dir(contents))
text=base64.b64decode(contents.content)
v=text.index(b'version')
i=v+10
j=text.index(b'"',i+1)
# print(text[i+1:j])
return text[i+1:j].decode("utf-8")
# version=get_version("dyte-in/react-sample-app")
# print(version)
if __name__=='__main__':
# print(get_version("dyte-in/react-sample-app"))
# for i in range(len(sys.argv)):
# print(i,sys.argv[i])
if(sys.argv[1]=='-i'):
df=read_csv(sys.argv[2])
# print(df['repo'][1])
v1=sys.argv[3][sys.argv[3].index('@')+1:]
if(sys.argv[1]=='-update' and sys.argv[2]=='-i'):
df=read_csv(sys.argv[3])
v1=sys.argv[4][sys.argv[4].index('@')+1:]
v=[]
for i in range(len(df['repo'])):
t=df['repo'][i].index('dyte-in')
s=df['repo'][i][t:]
v2=get_version(s.rstrip('/'))
# print(v2)
v.append(v2)
df['version']=v
comp=[]
for i in range(len(v)):
a1=v1.index('.')
a2=v[i].index('.')
b1=v1.index('.',a1+1)
b2=v[i].index('.',a2+1)
# print(a1,b1,a2,b2)
# print(v1[:a1],v[i][:a2])
if(int(v[i][:a2])>int(v1[:a1])):
comp.append('true')
elif(int(v[i][a2+1:b2])>int(v1[a1+1:b1])):
comp.append('true')
elif(int(v[i][b2+1:])>int(v1[b1+1:])):
comp.append('true')
else:
comp.append('false')
# print(comp)
df['version_satisfied']=comp
# print(df)
if(sys.argv[1]=='-update' and sys.argv[2]=='-i'):
pr=[]
for i in range(len(comp)):
if(comp[i]=='false'):
t=df['repo'][i].index('dyte-in')
s=df['repo'][i][t:]
rep=g.get_repo(s.rstrip('/'))
pulls=rep.get_pulls(state='open')
mx=-100
for p in pulls:
mx=p.number if mx>p.number else mx
pr[i]=df['repo'][i]+'/pull/'+mx+1
rep.create_pull(title='Update version of this repository',base='master')
df['update_pr']=pr
print(df)