Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c5314e

Browse files
feat: auto commands on script start-up
1 parent 7fe63ff commit 8c5314e

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

‎Github-Automation/filechange.py‎

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
import os
2-
from os import listdir
3-
from os.path import isfile, join
42
import gitcommands as git
5-
import time
63
import diffcalc
4+
from ignore import getIgnoreFiles
5+
import logger
6+
from utils import getNestedFiles,read_file,commitAndUpdate
7+
from colors import logcolors
78
mypath = os.getcwd()
8-
nestfiles = []
9-
# add folders that you don't want to listen to
10-
ignoredirs = ['.git' , '.idea' , '__pycache__' , 'node_modules']
9+
10+
ignoredirs = getIgnoreFiles()
11+
print(ignoredirs)
12+
1113
# gets the list of all nested files
12-
def getNestedFiles(rootDir):
13-
for path , subdirs , files in os.walk(rootDir):
14-
if(all(ele not in path for ele in ignoredirs)):
15-
for name in files:
16-
nestfiles.append(join(path , name))
17-
return nestfiles
18-
19-
onlyfiles = getNestedFiles(mypath)
14+
onlyfiles = getNestedFiles(mypath,ignoredirs)
2015

21-
# Reads and appends the contents of each file
22-
def read_file():
23-
filecontent = []
24-
for file in onlyfiles:
25-
with open(onlyfiles[onlyfiles.index(file)], "r") as f:
26-
filecontent.append(f.readlines())
27-
return filecontent
2816

29-
def ischanged(url , branch):
17+
18+
def ischanged(url, branch,*args,**kwargs):
3019
changedfile = []
20+
diffarr = []
21+
# if uncommited data found perform git commands on them
22+
initbuffer = kwargs.get('initbuffer' , -1)
23+
if(initbuffer != -1):
24+
for obj in initbuffer:
25+
file = obj['path']
26+
diff = obj['changes']
27+
diffarr.append(diff)
28+
changedfile.append(file)
29+
30+
# Performing Git Commands for changed files
31+
commitAndUpdate(changedfile,diffarr,url,branch)
3132
print('Listening for changes....')
32-
initial = list(read_file())
33+
initial = list(read_file(onlyfiles))
3334
while True:
34-
current = list(read_file())
35+
current = list(read_file(onlyfiles))
3536
changeditem = []
3637
previtem = []
3738
if(current != initial):
@@ -45,21 +46,19 @@ def ischanged(url , branch):
4546
if ele not in initial:
4647
changeditem.append(ele)
4748
# calculating changed file's name
48-
for i in range(0 ,len(changeditem)):
49-
print('loop :-', i)
49+
for i in range(0, len(changeditem)):
50+
print('loop :-', i)
5051
changedfile.append(onlyfiles[current.index(changeditem[i])])
51-
print('Changed file is:-' , changedfile,'\n')
52+
print(f"Changed file is {logcolors.BOLD}{changedfile}{logcolors.ENDC}\n")
53+
5254
# Calculating Diff for previous and changed version of file
53-
diffcalc.calcDiff(previtem , changeditem[0])
55+
diff = diffcalc.calcDiff(previtem, changeditem[0])
56+
diffarr.append(diff)
57+
for file in changedfile:
58+
logger.writedata(path=file, diff=diff)
5459

55-
# Performing Git Commands For Changed File
56-
# Performing Git Add
57-
git.add(changedfile)
58-
# Performing Git Commit
59-
if(git.commit(changedfile) == False):
60-
print('Reverting Push')
61-
# Performing Git Push
62-
elif(len(changedfile) == 0):
63-
git.push(url , branch)
64-
initial = current
60+
# Performing Git Commands for changed files
61+
commitAndUpdate(changedfile,diffarr,url,branch)
6562

63+
initial = current
64+
# time.sleep(5)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /