|
| 1 | +import os |
| 2 | +from os import listdir |
| 3 | +from os.path import isfile, join |
| 4 | +import gitcommands as git |
| 5 | +import time |
| 6 | +import diffcalc |
| 7 | +mypath = os.getcwd() |
| 8 | +onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] |
| 9 | +def read_file(): |
| 10 | + filecontent = [] |
| 11 | + for file in onlyfiles: |
| 12 | + with open(onlyfiles[onlyfiles.index(file)], "r") as f: |
| 13 | + filecontent.append(f.readlines()) |
| 14 | + return filecontent |
| 15 | + |
| 16 | +def ischanged(url , branch): |
| 17 | + changedfile = [] |
| 18 | + print('Listening for changes....') |
| 19 | + initial = list(read_file()) |
| 20 | + while True: |
| 21 | + current = list(read_file()) |
| 22 | + changeditem = [] |
| 23 | + previtem = [] |
| 24 | + if(current != initial): |
| 25 | + # Calculating Previous Version of File |
| 26 | + for ele in initial: |
| 27 | + if ele not in current: |
| 28 | + for item in ele: |
| 29 | + previtem.append(item) |
| 30 | + # Calculating New Version of File |
| 31 | + for ele in current: |
| 32 | + if ele not in initial: |
| 33 | + changeditem.append(ele) |
| 34 | + # calculating changed file's name |
| 35 | + for i in range(0 ,len(changeditem)): |
| 36 | + print('loop :-' , i) |
| 37 | + changedfile.append(onlyfiles[current.index(changeditem[i])]) |
| 38 | + print('Changed file is:-' , changedfile,'\n') |
| 39 | + # Calculating Diff for previous and changed version of file |
| 40 | + diffcalc.calcDiff(previtem , changeditem[0]) |
| 41 | + |
| 42 | + # Performing Git Commands For Changed File |
| 43 | + # Performing Git Add |
| 44 | + git.add(changedfile) |
| 45 | + # Performing Git Commit |
| 46 | + if(git.commit(changedfile) == False): |
| 47 | + print('Reverting Push') |
| 48 | + # Performing Git Push |
| 49 | + elif(len(changedfile) == 0): |
| 50 | + git.push(url , branch) |
| 51 | + initial = current |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
0 commit comments